feat(dsm): add kafka_cluster_id to confluent-kafka-go#4470
Conversation
0c09dde to
7de417d
Compare
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: b893370 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
BenchmarksBenchmark execution time: 2026-03-19 19:23:04 Comparing candidate commit b893370 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 157 metrics, 7 unstable metrics.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files
🚀 New features to boost your workflow:
|
Plumb Kafka cluster ID through the DSM pipeline so that offsets and checkpoints from different clusters are distinguishable. For confluent-kafka-go, the cluster ID is fetched automatically via the AdminClient API; other Kafka libraries pass empty string for now and will be wired in follow-up PRs. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add cluster ID as a span tag on produce and consume spans, add ext constant MessagingKafkaClusterID, and add integration test verifying cluster ID flows into spans, DSM pathway hashes, and backlog tags. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Auto-fetched cluster ID from the Kafka admin API is now prepended to options so that user-provided WithClusterID takes precedence. Also fix TestConsumerFunctional pathway hash to account for auto-fetched cluster ID in integration test environments. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The TestConsumerFunctional test was computing expected pathway hashes without the kafka_cluster_id tag, but the production code now includes it after auto-fetching from the broker. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
702c277 to
f2cb692
Compare
Avoid repeated admin API calls to fetch cluster ID when creating multiple consumers/producers to the same Kafka cluster. The cache is shared between v1 and v2 packages via kafkatrace. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Remove the public WithClusterID option function which was only used internally and for testing. Set cluster ID directly on the tracer after wrapping instead. Also reduce cluster ID fetch timeout from 10s to 2s. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
mtoffl01
left a comment
There was a problem hiding this comment.
Other changes look fine, but my real concern is the blocking network call. I think we should prefer to leave cluster ID out until we have a response from the network. This can be achieved with goroutine/channel to allow async behavior > synchronous
Move cluster ID fetching to a background goroutine so it doesn't block Consumer/Producer creation. Protect the clusterID field with a RWMutex for safe concurrent access. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Move cluster ID goroutine lifecycle into the Tracer via FetchClusterIDAsync/WaitForClusterID. Close() waits for the goroutine to prevent use-after-free of the librdkafka handle. Tests call WaitForClusterID before producing/consuming to ensure deterministic pathway hashes. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f5b176c985
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
darccio
left a comment
There was a problem hiding this comment.
LGTM. Please check Codex's comment.
|
The failures are all |
Add kafka_cluster_id support to both IBM/sarama and Shopify/sarama, matching the pattern from the confluent-kafka-go integration (PR #4470): - cfg.ClusterID() / cfg.SetClusterID() with sync.RWMutex for thread-safe access from the message path and the background fetch goroutine - closeAsync []func() on wrapped producers for cancelling in-flight fetches on Close() - startClusterIDFetch launches a background goroutine that connects to a broker, sends a MetadataRequest v4, and calls cfg.SetClusterID() - WithBrokers(addrs) option provides broker addresses (required because sarama's producer/consumer interfaces don't expose broker info) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add kafka_cluster_id support to both IBM/sarama and Shopify/sarama, matching the pattern from the confluent-kafka-go integration (PR #4470): - cfg.ClusterID() / cfg.SetClusterID() with sync.RWMutex for thread-safe access from the message path and the background fetch goroutine - closeAsync []func() on wrapped producers for cancelling in-flight fetches on Close() - startClusterIDFetch launches a background goroutine that connects to a broker, sends a MetadataRequest v4, and calls cfg.SetClusterID() - WithBrokers(addrs) option provides broker addresses (required because sarama's producer/consumer interfaces don't expose broker info) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
6ae9763
into
main
) ## Summary - Adds `kafka_cluster_id` support to the `segmentio/kafka-go` DSM integration, building on #4470 - Auto-fetches the Kafka cluster ID via async metadata request in `WrapReader`/`WrapWriter` - Plumbs cluster ID through DSM edge tags, offset tracking, and span tags Tested this manually and via unit/integration tests. Co-authored-by: genesor <[email protected]> Co-authored-by: rob.carlan <[email protected]>
## Summary - This follows practically the same pattern as the [confluent-kafka-go](#4470) and [kafka-go](#4477) PRs. However, this integration requires the user to supply the bootstrap servers explicitly in order to obtain the cluster id. - Adds `WithBrokers` option to both IBM/sarama and Shopify/sarama integrations that fetches the Kafka cluster ID via a metadata request and includes it in DSM payloads (DSM only) - Tested manually and via unit / integration tests. Co-authored-by: genesor <[email protected]> Co-authored-by: rob.carlan <[email protected]>
Summary
Most DSM tracer instrumentations for Kafka enrich a kafka_cluster_id. This is useful because numerous generated metrics such as
data_streams.latencyanddata_streams.kafka.lag_messageswill automatically add this metric if present.In situations where people have the same topic names across multiple kafka clusters, the above metric will become incorrect without the cluster id tag. This PR adds feature parity for Go and collects this metric tag when DSM is enabled.
This is implemented by:
For context, the other tracers implement this as follows:
Java (doesn't block, intercepts the metadata response to enrich cluster id going forwards, see here and here)
Node (blocks, see here and here)
Python (blocks with a 1 second timeout, see here and here)
Test plan
Screenshots:
Spans have

kafka_cluster_id:Metric now adds

kafka_cluster_id:🤖 Generated with Claude Code