-
Notifications
You must be signed in to change notification settings - Fork 798
httpx: add the is_instrumented
flag to the transport
#3106
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
Draft
Kludex
wants to merge
18
commits into
open-telemetry:main
Choose a base branch
from
Kludex:instrument-transport-instead-of-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7f552db
httpx: instrument transport instead of client
Kludex 3902028
And now?
Kludex 70e8cab
fix typo
Kludex ee2ec22
Merge branch 'main' into instrument-transport-instead-of-client
Kludex de40117
Move the test around
Kludex 4f3b83d
try to fix the issue
Kludex e5f1579
fix issue
Kludex f42c678
make sure that test fails
Kludex 52471f9
make sure that test fails
Kludex f209059
Transport was not being passed...
Kludex ed97732
Fix test
Kludex b89ee8f
Add changelog entry
Kludex 7660a00
Do nothing on transport already instrumented
Kludex cd925e7
Empty-Commit
Kludex 9378dfd
Add _is_instrumented_by_opentelemetry to the transport
Kludex 9ed3ebb
Merge branch 'main' into instrument-transport-instead-of-client
Kludex 7095cd0
Update CHANGELOG.md
Kludex da3545e
Merge branch 'main' into instrument-transport-instead-of-client
xrmx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -890,7 +890,9 @@ def instrument_client( | |
that is called right before the span ends | ||
""" | ||
|
||
if getattr(client, "_is_instrumented_by_opentelemetry", False): | ||
if getattr( | ||
client._transport, "_is_instrumented_by_opentelemetry", False | ||
): | ||
_logger.warning( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't log a warning if someone instruments a new client with the same transport. So I think we need to keep the attribute and warning on the client, but silently do nothing if the transport is already instrumented. |
||
"Attempting to instrument Httpx client while already instrumented" | ||
) | ||
|
@@ -946,7 +948,7 @@ def instrument_client( | |
response_hook=response_hook, | ||
), | ||
) | ||
client._is_instrumented_by_opentelemetry = True | ||
client._transport._is_instrumented_by_opentelemetry = True | ||
if hasattr(client._transport, "handle_async_request"): | ||
wrap_function_wrapper( | ||
client._transport, | ||
|
@@ -972,7 +974,7 @@ def instrument_client( | |
async_response_hook=async_response_hook, | ||
), | ||
) | ||
client._is_instrumented_by_opentelemetry = True | ||
client._transport._is_instrumented_by_opentelemetry = True | ||
|
||
@staticmethod | ||
def uninstrument_client( | ||
|
@@ -987,9 +989,9 @@ def uninstrument_client( | |
unwrap(client._transport, "handle_request") | ||
for transport in client._mounts.values(): | ||
unwrap(transport, "handle_request") | ||
client._is_instrumented_by_opentelemetry = False | ||
client._transport._is_instrumented_by_opentelemetry = False | ||
elif hasattr(client._transport, "handle_async_request"): | ||
unwrap(client._transport, "handle_async_request") | ||
for transport in client._mounts.values(): | ||
unwrap(transport, "handle_async_request") | ||
client._is_instrumented_by_opentelemetry = False | ||
client._transport._is_instrumented_by_opentelemetry = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.