Skip to content

feat(kafka): add span links for pub/sub tracing#2952

Merged
coolwednesday merged 10 commits intogofr-dev:developmentfrom
VIDHITTS:add-pubsub-tracing-reproduction-test
Feb 20, 2026
Merged

feat(kafka): add span links for pub/sub tracing#2952
coolwednesday merged 10 commits intogofr-dev:developmentfrom
VIDHITTS:add-pubsub-tracing-reproduction-test

Conversation

@VIDHITTS
Copy link
Contributor

@VIDHITTS VIDHITTS commented Feb 3, 2026

Description:

  • Implements OpenTelemetry span links for Kafka pub/sub tracing
  • Addresses issue Support Span links for PubSub Tracing #2650
  • Enables proper async correlation between producers and consumers following OTel messaging semantic conventions. Previously, subscriber spans created new disconnected traces. Now they create spans with links to producer spans.

Breaking Changes (if applicable):

  • No breaking changes. Kafka messages now include trace context headers, which are ignored by consumers not expecting them.

Additional Information:

  • Uses go.opentelemetry.io/otel for trace context propagation
  • W3C TraceContext format for header injection/extraction
  • This is the first phase (Kafka only). Other backends will follow in separate PRs.

Checklist:

  • I have formatted my code using goimport and golangci-lint.
  • All new code is covered by unit tests.
  • This PR does not decrease the overall code coverage.
  • I have reviewed the code comments and documentation for clarity.

Thank you for your contribution!

@VIDHITTS VIDHITTS force-pushed the add-pubsub-tracing-reproduction-test branch 2 times, most recently from 6abc11b to bac2358 Compare February 3, 2026 09:02
@coolwednesday
Copy link
Member

Please fix the title of the PR.

@VIDHITTS VIDHITTS changed the title Add pubsub tracing reproduction test feat(kafka): add span links for pub/sub tracing Feb 3, 2026
@VIDHITTS VIDHITTS force-pushed the add-pubsub-tracing-reproduction-test branch from bac2358 to 8e7e2af Compare February 3, 2026 09:06
@VIDHITTS
Copy link
Contributor Author

VIDHITTS commented Feb 3, 2026

@coolwednesday , have renamed the title

@VIDHITTS VIDHITTS force-pushed the add-pubsub-tracing-reproduction-test branch from a628f22 to f387d98 Compare February 4, 2026 05:50
@coolwednesday
Copy link
Member

@coolwednesday , have renamed the title

Thanks ! Will review.

Copy link
Member

@coolwednesday coolwednesday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tracer name is currently set to "gofr". It would be better to use a constant or a more specific package-level name (for example, gofr.dev/pkg/gofr/datasource/pubsub/kafka). This makes it easier for users to filter and identify traces by the source library.

Verifying span links with GoFr + Jaeger (Docker)

To validate your span link implementation:

  • Jaeger stores spans with links and converts those links into references (typically FOLLOWS_FROM).
  • You can inspect these in the Jaeger UI at localhost:16686 under span details.
  • Jaeger does not show a dedicated “span link” label — links appear as normal references.

If you see additional FOLLOWS_FROM references, it indicates your span links are being exported correctly.

@VIDHITTS VIDHITTS force-pushed the add-pubsub-tracing-reproduction-test branch 2 times, most recently from f0a8b8d to 495e1f4 Compare February 5, 2026 12:10
@coolwednesday
Copy link
Member

@VIDHITTS, Also, Please do add screenshot.

@VIDHITTS
Copy link
Contributor Author

VIDHITTS commented Feb 5, 2026

Span Links Verification with Jaeger

Screenshot 2026-02-05 at 21 19 05

The screenshot shows the kafka-subscribe span in Jaeger UI with:

  • Service: kafka-span-links-demo
  • Tags:
    • messaging.system = kafka
    • messaging.operation = receive
    • messaging.destination.name = test-span-links
  • References (1): FOLLOWS_FROM link to the producer span (SpanID: 76d60bffb8ea893c)

This confirms that:

  1. Producer injects W3C trace context into Kafka headers
  2. Consumer extracts trace context and creates a span linked to the producer
  3. Span links appear as FOLLOWS_FROM references in Jaeger (as expected per OTel messaging conventions)

@VIDHITTS VIDHITTS force-pushed the add-pubsub-tracing-reproduction-test branch from 495e1f4 to 3b58e83 Compare February 7, 2026 17:06
@VIDHITTS VIDHITTS force-pushed the add-pubsub-tracing-reproduction-test branch from 3b58e83 to 8271e43 Compare February 11, 2026 04:16
@coolwednesday coolwednesday merged commit 3114f2d into gofr-dev:development Feb 20, 2026
16 checks passed
@VIDHITTS
Copy link
Contributor Author

Hi @coolwednesday and @Umang01-hash,

Thank you for reviewing and merging the Kafka implementation!

Since the Kafka phase is finalized, I am ready to generalize this approach for the remaining pub/sub backends (Google Pub/Sub, NATS, SQS, etc.) to fully close out this issue.

How would you prefer I handle the remaining implementations?

Raise one combined PR for all remaining backends?

Raise individual, separate PRs for each backend?
Let me know how you'd like me to proceed with the backends!

rohansood10 added a commit to rohansood10/gofr that referenced this pull request Feb 21, 2026
Implement OpenTelemetry span links for SQS pub/sub tracing following
the same pattern established in the Kafka implementation (PR gofr-dev#2952).

- Add attributeCarrier implementing propagation.TextMapCarrier for
  SQS MessageAttributes
- Inject trace context into message attributes during Publish
- Extract trace context from message attributes during Subscribe
  and create span links to the producer span
- Request 'All' MessageAttributeNames in ReceiveMessage to ensure
  trace context attributes are returned
- Add comprehensive unit tests for carrier, injection, extraction,
  and span creation

Fixes gofr-dev#3015
rohansood10 added a commit to rohansood10/gofr that referenced this pull request Feb 21, 2026
Implement OpenTelemetry span links for Google Cloud Pub/Sub tracing
following the same pattern established in the Kafka implementation
(PR gofr-dev#2952).

- Add attributeCarrier implementing propagation.TextMapCarrier for
  GCP PubSub message Attributes (map[string]string)
- Inject trace context into message attributes during Publish
- Extract trace context from message attributes during Subscribe
  and create span links to the producer span
- Move span creation in Subscribe to after message receipt so headers
  are available for link extraction
- Add comprehensive unit tests for carrier, injection, extraction,
  and span creation

Fixes gofr-dev#3011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants