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

ext/requests - apply custom attributes callback #656

Conversation

nirsky
Copy link
Contributor

@nirsky nirsky commented May 7, 2020

This PR implements passing an optional span_callback callback when instrumenting requests.
The callback will be called just before returning the result and will be invoked with the span and the result (type of requests.Response).
This mimics the same functionality as in js http plugin.

Example:

import requests
from opentelemetry.ext.requests import RequestsInstrumentor
from opentelemetry.sdk.trace.export import Span

def apply(span: Span, result: requests.Response):
    span.set_attribute("http.request.body", result.request.body)

RequestsInstrumentor().instrument(
    span_callback=apply
)

Please LMK if and what docs need to be updated.

@nirsky nirsky requested a review from a team May 7, 2020 07:39
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.

Thanks! The code looks good, just want to discuss the naming of the argument and make sure it's succinct.

Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal left a comment

Choose a reason for hiding this comment

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

LGTM, some minor comments.

I second @toumorokoshi about the callback name, it could be more generic. Approving now assuming you'll handle it :)

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.

Great, thanks!

@toumorokoshi toumorokoshi merged commit b2e671a into open-telemetry:master May 11, 2020
owais pushed a commit to owais/opentelemetry-python that referenced this pull request May 22, 2020
Implement passing an optional span_callback callback when instrumenting requests.

The callback will be called just before returning the result and will be invoked with the span and the result (type of requests.Response).

This mimics the same functionality as the js http plugin.
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