Title: Transaction name comes out wrong in Starlette integration · Issue #4350 · getsentry/sentry-python · GitHub
Open Graph Title: Transaction name comes out wrong in Starlette integration · Issue #4350 · getsentry/sentry-python
X Title: Transaction name comes out wrong in Starlette integration · Issue #4350 · getsentry/sentry-python
Description: How do you use Sentry? Sentry Saas (sentry.io) Version 2.27.0 Steps to Reproduce 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) I passed starlette.St...
Open Graph Description: How do you use Sentry? Sentry Saas (sentry.io) Version 2.27.0 Steps to Reproduce In my existing app (using Starlette 0.41.3) I enabled Sentry tracing by passing a traces_sampler function in the ini...
X Description: How do you use Sentry? Sentry Saas (sentry.io) Version 2.27.0 Steps to Reproduce In my existing app (using Starlette 0.41.3) I enabled Sentry tracing by passing a traces_sampler function in the ini...
Opengraph URL: https://github.com/getsentry/sentry-python/issues/4350
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Transaction name comes out wrong in Starlette integration","articleBody":"### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Version\n\n2.27.0\n\n### Steps to Reproduce\n\n1. 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)\n3. 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 `\u003cunlabeled 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 ...\n4. ... 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`\n```python\ndef traces_sampler(sampling_context: SamplingContext):\n if sampling_context[\"parent_sampled\"] is not None:\n return sampling_context[\"parent_sampled\"]\n\n if sampling_context[\"transaction_context\"][\"name\"] == \"grid.routes.status.StatusEndpoint.get\":\n return 0\n\n return traces_sample_rate\n\nsentry_sdk.init(\n dsn=self._config.sentry_dsn,\n integrations=[starlette.StarletteIntegration(transaction_style=\"endpoint\"), sentry_logging],\n release=self._config.app_version,\n environment=self._config.release_stage,\n before_send=self._before_send,\n transport=custom_transport,\n traces_sampler=traces_sampler,\n)\n```\n\n### Expected Result\n\n1. with the default `transaction_style=\"url\"` I expected to get transactions named after the route paths automatically by the Starlette integration\n2. 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\n\n### Actual Result\n\n1. with the default `transaction_style=\"url\"`, the actual transaction names appearing in traces in Sentry are all `\u003cunlabeled transaction>`\n2. 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)","author":{"url":"https://github.com/gthb","@type":"Person","name":"gthb"},"datePublished":"2025-04-29T12:29:59Z","url":"https://github.com/getsentry/sentry-python/issues/4350"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:eff94c19-c005-9de9-d5ba-2e4a7e7550c0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CBA8:2131F3:38CFBF:4BFBCF:6B008A79 |
| html-safe-nonce | 720632e8750537b8a572db80a259a1d9b6be7e3695fc2e4ea31c88c39afa2c09 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQkE4OjIxMzFGMzozOENGQkY6NEJGQkNGOjZCMDA4QTc5IiwidmlzaXRvcl9pZCI6Ijc1MDI2NDQ5MDEwNTAzNTQyOTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 21869bbc4355c622d5370026a80d07fd3c876dd06885155db22f48e9a2a8f69c |
| hovercard-subject-tag | issue:3028146937 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-python/4350/issue_layout |
| twitter:image | https://opengraph.githubassets.com/89288e29c7071215a773f2c9b3881f2da326f9e803d11c16849f19a1c71d6961/getsentry/sentry-python/issues/4350 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/89288e29c7071215a773f2c9b3881f2da326f9e803d11c16849f19a1c71d6961/getsentry/sentry-python/issues/4350 |
| og:image:alt | How do you use Sentry? Sentry Saas (sentry.io) Version 2.27.0 Steps to Reproduce In my existing app (using Starlette 0.41.3) I enabled Sentry tracing by passing a traces_sampler function in the ini... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gthb |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4d3d8e50f02c1d7bf86d5acfa1d3bfe9366abd6528a6b429eb07a168429d2b61 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-python git https://github.com/getsentry/sentry-python.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 137814779 |
| octolytics-dimension-repository_nwo | getsentry/sentry-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 137814779 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | db758f8e02b8257935fb03edf81a3e76eb3abd11 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width