Skip to content

feat(kafka): add messaging.kafka.cluster.id to producer and consumer spans #18977

Description

@shashank-reddy-nr

Is your feature request related to a problem? Please describe.

When a service connects to multiple Kafka clusters, or when the same topic name exists across environments (dev/staging/prod), Kafka spans carry no information about which cluster a message came from. messaging.kafka.cluster.id is defined in the OTel messaging semantic conventions for Kafka but is not currently set by this instrumentation — making it impossible to distinguish spans by cluster from telemetry alone.

Describe the solution you'd like

Add messaging.kafka.cluster.id as a span attribute on both producer and consumer spans. The cluster ID is read from the client's own already-fetched Metadata object — no AdminClient, no extra broker connection, no additional security config. The attribute is opt-in (gated behind otel.instrumentation.kafka.experimental-span-attributes) and cached per client instance after the first successful read.

Implementation handles Kafka 3.7+ correctly: KafkaConsumer became a thin delegate wrapper in 3.7 (KIP-848) and no longer holds metadata directly — the fix walks KafkaConsumer.delegate → LegacyKafkaConsumer to find the metadata field.

Cross-language effort

This feature is being added consistently across all four OTel language instrumentations:

Describe alternatives you've considered

  • Extracting from consumer metrics() tags — Kafka does not expose the cluster ID as a standard metric tag, so this is not reliable across versions.
  • Requiring users to configure the cluster ID manually — eliminates the zero-config goal.

Additional context

messaging.kafka.cluster.id is defined in the OTel semconv incubating attributes (KIP-78). The attribute is gated behind the existing otel.instrumentation.kafka.experimental-span-attributes flag. A working implementation with staging verification is ready.

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestneeds triageNew issue that requires triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions