Skip to content

Instantly share code, notes, and snippets.

@slashdotdash
Created May 3, 2019 11:13
Show Gist options
  • Save slashdotdash/f3cdb234527ae27bb0ca28407882c871 to your computer and use it in GitHub Desktop.
Save slashdotdash/f3cdb234527ae27bb0ca28407882c871 to your computer and use it in GitHub Desktop.
A Commanded event handler to produce `:telemetry` events for each recorded event.
defmodule Commanded.EventTelemetry do
@moduledoc """
A Commanded event handler to produce `:telemetry` events for each recorded
event.
It produces the following event:
- `[:commanded, :event, :published]`
"""
use Commanded.Event.Handler, name: __MODULE__, start_from: :current
def handle(event, metadata) do
:telemetry.execute(
[:commanded, :event, :published],
%{timestamp: Map.get(metadata, :created_at)},
%{event: event, metadata: metadata}
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment