Skip to content

feat: Add OpenTelemetry instrumentation for aggregate populate - #47

Merged
yordis merged 1 commit into
mainfrom
otel-aggregate-populate
Jan 19, 2026
Merged

yordis merged 1 commit into
mainfrom
otel-aggregate-populate

Conversation

@yordis

@yordis yordis commented Jan 19, 2026

Copy link
Copy Markdown
Member

No description provided.

@cursor

cursor Bot commented Jan 19, 2026 •

Copy link
Copy Markdown

PR Summary

Introduces tracing for aggregate populate lifecycle.

  • New Commanded.OpenTelemetry.AggregatePopulate attaches telemetry handlers for [:commanded, :aggregate, :populate, :start|:stop], creating internal span commanded.aggregate.populate with messaging/code semconv and Commanded attributes; sets commanded.event.count and final commanded.aggregate.version on stop
  • Extends Commanded.OpenTelemetry.setup/1 with aggregate_populate option (can be :disabled) and wires to AggregatePopulate.setup/0
  • Tests: added AggregatePopulateTest; updated test support with Factory.build_aggregate_populate_metadata/1 and OpenTelemetryCase cleanup for new events

Written by Cursor Bugbot for commit 03c697d. This will update automatically on new commits. Configure here.

@coderabbitai

coderabbitai Bot commented Jan 19, 2026 •

Copy link
Copy Markdown

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds OpenTelemetry instrumentation for aggregate population: new Commanded.OpenTelemetry.AggregatePopulate module with telemetry handlers, wires setup and config option into Commanded.OpenTelemetry, and adds tests and factory/helper updates for aggregate populate events.

Changes

Cohort / File(s) Summary
OpenTelemetry Core
lib/commanded/opentelemetry.ex
Added Commanded.OpenTelemetry.AggregatePopulate alias; extended NimbleOptions schema with aggregate_populate option (accepts :disabled or list, default []); wired setup to call AggregatePopulate.setup() when enabled.
AggregatePopulate Instrumentation
lib/commanded/opentelemetry/aggregate_populate.ex
New module implementing setup/0 and handle_telemetry_event/4; attaches handlers for [:commanded, :aggregate, :populate, :start] and [:commanded, :aggregate, :populate, :stop]; starts internal span on start and sets event_count/aggregate_version on stop.
Tests
test/opentelemetry/aggregate_populate_test.exs
New test module verifying handler attachment, idempotency/fail-fast on double setup, span attributes (messaging, code, application, aggregate UUID/version, event count), and edge cases (zero/multiple events).
Test Helpers
test/support/factory.ex, test/support/opentelemetry_case.ex
Added build_aggregate_populate_metadata/1 factory helper; extended OpenTelemetry case teardown to detach [:commanded, :aggregate, :populate, :start] and [:commanded, :aggregate, :populate, :stop] handlers.

Sequence Diagram(s)

sequenceDiagram
    participant Aggregate as Aggregate
    participant Telemetry as Telemetry
    participant Handler as AggregatePopulate<br/>(handler)
    participant OTel as OpenTelemetry<br/>Tracer

    Aggregate->>Telemetry: emit [:commanded, :aggregate, :populate, :start]
    Telemetry->>Handler: handle_telemetry_event/4 (start)
    Handler->>Handler: build attributes (messaging, code, commanded)
    Handler->>OTel: start_span("commanded.aggregate.populate")
    OTel-->>Handler: span_ref

    Aggregate->>Aggregate: populate aggregate (apply events)

    Aggregate->>Telemetry: emit [:commanded, :aggregate, :populate, :stop]
    Telemetry->>Handler: handle_telemetry_event/4 (stop)
    Handler->>Handler: set event_count & aggregate_version attrs
    Handler->>OTel: set_attributes(span_ref, attrs)
    Handler->>OTel: end_span(span_ref)
    OTel-->>Handler: span closed
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Hopping through telemetry trails so keen,

I trace each aggregate, seen and unseen.
Spans knitted with versions, counts in a row,
Tiny rabbit feet mark every flow.
Cheers for traces that help us grow! 🥕✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to evaluate whether the description relates to the changeset. Add a pull request description that explains the purpose and context of the aggregate populate instrumentation changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: Add OpenTelemetry instrumentation for aggregate populate' directly and clearly describes the main change: adding OpenTelemetry instrumentation for aggregate populate events.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

cursor[bot]

This comment was marked as outdated.

@yordis
yordis force-pushed the otel-aggregate-populate branch 2 times, most recently from b11682e to e20783d Compare January 19, 2026 21:39

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Comment thread lib/commanded/opentelemetry/aggregate_populate.ex
Comment thread lib/commanded/opentelemetry/aggregate_populate.ex
@yordis
yordis force-pushed the otel-aggregate-populate branch 2 times, most recently from 4047054 to d033c2d Compare January 19, 2026 22:31
@yordis
yordis marked this pull request as ready for review January 19, 2026 22:32
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis
yordis force-pushed the otel-aggregate-populate branch from d033c2d to 03c697d Compare January 19, 2026 22:34
@yordis
yordis merged commit f7b43d1 into main Jan 19, 2026
5 checks passed
@yordis
yordis deleted the otel-aggregate-populate branch January 19, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant