From 2ac8cb8542ab49d8219304756b30ed2e57e482dd Mon Sep 17 00:00:00 2001 From: Konstantin Wohlwend Date: Sun, 2 Mar 2025 16:34:14 -0800 Subject: [PATCH] Add stack.process-id to OpenTelemetry attributes --- apps/backend/src/route-handlers/smart-route-handler.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/backend/src/route-handlers/smart-route-handler.tsx b/apps/backend/src/route-handlers/smart-route-handler.tsx index 117755f37..33f10ed41 100644 --- a/apps/backend/src/route-handlers/smart-route-handler.tsx +++ b/apps/backend/src/route-handlers/smart-route-handler.tsx @@ -52,6 +52,12 @@ function catchError(error: unknown, requestId: string): StatusError { return new InternalServerError(error, requestId); } +/** + * A unique identifier for the current process. This is used to correlate logs in serverless environments that allow + * multiple concurrent requests to be handled by the same instance. + */ +const processId = generateSecureRandomString(80); + /** * Catches any errors thrown in the handler and returns a 500 response with the thrown error message. Also logs the * request details. @@ -65,6 +71,7 @@ export function handleApiRequest(handler: (req: NextRequest, options: any, reque "stack.request.request-id": requestId, "stack.request.method": req.method, "stack.request.url": req.url, + "stack.process-id": processId, }, }, async (span) => { // Set Sentry scope to include request details