-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(fastify): Update scope transactionName
when handling request
#11447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -56,6 +56,23 @@ test('Sends an API route transaction', async ({ baseURL }) => { | |||
expect(transactionEvent).toEqual( | |||
expect.objectContaining({ | |||
spans: [ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The additional span here is a consequence of us adding another handler. I think this is fine unless someone has concerns.
size-limit report 📦
|
0f8abff
to
2d7ee55
Compare
const routeName = reqWithRouteInfo.routeOptions?.url || reqWithRouteInfo.routerPath; | ||
const method = reqWithRouteInfo.routeOptions?.method || 'GET'; | ||
|
||
getIsolationScope().setTransactionName(`${method} ${routeName}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am honestly wondering if we are grabbing the right isolation scope inside these hooks. Gut feeling wise it could I'd say no 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should verify this for sure - there may be a race condition if this hook is executed before the http.server span is created, that is correct 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this locally and the isolation scope already seems to be the forked one (i.e. not the default isolation scope). Added a check with a debug log nevertheless to ensure we don't pollute the default isolation scope.
…etsentry#11447) This PR updates the isolation scope's `transactionName` by adding another hook callback in our `setupFastifyErrorHandler` fastify plugin. This is better than accessing the otel span for two reasons: 1. We can always update the transactionName, not just when a span is sampled and recording 2. The `onRequest` hook is executed earlier in the lifecycle than the `preHandler` hook that Otel uses to trigger the `requestHook` callback.
This PR updates the isolation scope's
transactionName
whenever therequestHook
Otel instrumentation hook is invoked and we have a recording span (non-recording spans don't have a attributes :( )Update: Changed the transactionName updating mechanism to adding another hook callback in our
setupFastifyErrorHandler
fastify plugin. This is better than accessing the otel span for two reasons:onRequest
hook is executed earlier in the lifecycle than thepreHandler
hook that Otel uses to trigger therequestHook
callback.Also, we now access the same fields to read the route name as Otel.
adjusted existing e2e slightly to cover a paramterized route and to account for the additional span caused by our new
onRequest
handler.ref #10846