feat: add OpenTelemetry span links to MQTT pub/sub#3187
feat: add OpenTelemetry span links to MQTT pub/sub#3187majiayu000 wants to merge 1 commit intogofr-dev:developmentfrom
Conversation
Add trace context propagation to MQTT using payload wrapping, since MQTT v3.1.1 has no message-level headers. Publisher injects W3C trace context into a JSON envelope; subscriber extracts it and creates span links to the producer span. New file tracing.go provides headerCarrier, payload wrap/unwrap, and span creation helpers mirroring the Kafka and Google PubSub patterns already in GoFr. Signed-off-by: majiayu000 <1835304752@qq.com>
|
Hey @majiayu000 ! Thanks for the effort to make GoFr better. I also opened a PR #3101 to solve the same issue but the PR was closed as:
The core issue with both approaches comes down to MQTT protocol versions:
Your payload-wrapping approach does achieve span correlation, but it has a significant downside: it changes the actual message content. Any subscriber not using GoFr (or an older GoFr version) will receive a JSON envelope like {"payload": "...", "traceparent": "..."} instead of the original data. That's a silent breaking change for mixed The right path forward, as hinted by the maintainers, is to upgrade the MQTT driver to support MQTT 5.0, which would let us inject and extract trace context in User Properties — no payload modification needed, consistent with how Kafka/SQS/Google PubSub do it. |
Pull Request Template
Description:
tracing.goprovidesheaderCarrier(implementingpropagation.TextMapCarrier), payload wrap/unwrap, and span creation helpers.Breaking Changes (if applicable):
Additional Information:
go.opentelemetry.io/otelandgo.opentelemetry.io/otel/trace(already project dependencies).pkg/gofr/datasource/pubsub/kafka/tracing.goandpkg/gofr/datasource/pubsub/google/tracing.go.Checklist:
goimportandgolangci-lint.Thank you for your contribution!