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

httpx: rewrite patching to use wrapt instead of subclassing client #2909

Merged
merged 19 commits into from
Oct 29, 2024

Conversation

xrmx
Copy link
Contributor

@xrmx xrmx commented Oct 16, 2024

Description

Porting of httpx instrumentation to patch async transport methods instead of substituting the client. That is because the current approach will instrument httpx by instantianting another client with a custom transport class and this will race with code already subclassing. This one uses wrapt to patch the default httpx transport classes.

A few changes of behavior to discuss:

  • we are patching the two default httpx transport classes, if you subclass something else it still won't be instrumented, still instrument_client should work
  • global uninstrument() will remove instrumentation from client instrumented with instrument_client but I think that's legit
  • would be nice to deprecate the client subclassing thing and remove a ton of code

There is still a couple of FIXME that would like to get a second opinion.

Fixes #2364
Fixes #2609

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 A

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

@xrmx xrmx changed the title WIP httpx: rewrote patching to use wrapt instead of subclassing client httpx: rewrote patching to use wrapt instead of subclassing client Oct 22, 2024
@xrmx xrmx marked this pull request as ready for review October 22, 2024 15:08
@xrmx xrmx changed the title httpx: rewrote patching to use wrapt instead of subclassing client httpx: rewrite patching to use wrapt instead of subclassing client Oct 24, 2024
@xrmx xrmx requested a review from a team as a code owner October 28, 2024 09:32
Copy link
Contributor

@lzchen lzchen left a comment

Choose a reason for hiding this comment

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

Some small comments but overall lgtm

@xrmx xrmx enabled auto-merge (squash) October 29, 2024 20:27
@xrmx xrmx merged commit f6b68d0 into open-telemetry:main Oct 29, 2024
536 checks passed
lmolkova pushed a commit to lmolkova/opentelemetry-python-contrib that referenced this pull request Oct 30, 2024
…pen-telemetry#2909)

httpx: rewrote patching to use wrapt instead of subclassing client

Porting of httpx instrumentation to patch async transport methods instead of substituting the client. That is because the current approach will instrument httpx by instantianting another client with a custom transport class and this will race with code already subclassing. This one uses wrapt to patch the default httpx transport classes.

---------

Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants