diff --git a/packages/astro/src/server/middleware.ts b/packages/astro/src/server/middleware.ts index ec0dbb11d09a..adfac32843f8 100644 --- a/packages/astro/src/server/middleware.ts +++ b/packages/astro/src/server/middleware.ts @@ -66,8 +66,8 @@ export const handleRequest: (options?: MiddlewareOptions) => MiddlewareResponseH if (getActiveSpan()) { return instrumentRequest(ctx, next, handlerOptions); } - return withIsolationScope(() => { - return instrumentRequest(ctx, next, handlerOptions); + return withIsolationScope(isolationScope => { + return instrumentRequest(ctx, next, handlerOptions, isolationScope); }); }; }; @@ -76,6 +76,7 @@ async function instrumentRequest( ctx: Parameters[0], next: Parameters[1], options: MiddlewareOptions, + isolationScope?: Scope, ): Promise { // Make sure we don't accidentally double wrap (e.g. user added middleware and integration auto added it) const locals = ctx.locals as AstroLocalsWithSentry; @@ -121,6 +122,8 @@ async function instrumentRequest( attributes['http.fragment'] = ctx.url.hash; } + isolationScope?.setTransactionName(`${method} ${interpolatedRoute || ctx.url.pathname}`); + const res = await startSpan( { attributes,