opentelemetry-python-contrib icon indicating copy to clipboard operation
opentelemetry-python-contrib copied to clipboard

Ensure httpx.get etc. get instrumented

Open dmontagu opened this issue 2 years ago • 4 comments

Description

This closes https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1742 — "httpx instrumentation doesn't work for httpx.get, httpx.post, etc.".

The httpx.get, httpx.post, etc. methods ultimately use httpx._api.request, which makes instantiates httpx._api.Client. But httpx.Client is modified during instrumentation without updating the value imported in the httpx._api module.

Fixing this was as easy as also patching the Client value in httpx._api.

Fixes #1742

Type of change

I am not sure if it counts as a feature or bug fix. I'm sure it could be argued both ways, but I decided to call it a bug fix.

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

How Has This Been Tested?

I made this change and confirmed that it caused spans from the HTTPX instrumentation to be nested properly in my observability backend. I can add tests with a bit of guidance about where to look/modify/what would be desired. But I'd like to get confirmation that this is likely to be accepted before putting in the effort.

Does This PR Require a Core Repo Change?

  • [X] No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • [X] Followed the style guidelines of this project
  • [ ] Changelogs have been updated
  • [ ] Unit tests have been added
  • [X] Documentation has been updated

I don't think a documentation change is necessary; I'll update changelogs after adding unit tests once confirmed this is desirable.

dmontagu avatar Oct 20 '23 19:10 dmontagu

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: dmontagu / name: David Montague (fa69a654b30cc9f0635e3718418be1026f14c183)
  • :white_check_mark: login: xrmx / name: Riccardo Magliocchetti (e3353acaff095447b244bc078710a1a466a2ad73)

Could this patch be considered for merging? We hit this gap in instrumentation in our deployments which relied on httpx.request method.

rbagd avatar Apr 24 '24 18:04 rbagd

At least a CHANGELOG entry is required.

xrmx avatar Apr 26 '24 07:04 xrmx

Possibly related to https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2364 cc @jeremydvoss

I can add tests with a bit of guidance about where to look/modify/what would be desired. But I'd like to get confirmation that this is likely to be accepted before putting in the effort.

I would accept this PR with a test 😄

aabmass avatar Apr 26 '24 18:04 aabmass

Closing as superseded by #2538

xrmx avatar May 30 '24 15:05 xrmx