Add trace metrics: event counts, execution duration, and per-type child spans - #1
Open
pedroamaral-cvfx wants to merge 3 commits into
Open
Add trace metrics: event counts, execution duration, and per-type child spans#1pedroamaral-cvfx wants to merge 3 commits into
pedroamaral-cvfx wants to merge 3 commits into
Conversation
Enrich OpenTelemetry spans with more observable data: - Add `commanded.events` (list of event type names) to aggregate spans - Add `commanded.commands` (list of command type names) to process manager spans - Add `commanded.execution.duration_ms` to all span types (aggregate, application, event handler, process manager) by capturing telemetry measurements duration - Add `native_to_ms/1` helper to Util for converting Erlang native time units https://claude.ai/code/session_01Koa4DN6w78SgchqkWu28B6
Create child spans for each domain event emitted (aggregate) and each command dispatched (process manager) to enable per-type metrics in Datadog via "Generate Metrics from Spans": - `commanded.event.emitted` child spans with `commanded.event_type` and `commanded.aggregate_uuid` attributes on aggregate execution - `commanded.command.dispatched` child spans with `commanded.command_type` and `commanded.process_uuid` attributes on process manager handling This enables Datadog users to create timeseries like: count(*) where @span.name:commanded.event.emitted grouped by @commanded.event_type https://claude.ai/code/session_01Koa4DN6w78SgchqkWu28B6
Author
Author
|
disregard this comment, just fixing the PR list view |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Enriches OpenTelemetry spans with additional observable data to support monitoring and Datadog timeseries dashboards for Commanded CQRS applications.
Problem
The existing instrumentation creates spans for command dispatch, aggregate execution, event handling, and process management — but the spans lack quantitative data needed for operational dashboards:
commanded.event_countexisted but without the actual type namescommanded.eventscannot produce per-type timeseriesChanges
1. Execution duration on all spans (
commanded.execution.duration_ms)All four instrumentation modules (
aggregate,application,event_handler,process_manager) now capture the telemetrymeasurements[:duration]and set it ascommanded.execution.duration_ms(converted from native time units via:erlang.convert_time_unit/3). A sharednative_to_ms/1helper was added toOpentelemetryCommanded.Util.2. Event/command type name lists as span attributes
commanded.events— a list of event type name stringscommanded.commands— a list of dispatched command type name strings3. Per-type child spans for Datadog metrics
For each domain event emitted by an aggregate, a zero-duration child span
commanded.event.emittedis created withcommanded.event_typeandcommanded.aggregate_uuid. For each command dispatched by a process manager, acommanded.command.dispatchedchild span is created withcommanded.command_typeandcommanded.process_uuid.count(*)where@span.name:commanded.event.emittedcount(*)grouped by@commanded.event_typecount(*)grouped by@commanded.command_typeNew span attributes
commanded.execution.duration_mscommanded.eventscommanded.commandsNew child spans
commanded.event.emittedcommanded.aggregate.executecommanded.event_type,commanded.aggregate_uuidcommanded.command.dispatchedcommanded.process_manager.handlecommanded.command_type,commanded.process_uuidTest plan
mix test— all existing and new tests pass