Skip to content

fix(confluent-kafka): skip recv spans when poll/consume returns no messages#4349

Merged
xrmx merged 2 commits intoopen-telemetry:mainfrom
sterchelen:fix/confluent-kafka-skip-empty-recv-spans
Mar 25, 2026
Merged

fix(confluent-kafka): skip recv spans when poll/consume returns no messages#4349
xrmx merged 2 commits intoopen-telemetry:mainfrom
sterchelen:fix/confluent-kafka-skip-empty-recv-spans

Conversation

@sterchelen
Copy link
Copy Markdown
Contributor

Description

Matches Java instrumentation behavior: only create a recv span when a message is actually received, avoiding empty spans on idle polls.

Fixes #3590

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Added two new unit tests to cover the empty cases:

test_poll_empty_does_not_create_span: calls poll() on an empty queue twice and asserts no spans are produced
test_consume_empty_does_not_create_span: calls consume() on an empty queue twice and asserts no spans are produced
Existing tests (test_poll, test_consume) were updated to reflect that idle polls/consumes no longer produce recv spans.

  • Test A: py312-test-instrumentation-confluent-kafka — 12 passed

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

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

@sterchelen sterchelen requested a review from emdneto March 23, 2026 10:05
Copy link
Copy Markdown
Member

@emdneto emdneto left a comment

Choose a reason for hiding this comment

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

one more fix for precommit:
tox -e precommit and add the changelog.

@sterchelen sterchelen force-pushed the fix/confluent-kafka-skip-empty-recv-spans branch from d169f4b to 973aaf0 Compare March 24, 2026 07:53
@sterchelen sterchelen requested a review from a team as a code owner March 24, 2026 07:53
…ssages

Matches Java instrumentation behavior: only create a recv span when a
message is actually received, avoiding empty spans on idle polls.

Fixes open-telemetry#3590
@sterchelen sterchelen force-pushed the fix/confluent-kafka-skip-empty-recv-spans branch from 973aaf0 to d6bdd1d Compare March 24, 2026 07:54
@sterchelen
Copy link
Copy Markdown
Contributor Author

one more fix for precommit: tox -e precommit and add the changelog.

Thank you @emdneto for your assistance 🙇🏼‍♂️ ; should be good now 👍🏼

@sterchelen sterchelen requested a review from emdneto March 24, 2026 07:55
@emdneto emdneto moved this to Easy to review / merge / close in Python PR digest Mar 24, 2026
@xrmx
Copy link
Copy Markdown
Contributor

xrmx commented Mar 25, 2026

Checked that the kafka-clients 2.6 java instrumentations checks for records before tracing.

@xrmx xrmx moved this from Easy to review / merge / close to Approved PRs in Python PR digest Mar 25, 2026
@xrmx xrmx merged commit 70f2b8c into open-telemetry:main Mar 25, 2026
860 checks passed
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest Mar 25, 2026
@sterchelen sterchelen deleted the fix/confluent-kafka-skip-empty-recv-spans branch March 25, 2026 14:06
wrisa pushed a commit to wrisa/opentelemetry-python-contrib that referenced this pull request Mar 26, 2026
…ssages (open-telemetry#4349)

Matches Java instrumentation behavior: only create a recv span when a
message is actually received, avoiding empty spans on idle polls.

Fixes open-telemetry#3590

Co-authored-by: Emídio Neto <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[confluent-kafka] Avoid empty recv spans

3 participants