Trace a message across producer, broker, and consumer boundaries by carrying its creation context in message metadata and extracting it before processing.
Producer
Create a producer span around message creation or send work. Inject the active OpenTelemetry context into the message’s supported headers or metadata before publishing. For a batch, preserve the creation context for each message when the messaging client supports it.
Consumer
Extract context from each received message before starting its processing span. For one message with a direct causal relationship, the extracted context can be the parent when that matches the application flow. For batches, multiple independent producers, or processing inside another active request, use span links so no causal relationship is lost by choosing a single parent.
Conventions and safety
Use the OpenTelemetry messaging semantic conventions supported by the selected instrumentation version for system, destination, operation, and batch attributes. Those conventions evolve, so review version-specific guidance during upgrades.
Do not put credentials, personal data, or message bodies in trace context or baggage. Avoid high-cardinality identifiers as metric dimensions; retain per-message identifiers only when approved and necessary for trace-level diagnosis.