Skip to content

fix(confluent-kafka): populate bootstrap.servers span attributes#4423

Open
alliasgher wants to merge 4 commits intoopen-telemetry:mainfrom
alliasgher:fix-confluent-kafka-bootstrap-servers
Open

fix(confluent-kafka): populate bootstrap.servers span attributes#4423
alliasgher wants to merge 4 commits intoopen-telemetry:mainfrom
alliasgher:fix-confluent-kafka-bootstrap-servers

Conversation

@alliasgher
Copy link
Copy Markdown

Description

KafkaPropertiesExtractor.extract_bootstrap_servers was defined in utils.py but was never actually invoked anywhere in the instrumentation, so confluent-kafka spans were missing messaging.url, server.address, and server.port even though the extraction helper existed for it. This PR wires the helper up end-to-end.

Changes:

  • AutoInstrumentedProducer / AutoInstrumentedConsumer now capture the config dict passed to their constructor, and ProxiedProducer / ProxiedConsumer surface the wrapped instance's config if one is present.
  • extract_bootstrap_servers accepts both "bootstrap.servers" (the dotted key confluent-kafka uses) and "bootstrap_servers", tolerates list-valued configs, and returns None when no config is attached instead of raising AttributeError.
  • wrap_produce / wrap_poll / wrap_consume now pass the bootstrap servers through to _enrich_span, which sets messaging.url, server.address, and server.port (parsed from the first broker in the list).

Producer spans and consumer <topic> process spans both get the new attributes.

Fixes #4104

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Added test_producer_sets_bootstrap_servers_attributes and test_consumer_sets_bootstrap_servers_attributes that exercise the proxy path end-to-end and assert the new attributes.
  • Ran the full test_instrumentation.py suite (16 tests pass).

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Comment thread CHANGELOG.md Outdated
@tammy-baylis-swi tammy-baylis-swi moved this to Reviewed PRs that need fixes in Python PR digest Apr 14, 2026
@tammy-baylis-swi tammy-baylis-swi requested a review from a team April 14, 2026 22:02
KafkaPropertiesExtractor.extract_bootstrap_servers was defined but
never called, so confluent-kafka spans were missing messaging.url,
server.address, and server.port even though the extraction helper
existed for it.

- Capture the config dict in AutoInstrumentedProducer/Consumer and
  surface it on the Proxied{Producer,Consumer} wrappers.
- extract_bootstrap_servers now accepts both the "bootstrap.servers"
  dotted key (confluent-kafka standard) and "bootstrap_servers", and
  safely handles list-valued configs and instances without a config
  attribute.
- wrap_produce / wrap_poll / wrap_consume pull the config and pass
  it through _enrich_span, which sets messaging.url, server.address,
  and server.port (parsing host:port from the first broker).

Closes open-telemetry#4104

Signed-off-by: alliasgher <alliasgher123@gmail.com>
…link

Signed-off-by: alliasgher <alliasgher123@gmail.com>
@alliasgher alliasgher force-pushed the fix-confluent-kafka-bootstrap-servers branch from 366b445 to 73dd510 Compare April 14, 2026 23:24
Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Looks good, just noticed one thing that wasn't changed here but very close and would be good to fix. We can do in a separate PR if you prefer.

alliasgher and others added 2 commits April 16, 2026 01:28
The second _enrich_span call in wrap_produce also runs inside a producer
span but used RECEIVE. Align with the first path and with the semantic
conventions.

Signed-off-by: Ali <alliasgher123@gmail.com>
Copy link
Copy Markdown
Contributor

@tammy-baylis-swi tammy-baylis-swi left a comment

Choose a reason for hiding this comment

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

Thanks for revisions!

@github-project-automation github-project-automation bot moved this from Reviewed PRs that need fixes to Approved PRs in Python PR digest Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

[confluent-kafka] Dead code: extract_bootstrap_servers is never called, missing broker address in spans

3 participants