Skip to content

Conversation

@bourbonkk
Copy link
Contributor

Description

This PR addresses duplicate instrumentation of Future objects when using AsyncioInstrumentor multiple times on the same Future. Without proper de-duplication, callbacks can continue to accumulate and cause memory leaks. This change introduces a simple attribute check on each Future, coroutine, or function so that once instrumented, no additional callbacks or spans will be attached.

Fixes #3383 aiokafka instrumentation cause memory leak

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

  • Unit Tests:
    • Added a new test file (test_asyncio_duplicate_instrument.py) which repeatedly calls trace_future on the same Future objects.
    • Verified that the callback count does not grow beyond a small constant (1–2 callbacks).
  • Manual Verification:
    • Mocked up a simple scenario mimicking aiokafka.GroupCoordinator usage, confirming that repeated instrumentation does not cause exponential callback growth.

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

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Apr 4, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@xrmx xrmx changed the title #3383 fix duplicate instrument asyncio: fix duplicate instrumentation Apr 4, 2025
@xrmx
Copy link
Contributor

xrmx commented Apr 4, 2025

@bourbonkk looks like you commited with multiple accounts and one has not signed the CLA

@xrmx xrmx moved this to Reviewed PR that needs fixing in @xrmx's Python PR digest Apr 4, 2025
@bourbonkk bourbonkk requested a review from a team as a code owner April 4, 2025 07:54
@bourbonkk bourbonkk closed this Apr 4, 2025
@github-project-automation github-project-automation bot moved this from Reviewed PR that needs fixing to Done in @xrmx's Python PR digest Apr 4, 2025
@bourbonkk bourbonkk reopened this Apr 4, 2025
@xrmx xrmx moved this from Done to Ready for review in @xrmx's Python PR digest Apr 4, 2025
@bourbonkk bourbonkk removed their assignment Apr 4, 2025
Copy link

@yonathan-wolloch-lendbuzz yonathan-wolloch-lendbuzz left a comment

Choose a reason for hiding this comment

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

Thank you!

@xrmx xrmx moved this from Done to Ready for review in @xrmx's Python PR digest Apr 9, 2025
@bourbonkk
Copy link
Contributor Author

@xrmx
I believe I’ve made all the necessary changes in this PR. I’d appreciate it if you could review and let me know if anything else is required.

Copy link
Member

@aabmass aabmass left a comment

Choose a reason for hiding this comment

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

I don't want to block this since it's an improvement. Please just address comments

@aabmass aabmass enabled auto-merge (squash) April 15, 2025 15:46
…telemetry/instrumentation/asyncio/instrumentation_state.py
@aabmass aabmass merged commit fce17db into open-telemetry:main Apr 15, 2025
720 checks passed
@github-project-automation github-project-automation bot moved this from Ready for review to Done in @xrmx's Python PR digest Apr 15, 2025
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.

asyncio duplicated instrumentation cause memory leak

5 participants