How does context propagation work in-process and across processes?

AdvancedConceptTracing & OpenTelemetry
Answer
  • In-process: the SDK stores the active span in a context object (thread-local in Java, contextvars in Python, context.Context passed explicitly in Go, AsyncLocalStorage in Node.js). New spans pick the active span as their parent.
  • Across processes: a propagator injects the context into a carrier (HTTP headers, gRPC metadata, Kafka record headers) on the client side and extracts it on the server side.
ctx, span := tracer.Start(r.Context(), "charge-card")
defer span.End()
req, _ := http.NewRequestWithContext(ctx, "POST", url, body)
otel.GetTextMapPropagator().Inject(ctx, propagation.HeaderCarrier(req.Header))

Typical breaks: thread pools or goroutines that do not carry the context, async callbacks, and message queues where nobody injects headers. Auto-instrumentation handles common frameworks; custom executors need manual wrapping.

All Monitoring & Observability questions Roadmap: Logging & tracing

More on Tracing & OpenTelemetry