Skip to content

Add support for HTTPX instrumentation - #461

Merged
lzchen merged 23 commits into
open-telemetry:mainfrom
jomasti:feature/httpx-instrumentation
Jun 8, 2021
Merged

Add support for HTTPX instrumentation#461
lzchen merged 23 commits into
open-telemetry:mainfrom
jomasti:feature/httpx-instrumentation

Conversation

@jomasti

@jomastijomasti commented Apr 20, 2021

Copy link
Copy Markdown
Contributor

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

linux-foundation-easyclaBot commented Apr 20, 2021

Copy link
Copy Markdown

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 review from a team, owais and srikanthccv and removed request for a teamApril 20, 2021 03:54
@jomastijomasti mentioned this pull request Apr 20, 2021

@owaisowais left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threaddocs/nitpick-exceptions.ini Outdated
Comment threadinstrumentation/opentelemetry-instrumentation-httpx/README.rst Outdated
@jomasti

Copy link
Copy Markdown
ContributorAuthor

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.

@owaisowais left a comment

Copy link
Copy Markdown
Contributor

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 owaisApril 26, 2021 03:48
@codeboten

Copy link
Copy Markdown
Contributor

@owais have your comments been addressed?

@jomasti

Copy link
Copy Markdown
ContributorAuthor

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

cdvv7788 commented Jun 1, 2021

Copy link
Copy Markdown
Contributor

@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]: https://github.com/encode/httpx/issues/1264#issuecomment-732034750
[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.

@owaisowais left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thanks!

@owaisowais left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadinstrumentation/opentelemetry-instrumentation-httpx/setup.cfg Outdated
@lzchen

lzchen commented Jun 2, 2021

Copy link
Copy Markdown
Contributor

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

@jomasti

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
Contributor

@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
Copy Markdown
ContributorAuthor

@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
Copy Markdown
Contributor

@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.

@codebotencodeboten left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
Contributor

@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
Copy Markdown
ContributorAuthor

@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:mainJun 8, 2021
@jomasti
jomasti deleted the feature/httpx-instrumentation branch June 8, 2021 16:08
@lzchenlzchen mentioned this pull request Jan 18, 2022
7 tasks
Sign up for freeto 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

@jomasti@codeboten@cdvv7788@lzchen@owais