-
Notifications
You must be signed in to change notification settings - Fork 682
Fix aiokafka multiple values headers error. #3332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xrmx
reviewed
Mar 7, 2025
instrumentation/opentelemetry-instrumentation-aiokafka/tests/test_utils.py
Outdated
Show resolved
Hide resolved
...n/opentelemetry-instrumentation-aiokafka/src/opentelemetry/instrumentation/aiokafka/utils.py
Show resolved
Hide resolved
Hi. I suggest add smth to tests: async def test_send_and_wait(self) -> None:
AIOKafkaInstrumentor().uninstrument()
AIOKafkaInstrumentor().instrument(tracer_provider=self.tracer_provider)
producer = await self.producer_factory()
add_message_mock: mock.AsyncMock = (
producer._message_accumulator.add_message
)
add_message_mock.side_effect = [mock.AsyncMock()(), mock.AsyncMock()()]
tracer = self.tracer_provider.get_tracer(__name__)
with tracer.start_as_current_span("test_span") as span:
await producer.send_and_wait("topic_1", b"value_1")
add_message_mock.assert_awaited_with(
TopicPartition(topic="topic_1", partition=1),
None,
b"value_1",
40.0,
timestamp_ms=None,
headers=[("traceparent", mock.ANY)],
)
assert (
add_message_mock.call_args_list[0]
.kwargs["headers"][0][1]
.startswith(
f"00-{format_trace_id(span.get_span_context().trace_id)}-".encode()
)
)
await producer.send_and_wait("topic_2", b"value_2")
add_message_mock.assert_awaited_with(
TopicPartition(topic="topic_2", partition=1),
None,
b"value_2",
40.0,
timestamp_ms=None,
headers=[("traceparent", mock.ANY)],
) |
@dimastbk Thank you for your suggestion. This test is more reasonable |
dimastbk
approved these changes
Mar 31, 2025
emdneto
approved these changes
Apr 10, 2025
xrmx
approved these changes
Apr 10, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When using the send_and_wait method, a TypeError occurs:
TypeError: original_send() got multiple values for argument 'headers'
This happens because of the following lines in the OpenTelemetry AIoKafka instrumentation code:
[opentelemetry-instrumentation-aiokafka/utils.py#L263-L266](
opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-aiokafka/src/opentelemetry/instrumentation/aiokafka/utils.py
Lines 263 to 266 in 81eaea5
If
headers
is present inargs[5]
, these lines modifykwargs
, causingheaders
to appear in bothargs
andkwargs
, leading to the error.Example code triggering the issue(run with otel):
Fixes # (issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.