Documentation
¶
Overview ¶
Package otel bridges OpenAgentIO middleware to OpenTelemetry. Trace() rebuilds an upstream SpanContext from envelope.traceparent and starts a child span around handler execution; EnvelopePreparer() injects the active span back into outbound envelopes so cross-process traces stay linked.
The package is opt-in: importing it pulls go.opentelemetry.io/otel into the dependency tree. pkg/bus itself stays OTel-free.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvelopePreparer ¶
func EnvelopePreparer(opts ...Option) bus.EnvelopePreparer
EnvelopePreparer returns a bus.EnvelopePreparer that injects the current OpenTelemetry SpanContext into every outbound envelope (Publish / Invoke / StreamInvoke). Wire it via:
b, _ := bus.New(
// ...
bus.WithEnvelopePreparer(otel.EnvelopePreparer()),
)
The preparer is a no-op when ctx carries no valid span — direct user calls outside any traced flow leave the envelope untouched.
func Trace ¶
func Trace(opts ...Option) middleware.Middleware
Trace returns a middleware that, on every handler invocation:
- Extracts an upstream SpanContext from envelope.Traceparent via the configured propagator.
- Starts a Consumer-kind span named "acp.handle.<event_type>".
- Sets messaging-semconv attributes plus acp.* extensions.
- Records errors and marks span status accordingly when the inner handler returns a non-nil error.
If no TracerProvider is configured globally and no Option overrides it, OTel returns a Noop tracer and the middleware adds negligible overhead.
Types ¶
type Option ¶
type Option func(*config)
Option configures Trace and EnvelopePreparer. Sensible defaults are used when no Option is supplied: the global TracerProvider and the global TextMapPropagator (which Anthropic-style apps wire to W3C Trace Context during OTel SDK init).
func WithPropagator ¶
func WithPropagator(p propagation.TextMapPropagator) Option
WithPropagator overrides the TextMapPropagator. Default is otel.GetTextMapPropagator(), which standard OTel init wires to W3C Trace Context.
func WithTracerProvider ¶
func WithTracerProvider(tp trace.TracerProvider) Option
WithTracerProvider overrides the TracerProvider. Useful for tests that want a SpanRecorder without touching the global provider.