Skip to content

Transaction name comes out wrong in Starlette integration #4350

Open
@gthb

Description

@gthb

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.27.0

Steps to Reproduce

  1. In my existing app (using Starlette 0.41.3) I enabled Sentry tracing by passing a traces_sampler function in the init call (see below)
  2. I passed starlette.StarletteIntegration(transaction_style="endpoint") in the integrations list to work around the problem that with the default "url" style, all transactions were showing up with the name <unlabeled transaction> instead of a Starlette route binding like GET /status like I was hoping. So instead I get grid.routes.status.StatusEndpoint.get which is the name of the get method in our routing class, and I can live with that ...
  3. ... but then I made the traces_sampler function filter out that name (see function below) because it's just a Kubernetes health check endpoint ... but that didn't work, I still got status transactions ... so to troubleshot that I logged sampling_context["transaction_context"]["name"] and that turns out to be the raw URL, http://123.45.6.78:5001/status
def traces_sampler(sampling_context: SamplingContext):
    if sampling_context["parent_sampled"] is not None:
        return sampling_context["parent_sampled"]

    if sampling_context["transaction_context"]["name"] == "grid.routes.status.StatusEndpoint.get":
        return 0

    return traces_sample_rate

sentry_sdk.init(
    dsn=self._config.sentry_dsn,
    integrations=[starlette.StarletteIntegration(transaction_style="endpoint"), sentry_logging],
    release=self._config.app_version,
    environment=self._config.release_stage,
    before_send=self._before_send,
    transport=custom_transport,
    traces_sampler=traces_sampler,
)

Expected Result

  1. with the default transaction_style="url" I expected to get transactions named after the route paths automatically by the Starlette integration
  2. once I switched to transaction_style="endpoint" and saw distinct transaction names appear in Sentry, I expected to be able to filter by those transaction names in the transaction context passed to the traces_sampler function

Actual Result

  1. with the default transaction_style="url", the actual transaction names appearing in traces in Sentry are all <unlabeled transaction>
  2. after I switched to transaction_style="endpoint", the actual transaction context passed to the traces_sampler function contains "name" which is the full URL (including the pod IP address in my Kubernetes cluster so it's going to vary in ways that are not useful to make transaction names vary by)

Metadata

Metadata

Type

No type

Projects

Status

Waiting for: Community

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions