Skip to content

opentelemetry-instrumentation-starlette: fix memory leak and double middleware #3529

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 4 commits into from
Jun 3, 2025

Conversation

anuraaga
Copy link
Contributor

@anuraaga anuraaga commented May 22, 2025

Description

Fixes memory leak from using set, which prevents __del__, which means starlette apps can never be garbage collected.

Fixes adding two middlewares if instrument_app is called with auto instrumentation active

/cc @xrmx

Type of change

  • [] 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 of latest and oldest

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

@anuraaga anuraaga requested a review from a team as a code owner May 22, 2025 06:36
@anuraaga anuraaga changed the title Remove starlette version ceiling opentelemetry-instrumentation-starlette: remove starlette version ceiling May 22, 2025
@anuraaga anuraaga marked this pull request as draft May 22, 2025 06:59
@xrmx
Copy link
Contributor

xrmx commented May 22, 2025

@anuraaga this is ready to review since you fixed the testcase right?

@anuraaga anuraaga marked this pull request as ready for review May 22, 2025 07:17
@anuraaga
Copy link
Contributor Author

FYI @codefromthecrypt

@anuraaga
Copy link
Contributor Author

@anuraaga this is ready to review since you fixed the testcase right?

Yup should be ok now

@anuraaga
Copy link
Contributor Author

Oh no, I didn't check existing PRs before making this one and now see @MattiasDC's #3456 is quite similar. I found the tests seem to pass fine for the current baseline version so didn't raise it here which is the main difference. Feel free to reject this PR as a duplicate and get that one in instead though, then I can send another one with just the WeakSet and other fixes which should still apply.

Copy link
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.

@anuraaga Thank you for the fix! To be fair with the already opened PR #3456 I would suggest that we proceed with #3456 and later you can modify your PR with the changes you are proposing here (weakset and the fix for the already instrumented flag)

@anuraaga anuraaga marked this pull request as draft May 23, 2025 05:28
@emdneto
Copy link
Member

emdneto commented May 23, 2025

@anuraaga #3456 was merged.

@anuraaga anuraaga force-pushed the starlette-update-latest branch from dee09c0 to 3aebb34 Compare May 30, 2025 01:46
@anuraaga anuraaga changed the title opentelemetry-instrumentation-starlette: remove starlette version ceiling opentelemetry-instrumentation-starlette: fix memory leak and double middleware May 30, 2025
Copy link
Contributor Author

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

Thanks @emdneto have rebased this PR

@anuraaga anuraaga marked this pull request as ready for review May 30, 2025 01:48
Co-authored-by: Joe McGinley <[email protected]>
@xrmx xrmx requested a review from emdneto June 3, 2025 08:42
@xrmx xrmx enabled auto-merge (squash) June 3, 2025 13:46
@xrmx xrmx merged commit b9a78e7 into open-telemetry:main Jun 3, 2025
625 checks passed
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.

4 participants