Skip to content
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

Fix aiokafka multiple values headers error. #3332

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fcfangcc
Copy link

@fcfangcc fcfangcc commented Mar 5, 2025

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](

headers = _extract_send_headers(args, kwargs)
if headers is None:
headers = []
kwargs["headers"] = headers
).

If headers is present in args[5], these lines modify kwargs, causing headers to appear in both args and kwargs, leading to the error.

Example code triggering the issue(run with otel):

import asyncio

from aiokafka import AIOKafkaProducer


async def test():
    producer = AIOKafkaProducer(
        bootstrap_servers='bootstrap_servers',
    )
    await producer.start()
    await producer.send_and_wait('topic', value=b'test', headers=[])  # that's ok
    await producer.send_and_wait('topic', value=b'test')  # error here


asyncio.run(test())

Fixes # (issue)

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?

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

  • test_wrap_send_with_headers_as_args

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

Copy link

linux-foundation-easycla bot commented Mar 5, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: fcfangcc / name: fcfangcc (39e592d)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant