Skip to content

[enhancement] Add OpenTelemetry tracing spans to distributed event bus pipeline #60

@yilmaztayfun

Description

@yilmaztayfun

Description

The distributed event bus pipeline (publish, outbox, inbox, handler invocation) has no
application-level OpenTelemetry Activity instrumentation. The Dapr sidecar creates its
own trace context for HTTP calls, but there are no semantic spans with event name, topic,
pubsub, or handler metadata. This makes it impossible to correlate event publishing with
handler execution in trace tools, and outbox/inbox background processing is completely
invisible.

This issue covers adding Activity spans using the existing InfrastructureActivitySource
(BBT.Aether.Infrastructure) to 5 key locations in the event pipeline.

Expected Behavior

Trace tools (Jaeger, Tempo, etc.) should show a clear span hierarchy for the full event
lifecycle:

  • Direct publish: EventBus.PublishEventBus.PublishToBroker → HTTP Client span
  • Outbox publish: EventBus.Publish (use_outbox=true) ... Outbox.ProcessEventBus.PublishEnvelopeEventBus.PublishToBroker
  • Inbox consumption: Inbox.ProcessInbox.Invoke → handler execution

Each span should carry semantic tags (event.name, event.topic, event.pubsub_name,
event.broker, event.handler, outbox.message_id, etc.) and record exceptions on failure.

Technical Context

  • framework/src/BBT.Aether.Infrastructure/BBT/Aether/Events/Distributed/DistributedEventBusBase.csPublishAsync (2 overloads) and PublishEnvelopeAsync need EventBus.Publish / EventBus.PublishEnvelope spans
  • framework/src/BBT.Aether.Infrastructure/BBT/Aether/Events/Distributed/DaprEventBus.csPublishToBrokerAsync (2 overrides) need EventBus.PublishToBroker spans with event.broker=dapr
  • framework/src/BBT.Aether.Infrastructure/BBT/Aether/Events/Processing/OutboxProcessor.cs — per-message Outbox.Process span in ProcessOutboxMessagesAsync
  • framework/src/BBT.Aether.Infrastructure/BBT/Aether/Events/Processing/InboxProcessor.csInbox.Process span in ProcessSingleEventAsync
  • framework/src/BBT.Aether.Infrastructure/BBT/Aether/Events/Distributed/DistributedEventInvoker.csInbox.Invoke span in InvokeAsync
  • framework/src/BBT.Aether.Infrastructure/BBT/Aether/Telemetry/InfrastructureActivitySource.cs — existing ActivitySource to reuse (already registered in telemetry setup)
  • framework/docs/distributed-events/README.md — needs a "Tracing" section
  • framework/docs/telemetry/README.md — infrastructure spans list needs event bus entries

Acceptance Criteria

  • DistributedEventBusBase.PublishAsync (both overloads) creates EventBus.Publish span with tags: event.name, event.topic, event.use_outbox
  • DistributedEventBusBase.PublishEnvelopeAsync creates EventBus.PublishEnvelope span with tags: event.topic, event.pubsub_name
  • DaprEventBus.PublishToBrokerAsync (both overrides) creates EventBus.PublishToBroker span with tags: event.topic, event.pubsub_name, event.broker=dapr
  • OutboxProcessor creates Outbox.Process span per message with tags: event.name, event.topic, event.pubsub_name, outbox.message_id, outbox.retry_count
  • InboxProcessor.ProcessSingleEventAsync creates Inbox.Process span with tags: event.id, event.name, event.version
  • DistributedEventInvoker.InvokeAsync creates Inbox.Invoke span with tags: event.name, event.version, event.handler
  • All spans record exceptions with ActivityStatusCode.Error and exception event on failure
  • distributed-events/README.md documents tracing spans, tags, and example trace hierarchies
  • telemetry/README.md infrastructure spans list includes event bus operations
  • Solution builds with zero errors

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request
No fields configured for Feature.

Projects

Status
In Production / Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions