Skip to content

starlette: use wrapt for patching instead of class replacement#3530

Closed
SrdjanLL wants to merge 2 commits into
open-telemetry:mainfrom
SrdjanLL:starlette-wrapt
Closed

starlette: use wrapt for patching instead of class replacement#3530
SrdjanLL wants to merge 2 commits into
open-telemetry:mainfrom
SrdjanLL:starlette-wrapt

Conversation

@SrdjanLL
Copy link
Copy Markdown
Contributor

Description

Moving starlette instrumentation to patch Starlette.__init__ method using wrapt instead of doing the class replacement to prevent potential ordering issues.

Left the behaviour of manual instrumentation methods of StarletteInstrumentor to work as it did before.

The core issue where this surfaced (#3476) has already been closed, but this was still a relevant improvement

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit tests

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 updated
  • Documentation has been updated

@SrdjanLL SrdjanLL requested a review from a team as a code owner May 22, 2025 11:00
Comment on lines 182 to 183
from starlette import applications
from starlette.routing import Match
Copy link
Copy Markdown
Contributor

@xrmx xrmx May 22, 2025

Choose a reason for hiding this comment

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

So if we don't have an ordering issue with other instrumentations then the value of switching to wrapt would be the removal of these top level imports and push them at a later time or move them under type checking. Do you see this achievable?

@codefromthecrypt
Copy link
Copy Markdown
Contributor

codefromthecrypt commented May 26, 2025

Would love a fix to the issue, if it is this, so that we don't need to manually do StarletteInstrumentor.instrument_app(app). There are an increasing number of applications using starlette due to the prevalence of JSON-RPC in genai agents, such as Google A2A.

Right now, you have to manually instrument the app in order to use "zero code instrumentation" (and successfully join agents in the same trace). The combination of "zero code" and also needing to patch your code doesn't make any sense. cc @aabmass

@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Mar 11, 2026
@github-actions
Copy link
Copy Markdown

This PR has been closed due to inactivity. Please reopen if you would like to continue working on it.

@github-actions github-actions Bot closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants