diff --git a/apps/backend/sentry.client.config.ts b/apps/backend/sentry.client.config.ts index f217ada31..412e10872 100644 --- a/apps/backend/sentry.client.config.ts +++ b/apps/backend/sentry.client.config.ts @@ -14,6 +14,8 @@ Sentry.init({ "NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.", ], + normalizeDepth: 5, + // Adjust this value in production, or use tracesSampler for greater control tracesSampleRate: 1, @@ -24,8 +26,6 @@ Sentry.init({ replaysOnErrorSampleRate: 1.0, - // This sets the sample rate to be 10%. You may want this to be 100% while - // in development and sample at a lower rate in production replaysSessionSampleRate: 1.0, // You can remove this option if you're not planning to use the Sentry Session Replay feature: diff --git a/apps/backend/src/instrumentation.ts b/apps/backend/src/instrumentation.ts index e57f8cc62..6d7fa9581 100644 --- a/apps/backend/src/instrumentation.ts +++ b/apps/backend/src/instrumentation.ts @@ -21,6 +21,8 @@ export function register() { "NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.", ], + normalizeDepth: 5, + // Adjust this value in production, or use tracesSampler for greater control tracesSampleRate: 1, diff --git a/apps/backend/src/route-handlers/smart-route-handler.tsx b/apps/backend/src/route-handlers/smart-route-handler.tsx index 45c196a55..a7ac9f60b 100644 --- a/apps/backend/src/route-handlers/smart-route-handler.tsx +++ b/apps/backend/src/route-handlers/smart-route-handler.tsx @@ -1,5 +1,6 @@ import "../polyfills"; +import * as Sentry from "@sentry/nextjs"; import { EndpointDocumentation } from "@stackframe/stack-shared/dist/crud"; import { KnownError, KnownErrors } from "@stackframe/stack-shared/dist/known-errors"; import { yupMixed } from "@stackframe/stack-shared/dist/schema-fields"; @@ -58,6 +59,16 @@ function catchError(error: unknown): StatusError { export function handleApiRequest(handler: (req: NextRequest, options: any, requestId: string) => Promise): (req: NextRequest, options: any) => Promise { return async (req: NextRequest, options: any) => { const requestId = generateSecureRandomString(80); + + // Set Sentry scope to include request details + Sentry.setContext("stack-request", { + requestId: requestId, + method: req.method, + url: req.url, + query: Object.fromEntries(req.nextUrl.searchParams), + headers: Object.fromEntries(req.headers), + }); + let hasRequestFinished = false; try { // censor long query parameters because they might contain sensitive data @@ -208,6 +219,8 @@ export function createSmartRouteHandler< const fullReq = reqsParsed[0][0][1]; const handler = reqsParsed[0][1]; + Sentry.setContext("stack-parsed-smart-request", smartReq as any); + let smartRes = await handler.handler(smartReq as any, fullReq); return await createResponse(nextRequest, requestId, smartRes, handler.response); @@ -216,6 +229,9 @@ export function createSmartRouteHandler< return Object.assign(handleApiRequest(async (req, options, requestId) => { const bodyBuffer = await req.arrayBuffer(); const smartRequest = await createSmartRequest(req, bodyBuffer, options); + + Sentry.setContext("stack-full-smart-request", smartRequest); + return await invoke(req, requestId, smartRequest); }), { [getSmartRouteHandlerSymbol()]: true, diff --git a/apps/dashboard/sentry.client.config.ts b/apps/dashboard/sentry.client.config.ts index 854dac9c7..9a186ea91 100644 --- a/apps/dashboard/sentry.client.config.ts +++ b/apps/dashboard/sentry.client.config.ts @@ -15,6 +15,8 @@ Sentry.init({ "NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.", ], + normalizeDepth: 5, + // Adjust this value in production, or use tracesSampler for greater control tracesSampleRate: 1, @@ -25,8 +27,6 @@ Sentry.init({ replaysOnErrorSampleRate: 1.0, - // This sets the sample rate to be 10%. You may want this to be 100% while - // in development and sample at a lower rate in production replaysSessionSampleRate: 1.0, // You can remove this option if you're not planning to use the Sentry Session Replay feature: diff --git a/apps/dashboard/src/instrumentation.ts b/apps/dashboard/src/instrumentation.ts index dd233a60a..4b120d903 100644 --- a/apps/dashboard/src/instrumentation.ts +++ b/apps/dashboard/src/instrumentation.ts @@ -14,6 +14,8 @@ export function register() { "NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.", ], + normalizeDepth: 5, + // Adjust this value in production, or use tracesSampler for greater control tracesSampleRate: 1,