Skip to content

Add OpenTelemetry end-to-end trace context propagation for Pekko Streams #3107

Description

@He-Pin

Motivation

Pekko Streams has no distributed tracing support. Users running Pekko in microservices cannot trace how elements flow through stream topologies. This is increasingly expected in production environments for observability.

Proposed design (based on Akka.NET reference implementation)

  1. Trace context in Connection slots: Extend Connection in GraphInterpreter with a trace context field. Capture io.opentelemetry.context.Context.current() on element push.

  2. Stage-scoped spans: In processPush, start an OpenTelemetry span scoped to the stage. Span name = stage operation (e.g., MapAsync, Filter).

  3. Fan-in links: For fan-in stages (Batch, Merge, Concat, GroupedWeightedWithin), record ActivityLinks from all input connections.

  4. Cross-async-boundary propagation: Extend OnNext events with trace context. BatchingActorInputBoundary buffers contexts in parallel arrays and restores them on dequeue.

  5. Zero-cost when no listener: When no OpenTelemetry listener is registered, all tracing code should be a no-op with negligible overhead.

JVM-specific considerations

  • Use io.opentelemetry.api.trace.Tracer instead of .NET ActivitySource
  • Use io.opentelemetry.context.Context and ThreadLocal propagation
  • Consider integration with Pekko's existing ContextPropagation mechanism
  • May need a new module/dependency for opentelemetry-api

Scope

This is a large, cross-cutting feature (~2000+ lines across 20+ files). It should be broken into multiple PRs:

  1. Core trace context in GraphInterpreter Connection
  2. Stage-scoped spans in processPush
  3. Fan-in link support
  4. Cross-async-boundary propagation
  5. Source.Queue / Sink.Queue ingress/egress tracing
  6. Configuration and opt-in mechanism

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    akkadotnetIssue/PR inspired by Akka.netenhancementNew feature or requestt:streamPekko Streams

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions