feat(fastify): Update scope transactionName when handling request#11447
feat(fastify): Update scope transactionName when handling request#11447
transactionName when handling request#11447Conversation
| expect(transactionEvent).toEqual( | ||
| expect.objectContaining({ | ||
| spans: [ | ||
| { |
There was a problem hiding this comment.
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.
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.
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.
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
transactionNamewhenever therequestHookOtel 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
setupFastifyErrorHandlerfastify plugin. This is better than accessing the otel span for two reasons:onRequesthook is executed earlier in the lifecycle than thepreHandlerhook that Otel uses to trigger therequestHookcallback.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
onRequesthandler.ref #10846