sentry-python
sentry-python copied to clipboard
Set correct parent span in async environment
How do you use Sentry?
Sentry Saas (sentry.io)
Version
1.9.10
Steps to Reproduce
- Have a FastAPI app
- Have a FastAPI middleware like this one: https://github.com/getsentry/demo-app-django-react/blob/main/backend/fastapi/main.py#L80-L101
- Do something in this middleware that creates a span (like the redis call in the span
- Reload an endpoint that uses this middleware
- Go to the "Performance" section of sentry.io and look at the event
- You will see this:

Expected Result
The redis span should be under the CounterMiddleware.
Actual Result
The redis span is under the AsyncExitStackMiddleware
This is also related with this amazing issue: https://github.com/getsentry/sentry-python/issues/1187
and https://github.com/getsentry/sentry-python/issues/772
also https://github.com/getsentry/sentry-python/issues/772#issuecomment-1270020139
and https://github.com/getsentry/sentry-python/issues/1333#issuecomment-1270030888