-
Notifications
You must be signed in to change notification settings - Fork 515
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
Performances: How to bind the correct parent span with asyncio? #1187
Comments
I struggled a lot but I think I finally found the way to do it. Here is my from functools import wraps
import sentry_sdk
def traced_asyncio_task(func):
@wraps(func)
async def wrapper(*args, **kwargs):
with sentry_sdk.Hub(client.Hub.current) as hub:
with hub.scope.span.start_child(op='aiotask') as span:
span.set_tag('task', func.__name__)
return await func(*args, **kwargs)
return wrapper Now, I just have to wrap my tasks with
Can you confirm this is the way to go? Maybe this would benefit from being documented somewhere ? |
Yeah that decorator is probably your best bet going forward. We need to do some work to improve the documentation here, and possibly expose some nice decorators/wrapper func that make async use cases easier to use. Thanks for bringing this up, we will work on it. |
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
Hello,
I'm trying to implement Sentry performances tracing in an async context. Unfortunately, when I try to do it in a generic way, using
sentry_sdk.Hub.current.scope.span
, it fails to find the correct parent span to start a child.For instance, if I do the following:
It ends up like this:
All zip files extractions are bound to the same span, while each were handled by a different
get_distlib
span.Of course I can handle it specifically for this script, and create the span in my code instead of implementing it to my custom
TracedZipFile
class:This works perfectly:
However, this requires to pass the parent span through the whole chain of function calls, and always create spans manually, which is quite annoying.
I could make it partially generic by allowing to pass a span to my custom
TracedZipFile
:This avoids me to manually create the
io
span, but I still have to pass the parent span through function calls, which is not very DRY and not always possible.So my question is: Is there a way to retrieve the correct parent span?
Thank you very much !
The text was updated successfully, but these errors were encountered: