GeezerVison is showing github.com — tracesSampler "name" property missing route name with Fastify integration · Issue #12944 · getsentry/sentry-javascript
tracesSampler "name" property missing route name with Fastify integration #12944DescriptionIs there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
8.18
Framework Version
Fastify v4
Link to Sentry event
No response
SDK Setup/Reproduction Example
Sentry.init({
dsn: "https://763f4daed63fb0d58072fa782c353c8d@o4505228622036992.ingest.us.sentry.io/4505903337570304",
debug: false,
integrations: [
nodeProfilingIntegration(),
],
tracesSampler: ({ name, attributes, parentSampled }) => {
// for fastify routes, name is always just the http method e.g. "GET"
}
Steps to Reproduce
See above ^
Expected Result
name should be the full route name e.g. POST /games/:gameId/join
Actual Result
The name returned is just "POST" I can get the url from attributes but this isn't ideal for parameterized routes.
Overall was a smooth experience upgrading from v7/fastify-sentry to native v8, great update otherwise! :) Activitymydea commented on Jul 17, 2024 hello, thanks for writing in!
Sadly, this is a restriction we have right now with these http.server spans 😬 the problem is that these spans are created initially with just this name, and are later updated before we send them. Because of this, you'll have to make the sampling decision based on the attributes that are passed to the sampler, which should contain some more details.
We could improve the name a bit, and I think it would be worthwhile to do that. But if may still not be the name that the span/transaction has at the very end, e.g. it may not be parametrized (e.g. GET /users/12 instead of GET /users/:id or something like this). mydea commented on Jul 17, 2024 I opened a PR here: #12945 to improve this. You can read the PR description, this should make this much better than it is today, although there are still some caveats, but filtering should become way easier at least. MattJustMatt commented on Jul 18, 2024 Thanks for this! Like you said things are easier now, but still a pain for some of the more complex parameterized items. Is there a path to getting the route name itself? Lms24 commented on Jul 18, 2024 @MattJustMatt unfortunately, there is not at span creation time due to a fundamental limitation how OpenTelemetry instrumentation works. Quoting @mydea's PR description from #12945:
This means that we'll never have e.g. the http.route correctly there, because all http.server spans originate from the http instrumentation where they do not have a route yet, and then more specific instrumentation (e.g. express or fastify) add the http.route to that span later
(Side note: Even if we didn't make the switch to Otel in v8, we invested a lot of time in obtaining a paramterized route name as early as possible and failed in a lot of cases. Many frameworks, for example express, were just not designed to support this use case)
But: You can filter out the span or transaction in the beforeSendTransaction hook. At this time, its name will be parameterized. If you filter out the span, it won't be sent to Sentry or deplete your quota. Lms24 commented on Jul 18, 2024 Another side note: The only way to theoretically get this working is to write a route matching algorithm where you give it the unparameterized route name and a set of available routes and you infer the right route name in return.
We actually gave this a thought a while ago (#5510) but decided to abandon it due to usability and performance overhead concerns as well as route matching working slightly differently in different frameworks.
MetadataMetadataStatusShow more project fields
DevelopmentNo branches or pull requestsIssue actions
|