Skip to content

Transaction name not set for FastApi in sentry-python 1.9.7 #1599

@sturaipo

Description

@sturaipo

How do you use Sentry?

Self-hosted/on-premise

Version

1.9.7

Steps to Reproduce

Sample code to reproduce the issue:

from datetime import datetime

import sentry_sdk
from fastapi import FastAPI
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware

app = FastAPI()


SENTRY_DSN = "<redacted>"


sentry_sdk.init(
    dsn=SENTRY_DSN,
    environment="dev",
    traces_sample_rate=1,
    release=f"test-transaction-name:0.01",
)


@app.get("/{par}")
async def root(par: str | None):
    with sentry_sdk.configure_scope() as scope:
        scope.set_transaction_name(f"test sentry transaction {par}")
        return {"message": "Hello World", "time": str(datetime.utcnow())}


app = SentryAsgiMiddleware(app)

Then call the api with curl:

$ curl http://127.0.0.1:8000/test1                                                                                                                             [6:48:48]
{"message":"Hello World","time":"2022-09-05 10:53:08.987063"}%

$ curl http://127.0.0.1:8000/test1                                                                                                                             [6:53:08]
{"message":"Hello World","time":"2022-09-05 10:53:10.981846"}%

$ curl http://127.0.0.1:8000/test2                                                                                                                             [6:53:10]
{"message":"Hello World","time":"2022-09-05 10:53:12.449257"}%

Expected Result

Transaction are stored in sentry with the expected transaction names:

  • test sentry transaction test1
  • test sentry transaction test2

Actual Result

Sentry stores these transactions with the default name:

image

The issue affects sentry-python 1.9.7
If I downgrade to sentry-python 1.9.5 the I get the expected behavior

Metadata

Metadata

Assignees

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions