diff --git a/guides/telemetry.md b/guides/telemetry.md index cb119414..79058c67 100644 --- a/guides/telemetry.md +++ b/guides/telemetry.md @@ -75,5 +75,5 @@ Indicates when a coordinating event was raised, like a process being added for c ```erlang event_name: [amoc, coordinator, start | stop | add | reset | timeout] measurements: #{count => 1} -metadata: #{name => atom()} +metadata: #{monotonic_time => integer(), name => atom()} ``` diff --git a/src/amoc_coordinator/amoc_coordinator.erl b/src/amoc_coordinator/amoc_coordinator.erl index 374c9379..63658044 100644 --- a/src/amoc_coordinator/amoc_coordinator.erl +++ b/src/amoc_coordinator/amoc_coordinator.erl @@ -74,7 +74,8 @@ start(Name, CoordinationPlan, Timeout) when ?IS_TIMEOUT(Timeout) -> Plan = normalize_coordination_plan(CoordinationPlan), case gen_event:start({local, Name}) of {ok, _} -> - telemetry:execute([amoc, coordinator, start], #{count => 1}, #{name => Name}), + telemetry:execute([amoc, coordinator, start], #{count => 1}, + #{monotonic_time => erlang:monotonic_time(), name => Name}), %% according to gen_event documentation: %% %% When the event is received, the event manager calls @@ -99,7 +100,8 @@ start(Name, CoordinationPlan, Timeout) when ?IS_TIMEOUT(Timeout) -> -spec stop(name()) -> ok. stop(Name) -> gen_event:stop(Name), - telemetry:execute([amoc, coordinator, stop], #{count => 1}, #{name => Name}). + telemetry:execute([amoc, coordinator, stop], #{count => 1}, + #{monotonic_time => erlang:monotonic_time(), name => Name}). %% @see add/3 -spec add(name(), any()) -> ok. @@ -163,8 +165,8 @@ handle_event(Event, {timeout, Name, Pid}) -> reset_coordinator -> reset; coordinator_timeout -> timeout end, - telemetry:execute([amoc, coordinator, TelemetryEvent], - #{count => 1}, #{name => Name}), + telemetry:execute([amoc, coordinator, TelemetryEvent], #{count => 1}, + #{monotonic_time => erlang:monotonic_time(), name => Name}), erlang:send(Pid, Event), {ok, {timeout, Name, Pid}}; handle_event(Event, {worker, WorkerPid}) -> diff --git a/test/amoc_coordinator_SUITE.erl b/test/amoc_coordinator_SUITE.erl index 88dc3f57..90241755 100644 --- a/test/amoc_coordinator_SUITE.erl +++ b/test/amoc_coordinator_SUITE.erl @@ -327,9 +327,8 @@ assert_telemetry_events(Name, [{_Pid, Call, _Ret} | History], [Event | EventList assert_telemetry_handler_call(Name, Call, Event) -> EventName = [amoc, coordinator, Event], Measurements = #{count => 1}, - EventMetadata = #{name => Name}, HandlerConfig = ?TELEMETRY_HANDLER_CONFIG, - ExpectedHandlerCall = {?TELEMETRY_HANDLER, handler, - [EventName, Measurements, - EventMetadata, HandlerConfig]}, - ?assertEqual(ExpectedHandlerCall, Call). + ?assertMatch( + {?TELEMETRY_HANDLER, handler, + [EventName, Measurements, + #{name := Name, monotonic_time := _}, HandlerConfig]}, Call).