Skip to content

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

Open
sterchelen wants to merge 1 commit intoopen-telemetry:mainfrom
sterchelen:fix/confluent-kafka-skip-empty-recv-spans
Open

fix(confluent-kafka): skip recv spans when poll/consume returns no messages#4349
sterchelen wants to merge 1 commit intoopen-telemetry:mainfrom
sterchelen:fix/confluent-kafka-skip-empty-recv-spans

Conversation

@sterchelen
Copy link

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

…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
):
record = func(*args, **kwargs)
if record:
record = func(*args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

can you make a test to assert _current_consume_span and _current_context_token are correctly cleaned up on the empty path?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[confluent-kafka] Avoid empty recv spans

2 participants