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

Add support for HTTPX instrumentation #461

Merged
merged 23 commits into from
Jun 8, 2021
Merged

Add support for HTTPX instrumentation #461

merged 23 commits into from
Jun 8, 2021

Conversation

jomasti
Copy link
Contributor

@jomasti jomasti commented Apr 20, 2021

Description

This builds off of the initial idea in this issue of using the
transport API in httpx. This allows for using custom transports.

This allows for manually creating transports to use with individual
clients and for instrumenting all created clients.

One issue with this current implementation is that there are few more
changes coming in 0.18.0 that this will probably want to use. So
maybe it will make sense to finalize this on that version before
releasing it. Want to get some eyes on this sooner.

Fixes #263

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Added unit tests for the transports used manually and for an instrumentor class

Does This PR Require a Core Repo Change?

  • 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 20, 2021

CLA Signed

The committers are authorized under a signed CLA.

@jomasti jomasti marked this pull request as ready for review April 20, 2021 03:54
@jomasti jomasti requested a review from a team as a code owner April 20, 2021 03:54
@jomasti jomasti requested review from owais and srikanthccv and removed request for a team April 20, 2021 03:54
@jomasti jomasti mentioned this pull request Apr 20, 2021
Copy link
Contributor

@owais owais left a comment

Choose a reason for hiding this comment

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

Thanks. Instrumentation LGTM. Left a few minor comments.

@jomasti
Copy link
Contributor Author

jomasti commented Apr 21, 2021

The docs check fails because of a missing requirement. It's added in #463, so I will rebase and update the versions once that is merged.

Copy link
Contributor

@owais owais left a comment

Choose a reason for hiding this comment

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

Thanks. Looks really good. Left a couple of questions.

@jomasti jomasti requested a review from owais April 26, 2021 03:48
@codeboten
Copy link
Contributor

@owais have your comments been addressed?

@jomasti
Copy link
Contributor Author

jomasti commented May 11, 2021

I have changes for 0.18.x of httpx that I still need to push up soon. Since that version formalizes the transport API, it should be the preferred base for this instrumentation.

@cdvv7788
Copy link
Contributor

cdvv7788 commented Jun 1, 2021

@jomasti Anything I can help with here? Very interested on this instrumentation.

jomasti added 16 commits June 1, 2021 15:18
This builds off of the initial idea in [this issue][1] of using the
transport API in `httpx`. This allows for using [custom transports][2].

One issue with this current implementation is that there are few more
[changes coming][3] in 0.18.0 that this will probably want to use. So
maybe it will make sense to finalize this on that version before
releasing it. Want to get some eyes on this sooner.

Resolves #263

[1]: encode/httpx#1264 (comment)
[2]: https://www.python-httpx.org/advanced/#custom-transports
[3]: encode/httpx#1522
This is to avoid calling `get_tracer` every time.
Replaces the span and name callbacks
Simplifies the usage of request/response hooks for consumers with
expected objects
Allows for instrumenting and uninstrumenting existing client instances
Not sure how that happened.
Back to only providing the raw arguments and return values instead of
using httpx Request and Response objects to avoid any additional
overhead or unexpected side effects.
Copy link
Contributor

@owais owais left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

Copy link
Contributor

@owais owais left a comment

Choose a reason for hiding this comment

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

Looks great. Just a suggestion to use namedtuple for hook args.

@lzchen
Copy link
Contributor

lzchen commented Jun 2, 2021

Have you gotten a chance to look at the instrumentation guidelines and expectations?

@jomasti
Copy link
Contributor Author

jomasti commented Jun 2, 2021

Have you gotten a chance to look at the instrumentation guidelines and expectations?

I have. Is there something specific you are wanting to highlight in those?

extensions=extensions,
)

span_attributes = _prepare_attributes(method, url)
Copy link
Contributor

Choose a reason for hiding this comment

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

Attributes should not be recorded if is_recording() is false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The attributes are not recorded in this function call, but later in _apply_status_code, which checks is_recording(). Do you suggest changing this to make it more clear?

@lzchen
Copy link
Contributor

lzchen commented Jun 4, 2021

@jomasti

It would be great if you could create issues for the features that are not included yet in this PR for this instrumentation (such as exclude_url and url_filter.

@jomasti
Copy link
Contributor Author

jomasti commented Jun 4, 2021

@lzchen Isn't exclude_urls meant for the server instrumentation? The example in the file points to Flask, and the other examples in the codebase are only other server instrumentation.

@lzchen
Copy link
Contributor

lzchen commented Jun 7, 2021

@jomasti
I don't believe that it was decided just for server instrumentations. I think it just so happens it is only implemented for server instrumentations :).

e.g. requests integration in OpenCensus has this feature.

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Just a minor comment in the setup file. @lzchen would it be ok to create a separate issue to add exclude_url functionality since the same functionality will be needed for requests as well.

Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Copy link
Contributor

Choose a reason for hiding this comment

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

Should include Python 3.9

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add it, but it looks like this is missing from almost all the other packages.

@lzchen
Copy link
Contributor

lzchen commented Jun 7, 2021

@codeboten

Yes that's fine. @jomasti No need to add these features in this PR. It would be great if you could create issues for them to track :)

@jomasti
Copy link
Contributor Author

jomasti commented Jun 8, 2021

@lzchen I can make an issue for the exclude urls feature. Looking at the functionality provided by the url filter in the example, it seems that the request hook functionality here should provide a way to accomplish the same thing. Or am I overlooking something?

- Move changelog entry
- Fix license copyright
- Add Python 3.9 classifier
@lzchen lzchen merged commit 9695bcf into open-telemetry:main Jun 8, 2021
@jomasti jomasti deleted the feature/httpx-instrumentation branch June 8, 2021 16:08
@lzchen lzchen mentioned this pull request Jan 18, 2022
7 tasks
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.

httpx support
5 participants