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

RequestsInstrumentor: Add support for prepared requests #1040

Merged

Conversation

mariojonke
Copy link
Contributor

@mariojonke mariojonke commented Aug 25, 2020

Description

The RequestsInstrumentor was currently only instrumeting Session.request. Sending a prepared request with a direct call to Session.send were not tracked.
This PR adds instrumentation support for prepared requests by instrumenting Session.send in addition to Session.request.

Type of change

Please delete options that are not relevant.

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

How Has This Been Tested?

Additional unit tests for sending prepared requests were added.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added

in addition to Session.request instrument Session.send to also
create spans for prepared requests.
@mariojonke mariojonke requested a review from a team as a code owner August 25, 2020 14:34
Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

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

LGTM! I think the test code can use a bit more of a refactor, but the execution looks good.

currently not traced. If you find any other way to trigger an untraced HTTP
request, please report it via a GitHub issue with :code:`[requests: untraced
API]` in the title.
If you find any way to trigger an untraced HTTP request, please report it via a
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if this comment even needs to be in the code? An uninstrumented trace feels like a self-evident issue.

def instrumented_send(self, request, **kwargs):
def get_or_create_headers():
request.headers = (
request.headers if request.headers is not None else {}
Copy link
Member

Choose a reason for hiding this comment

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

this could also be request.headers or {}, although it comes with a little less type safety.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

an empty request.headers would actually change the type from CaseInsensitiveDict to a plain dict.
i guess in the else clause should also use a CaseInsensitiveDict

httpretty.disable()


class TestRequestsIntegration(TestBase, RequestsIntegrationTestBase):
Copy link
Member

Choose a reason for hiding this comment

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

I believe you could actually incorporate this setup and teardown code into RequestsIntegrationTestBase.

abc.ABC is okay to use as a second parent class, and will still have the abstractmethod enforcing logic as if it was the first class passed.

Then you can just subclass everything from TestRequestsBase as before.

@mariojonke
Copy link
Contributor Author

Hm.., TestFlask.test_flask is failing with [Errno 111] Connection refused. Doesn't seem to be related to this change since the failing request is not instrumented. Also the backtrace in the failing test does not show any instrumenteation code running

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.

LGTM, the failing test is related to a flaky test captured in #1044

@codeboten codeboten merged commit 140e5f9 into open-telemetry:master Sep 2, 2020
@mariojonke mariojonke deleted the requests-instrument-prepared branch April 13, 2021 07:56
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.

None yet

3 participants