Skip to content

Implement Trace Context Propagation over NATS #19

Description

@taitelee

Problem

When the API publishes a message to NATS and the Worker picks it up, the "trace" normally breaks. The Worker starts a new trace, making it impossible to see that the Worker's action was caused by a specific API call. This is known as a "Context Gap."

Proposed Solution

Use OpenTelemetry's TextMapPropagator to inject and extract trace headers.

  • Producer (API): Before publishing to NATS, "inject" the current span context into the NATS message headers.
  • Consumer (Worker): Upon receiving a message, "extract" the context from the headers and use it as the parent for the Worker's new span.

Alternatives Considered

Passing IDs in JSON payload: Rejected as it litters the business logic with telemetry data. Using NATS headers keeps the payload clean.

Additional Context

None

Metadata

Metadata

Assignees

Labels

area/observabilityMetrics, logs, traces, health, profilingenhancementNew feature or request

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions