From 8cd8f4c72262ca682170fcb2cd3ad0351d3c90f0 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Tue, 2 May 2023 11:44:00 +0200 Subject: [PATCH 1/2] fix(node): Mark stack frames with url protocol as in-app frames --- packages/utils/src/node-stack-trace.ts | 11 ++++++++++- packages/utils/test/stacktrace.test.ts | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/utils/src/node-stack-trace.ts b/packages/utils/src/node-stack-trace.ts index 7797eb327bbe..a71e35d7f847 100644 --- a/packages/utils/src/node-stack-trace.ts +++ b/packages/utils/src/node-stack-trace.ts @@ -85,7 +85,16 @@ export function node(getModule?: GetModuleFn): StackLineParserFn { } const isInternal = - isNative || (filename && !filename.startsWith('/') && !filename.startsWith('.') && !filename.includes(':\\')); + isNative || + (filename && + // It's not internal if it's an absolute linux path + !filename.startsWith('/') && + // It's not internal if it's an absolute windows path + !filename.includes(':\\') && + // It's not internal if the path is starting with a dot + !filename.startsWith('.') && + // It's not internal if the frame has a protocol. In node, this is usually the case if the file got pre-processed with a bundler like webpack + !filename.match(/^[a-zA-Z]([a-zA-Z0-9.-+])*:\/\//)); // Schema from: https://stackoverflow.com/a/3641782 // in_app is all that's not an internal Node function or a module within node_modules // note that isNative appears to return true even for node core libraries diff --git a/packages/utils/test/stacktrace.test.ts b/packages/utils/test/stacktrace.test.ts index 23257e507fb7..295fa282d906 100644 --- a/packages/utils/test/stacktrace.test.ts +++ b/packages/utils/test/stacktrace.test.ts @@ -264,4 +264,10 @@ describe('node', () => { in_app: true, }); }); + + it('should mark frames with protocols as in_app: true', () => { + const line = 'at Object. (app:///_next/server/pages/[error].js:10:20)'; + const result = node(line); + expect(result?.in_app).toBe(true); + }); }); From 35e2fb946416658231d8d9f810b0c310bec7c348 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Tue, 2 May 2023 13:38:48 +0200 Subject: [PATCH 2/2] fix overly permissive regex --- packages/utils/src/node-stack-trace.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/src/node-stack-trace.ts b/packages/utils/src/node-stack-trace.ts index a71e35d7f847..00b02b0fee35 100644 --- a/packages/utils/src/node-stack-trace.ts +++ b/packages/utils/src/node-stack-trace.ts @@ -94,7 +94,7 @@ export function node(getModule?: GetModuleFn): StackLineParserFn { // It's not internal if the path is starting with a dot !filename.startsWith('.') && // It's not internal if the frame has a protocol. In node, this is usually the case if the file got pre-processed with a bundler like webpack - !filename.match(/^[a-zA-Z]([a-zA-Z0-9.-+])*:\/\//)); // Schema from: https://stackoverflow.com/a/3641782 + !filename.match(/^[a-zA-Z]([a-zA-Z0-9.\-+])*:\/\//)); // Schema from: https://stackoverflow.com/a/3641782 // in_app is all that's not an internal Node function or a module within node_modules // note that isNative appears to return true even for node core libraries