feat(telemetry): add and surface processing_latency_ms in event handler spans - #68
Conversation
PR SummaryLow Risk Overview Event handler and batch handler Reviewed by Cursor Bugbot for commit ecb6a0c. Bugbot is set up for automated code reviews on this repo. Configure here. |
WalkthroughAdded a new OpenTelemetry span attribute constant representing event processing latency. Modified event handler telemetry callbacks to conditionally set this attribute on span completion when processing latency measurements are available. Updated corresponding tests to verify the attribute is captured. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 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 |
3b3156f to
c3e3745
Compare
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 `@lib/commanded/opentelemetry/event_handler.ex`:
- Around line 261-267: The helper put_commanded_processing_latency_ms currently
only matches measurements with the key :processing_latency_ms so spans never get
the attribute when measurements use %{n: ...}; update
put_commanded_processing_latency_ms to handle either key (e.g., pattern-match
%{processing_latency_ms: latency} or %{n: latency}) and accept numeric values
(use is_number/1 or convert to integer) before calling Span.set_attribute(ctx,
CommandedAttributes.commanded_processing_latency_ms(), latency) so the attribute
is set regardless of which producer key is used.
🪄 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: 947ba220-9131-45dd-a332-3a2279124738
📒 Files selected for processing (3)
lib/commanded/opentelemetry/commanded_attributes.exlib/commanded/opentelemetry/event_handler.extest/opentelemetry/event_handler_test.exs
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 19dfe61. Configure here.
Add commanded.processing_latency_ms as a span attribute on event handler stop spans, bridging the telemetry measurement into the trace for use in SLA dashboards and alerting. Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>

commanded.handler.lagspan attribute to[:commanded, :event, :handle, :stop]and[:commanded, :event, :batch, :stop]OTel spans — elapsed milliseconds fromRecordedEvent.created_atto handler completion, representing how far behind the handler is relative to when events were written