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

Tornado attributes #706

Merged
merged 8 commits into from
Oct 4, 2021
Merged

Tornado attributes #706

merged 8 commits into from
Oct 4, 2021

Conversation

remram44
Copy link
Contributor

@remram44 remram44 commented Oct 1, 2021

Description

  • Set http.client_ip instead of net.peer.ip: the value is changed by Tornado to X-Forwarded-For or X-Real-IP, see Tornado code, see spec
    • The actual net.peer.ip is in _orig_remote_ip, however I thought it best not to read a private field. Let me know if it's ok.
  • Set handler to the fully-qualified name of the request handler class
    • The Tornado instrumentation does not provide any route information, such as http.route, only the base handler class's name as the span name. I didn't find an easy way to read the route pattern, the name of the handler seems like the next best thing

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • tox -e py38-test-instrumentation-tornado (TestTornadoInstrumentation updated)

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • 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

Tornado sets remote_ip to the value of X-Forwarded-For or X-Real-IP if
the 'xheaders' setting is set.
The spec has a 'http.route' which unfortunately seems difficult to get
at. However the full class name is readily available and most helpful.
@remram44 remram44 requested a review from a team October 1, 2021 19:33
@@ -252,6 +249,11 @@ def _get_operation_name(handler, request):
return f"{class_name}.{request.method.lower()}"


def _get_full_handler_name(handler):
klass = type(handler)
return f"{klass.__module__}.{klass.__qualname__}"
Copy link
Contributor

Choose a reason for hiding this comment

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

would this work fine for dynamically generated handlers within a function? I know that is not very common but sounds like an edge case. Any concerns regarding that?

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 believe __qualname__ would do the right thing with closures, see the examples in PEP 3155

@owais
Copy link
Contributor

owais commented Oct 1, 2021

The actual net.peer.ip is in _orig_remote_ip, however I thought it best not to read a private field. Let me know if it's ok.

that is OK as long as we do it defensively

@remram44
Copy link
Contributor Author

remram44 commented Oct 1, 2021

I added reading net.peer.ip from _orig_remote_ip, if it's present

Off-topic: I see the hacktoberfest topic is set on some open-telemetry repos but not here, I'm not sure if it's on purpose 😉

@owais
Copy link
Contributor

owais commented Oct 1, 2021

Last time there was a "fest" we had a few dozen people open PRs to add new lines in markdown files to earn some free merch 😂 is this similar?

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. Please take care of the comments.

if request.remote_ip:
attrs[SpanAttributes.NET_PEER_IP] = request.remote_ip
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment here for future contributors describing why we assign these to different attributes.

@remram44
Copy link
Contributor Author

remram44 commented Oct 1, 2021

Done!

hacktoberfest is usually ok in my experience, last year really did not go well. I believe they have made some changes to the procedure this year but I can't vouch for the masses.

remram44 and others added 5 commits October 3, 2021 20:54
@remram44
Copy link
Contributor Author

remram44 commented Oct 4, 2021

(this should take care of test failures)

@owais owais merged commit 3b5071b into open-telemetry:main Oct 4, 2021
@remram44 remram44 deleted the tornado-attributes branch October 4, 2021 16:02
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.

3 participants