Skip to content

@opentelemetry/instrumentation-kafkajs: Add brokerAddress attribute support (requires narrowing supported versions) #2770

Open
@AvihuHenya

Description

@AvihuHenya
  • This only affects the JavaScript OpenTelemetry library
  • This may affect other libraries, but I would like to get opinions here first

I’ve been working on improving the kafkajs instrumentation by adding support for capturing the Kafka broker address as an attribute.
The Kafka broker address can be extracted from the brokerAddress property in kafkajs — however, this property only exists from kafkajs v1.4.1 onwards.

Current situation

  • The current instrumentation supports kafkajs >=0.3.0 <3.
  • Adding server.address would be a valuable enhancement, but would require narrowing the supported range to >=1.4.1 <3.

Proposed change

  • Update the instrumentation to add brokerAddress (ATTR_SERVER_ADDRESS) (for producer spans at this time).
  • Adjust the supported versions in the instrumentation to >=1.4.1 <3.

Why this should be safe

  • Looking at kafkajs version download statistics on npm, versions below 1.4.1 account for a very small percentage of downloads.
  • This means the impact of narrowing the supported range will be minimal and unlikely to affect most users.

Benefits

  • Aligns with OpenTelemetry semantic conventions for messaging systems.
  • Provides more granular and valuable telemetry data for tracing Kafka communications.

Questions for maintainers
Are you open to narrowing the supported range as part of this enhancement?
If yes, would you like me to open a PR with the changes and the version range adjustment?

My current progress
I already have a working local implementation that:

  • Patches the appropriate kafkajs internals
  • Adds the broker address as a span attribute
  • Handles injection and context propagation properly

Happy to polish it and contribute if this direction makes sense!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions