Context Propagation
Span context is a serialized representation of the current span. Pass it to downstream services, and they can continue the same trace. Common patterns:- HTTP headers — Include serialized context in a custom header (e.g.,
X-Laminar-Span-Context) - Message queues — Embed context in the message payload alongside your data
- Database storage — Store context with workflow state for long-running processes that span multiple requests
Example
When you can’t pass span objects directly (HTTP, queues, cron jobs), serialize context in the upstream service and deserialize in the downstream service.- TypeScript
- Python
Laminar.serializeLaminarSpanContext and Laminar.startSpanCommon Patterns
- Database storage: store serialized context alongside workflow state, then reuse it when the workflow resumes.
- Message queues: include context in the message payload so the consumer can continue the trace.
Database Storage Pattern
Persist span context with workflow state so you can resume a long-running trace later.- TypeScript
- Python
Message Queue Pattern
Include span context in your queued message payload so consumers can continue the trace.- TypeScript
- Python
Notes
- Within a service: prefer passing span objects and activating them (
withSpan/use_span) instead of serializing context (seesdk/manual-spans). - When context is unavailable: if deserialization fails or context is missing, start a new trace rather than crashing.
- Treat context as untrusted input: validate and fail open (see
sdk/context-utilities).
