sentry-python: Transaction doesn't work with FastAPI
How do you use Sentry?
Sentry Saas (sentry.io)
Version
1.38.0
Steps to Reproduce
- Create main.py
import sentry_sdk
from fastapi import FastAPI
import time
sentry_sdk.init(
dsn=$DSN,
profiles_sample_rate=1.0,
traces_sample_rate=1.0,
environment="dev",
release="1.0",
debug=True,
)
api = FastAPI()
@api.get("/sentry-debug")
async def trigger_error():
with sentry_sdk.start_transaction(op="task", name="test2"):
for _ in range(100):
time.sleep(0.01)
async def test1():
with sentry_sdk.start_transaction(op="task", name="test1"):
for _ in range(100):
time.sleep(0.01)
import asyncio
asyncio.run(test1())
- run
gunicorn main:api -k uvicorn.workers.UvicornWorker - Check sentry.io and confirm test1 showed up
- Open
http://localhost:8000/sentry-debugon browser - Can see this log on terminal
[sentry] DEBUG: [Tracing] Starting <task> transaction <test2>
[sentry] DEBUG: [Profiling] Initializing profile
[sentry] DEBUG: [Profiling] Starting profile
[sentry] DEBUG: [Profiling] Stopping profile
[sentry] DEBUG: [ASGI] Set transaction name and source in event_processor: '/sentry-debug' / 'route'
[sentry] DEBUG: [Profiling] Stopping profile
[sentry] DEBUG: Sending envelope [envelope with 2 items (profile, transaction)]
- Check sentry.io but don’t see test2
Expected Result
Both test1 and test2 on sentry.io
Actual Result
test1 works, but test2 doesn’t show up
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Reactions: 1
- Comments: 16 (8 by maintainers)
Thanks folks! We use fastapi 0.104.1 and sentry-sdk 1.38.0.
Just sent the email to support@sentry.io