-
Notifications
You must be signed in to change notification settings - Fork 651
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
Create a tracer.decorate
decorator that work with async functions
#3595
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to actually change the behavior of tracer.start_as_current_span()
at all. It looks like this PR adds a new separate decorator
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
@QuentinN42 This doesn't seem to actually change the behavior of |
Yes as sayed in the initial comment, do you think I should create a custom sync and async contrxtmanager ? |
Do you have a backward compatible way to achieve this without adding to the API surface? I will bring this up in the Python SIG meeting tomorrow (you're welcome to attend if you're available). edit I think I've figured out a way to make it behave as expected if you need some help, lmk |
record_exception: bool = True, | ||
set_status_on_exception: bool = True, | ||
end_on_exit: bool = True, | ||
span_arg_name: str | None = "span", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense for this to be implemented by its own decorator? It could be a free function which is nice and could be stacked with other decorators if needed
@trace.start_as_current_span("foo")
@with_span_arg("the_span")
def foo(the_span: Span):
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can open an issue if you think it's a useful feature.
I have tested the get_current_span().set_attribute(...)
and I think it's a better way to make it works without surcharging the function parameters that must be more business oriented...
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
tracer.start_as_current_span()
decorator work with async functionstracer.decorate
decorator that work with async functions
Closing this MR in favor of #3633 |
Description
As we discussed in #3270, we want to be able to decorate functions with a span.
Currently it's not raising any exceptions, but async functions always reports a near zero span duration due to the result not beeing awaited.
But as context managers can be sync OR async but not both (@contextlib.asynccontextmanager), I've added a small method
Tracer.decorate
that do this job.I'm still not sure about the function name ... Any ideas are welcome :)
Type of change
How Has This Been Tested?
Not yet tested, here is my two tests idea :
Does This PR Require a Contrib Repo Change?
Answer the following question based on these examples of changes that would require a Contrib Repo Change:
opentelemetry-api/
oropentelemetry-sdk/
I dont think so, I'm in the "this functionality MAY be offered additionally as a separate operation" of Span creation.
Checklist: