MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / handleRequest

Function handleRequest

packages/astro/src/server/middleware.ts:65–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63};
64
65export const handleRequest: (options?: MiddlewareOptions) => MiddlewareResponseHandler = options => {
66 const handlerOptions = {
67 trackClientIp: false,
68 ...options,
69 };
70
71 return async (ctx, next) => {
72 // If no Sentry client exists, just bail
73 // Apart from the case when no Sentry.init() is called at all, this also happens
74 // if a prerendered page is hit first before a ssr page is called
75 // For regular prerendered pages, this is fine as we do not want to instrument them at runtime anyhow
76 // BUT for server-islands requests on a static page, this can be problematic...
77 // TODO: Today, this leads to inconsistent behavior: If a prerendered page is hit first (before _any_ ssr page is called),
78 // Sentry.init() has not been called yet (as this is only injected in SSR pages), so server-island requests are not instrumented
79 // If any SSR route is hit before, the client will already be set up and everything will work as expected :O
80 // To reproduce this: Run the astro-5 "tracing.serverIslands.test" only
81 if (!getClient()) {
82 return next();
83 }
84
85 const isDynamicPageRequest = checkIsDynamicPageRequest(ctx);
86
87 // For static (prerendered) routes, we only want to inject the parametrized route meta tags
88 if (!isDynamicPageRequest) {
89 return handleStaticRoute(ctx, next);
90 }
91
92 const activeSpan = getActiveSpan();
93 const rootSpan = activeSpan ? getRootSpan(activeSpan) : undefined;
94
95 // if there is an active span, we just want to enhance it with routing data etc.
96 if (rootSpan && spanToJSON(rootSpan).op === 'http.server') {
97 return enhanceHttpServerSpan(ctx, next, rootSpan);
98 }
99
100 return instrumentRequestStartHttpServerSpan(ctx, next, handlerOptions);
101 };
102};
103
104async function handleStaticRoute(
105 ctx: Parameters<MiddlewareResponseHandler>[0],

Callers 2

middleware.test.tsFile · 0.90
onRequestFunction · 0.90

Calls 9

spanToJSONFunction · 0.90
nextFunction · 0.85
handleStaticRouteFunction · 0.85
getRootSpanFunction · 0.85
enhanceHttpServerSpanFunction · 0.85
getClientFunction · 0.50
getActiveSpanFunction · 0.50

Tested by

no test coverage detected