feat(telemetry): add processing_latency_ms to event handler stop measurements - #66
Conversation
PR SummaryMedium Risk Overview Updates event handler telemetry emission to pass additional measurements through Reviewed by Cursor Bugbot for commit 6da285a. Bugbot is set up for automated code reviews on this repo. Configure here. |
|
Caution Review failedPull request was closed or merged during review WalkthroughAdds a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 62c8812. Configure here.
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/commanded/event/handler.ex (1)
1084-1093:⚠️ Potential issue | 🟡 MinorCI is blocked by formatter failures in these ranges.
mix format --check-formattedis failing for this file (as reported in pipeline). Please run formatter on the updated telemetry calls/signatures.Also applies to: 1162-1180, 1437-1459
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/commanded/event/handler.ex` around lines 1084 - 1093, The formatter check is failing due to unformatted changes around the telemetry call sites and updated function signatures; run mix format over the modified ranges and ensure telemetry_exception/6 and related telemetry calls (and their surrounding concatenated Logger.error blocks) are formatted to match project formatting rules; specifically reformat the block that calls telemetry_exception(start_time, :error, reason, stacktrace, telemetry_metadata, :handle, lag), the failure_context/retry_fun/handle_event_error sequence, and the Logger.error describe(state) <> " failed to handle event " concatenation (also apply the same formatting fixes to the other affected ranges around the existing telemetry and Logger blocks at the noted locations).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/commanded/event/handler.ex`:
- Around line 1045-1047: The lag measurement is being captured too early; move
the call to lag_measurements so it runs after handler execution and use that
value when emitting the stop/exception telemetry. Specifically, keep
telemetry_start(telemetry_metadata, :handle) where it is, but call
lag_measurements(event) after delegate_event_to_handler/2 returns (and also in
the rescue/exception path) and pass that computed lag (e.g., lag_ms) into the
subsequent stop/exception emit logic so the reported lag reflects time "when the
handler finished."
- Around line 1148-1150: The telemetry metadata currently injects the full
%Handler{} (variable state) instead of the returned handler_state; update the
call to telemetry_stop in the {:ok, handler_state} branch to pass handler_state
(not state) into the metadata (i.e., %{telemetry_metadata | handler_state:
handler_state}) so telemetry_stop and subsequent confirm_receipt receive the
correct handler_state value from the invoked handler function.
---
Outside diff comments:
In `@lib/commanded/event/handler.ex`:
- Around line 1084-1093: The formatter check is failing due to unformatted
changes around the telemetry call sites and updated function signatures; run mix
format over the modified ranges and ensure telemetry_exception/6 and related
telemetry calls (and their surrounding concatenated Logger.error blocks) are
formatted to match project formatting rules; specifically reformat the block
that calls telemetry_exception(start_time, :error, reason, stacktrace,
telemetry_metadata, :handle, lag), the
failure_context/retry_fun/handle_event_error sequence, and the Logger.error
describe(state) <> " failed to handle event " concatenation (also apply the same
formatting fixes to the other affected ranges around the existing telemetry and
Logger blocks at the noted locations).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 55cf829e-1d4e-490b-b06c-6109d9caeb18
📒 Files selected for processing (4)
guides/explanations/fork-differences.mdlib/commanded/event/handler.extest/event/event_handler_batch_telemetry_test.exstest/event/event_handler_telemetry_test.exs
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/event/event_handler_telemetry_test.exs`:
- Around line 18-30: The test name and PR text mention "lag_ms" but the code
emits "processing_latency_ms"; update the measurement name to be consistent by
either changing the emitted telemetry key in the handler (where
Handler.handle_info/2 and EchoHandler produce telemetry) to use :lag_ms or
rename the test assertions to expect :processing_latency_ms so names match;
additionally, add an assertion verifying the handler actually processed the
event (e.g., assert_receive for EchoHandler's reply message) before asserting
telemetry to ensure the telemetry came from a successful handling path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8313497a-7e66-4a16-b525-185cd60eaa9c
📒 Files selected for processing (4)
guides/explanations/fork-differences.mdlib/commanded/event/handler.extest/event/event_handler_batch_telemetry_test.exstest/event/event_handler_telemetry_test.exs
✅ Files skipped from review due to trivial changes (2)
- test/event/event_handler_batch_telemetry_test.exs
- guides/explanations/fork-differences.md
🚧 Files skipped from review as they are similar to previous changes (1)
- lib/commanded/event/handler.ex
…urements Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>

Summary
processing_latency_msto the measurements emitted on[:commanded, :event, :handle, :stop]and[:commanded, :event, :batch, :stop]telemetry events — the elapsed milliseconds betweenRecordedEvent.created_atand when the handler finished processing itprocessing_latency_msreflects the oldest event in the batch (worst-case processing latency for that invocation — the signal that drives SLA alerting){:ok, handler_state}batch telemetry emitting the fullHandlerstruct ashandler_statein metadata instead of the application handler's own stateRelated