1- import type { DynamicSamplingContext , TraceparentData } from '@sentry/types' ;
2- import { baggageHeaderToDynamicSamplingContext , extractTraceparentData } from '@sentry/utils' ;
1+ import type { DynamicSamplingContext , StackFrame , TraceparentData } from '@sentry/types' ;
2+ import { baggageHeaderToDynamicSamplingContext , basename , extractTraceparentData } from '@sentry/utils' ;
33import type { RequestEvent } from '@sveltejs/kit' ;
44
55/**
@@ -17,3 +17,40 @@ export function getTracePropagationData(event: RequestEvent): {
1717
1818 return { traceparentData, dynamicSamplingContext } ;
1919}
20+
21+ /**
22+ * A custom iteratee function for the `RewriteFrames` integration.
23+ *
24+ * Does the same as the default iteratee, but also removes the `module` property from the
25+ * frame to improve issue grouping.
26+ *
27+ * For some reason, our stack trace processing pipeline isn't able to resolve the bundled
28+ * module name to the original file name correctly, leading to individual error groups for
29+ * each module. Removing the `module` field makes the grouping algorithm fall back to the
30+ * `filename` field, which is correctly resolved and hence grouping works as expected.
31+ */
32+ export function rewriteFramesIteratee ( frame : StackFrame ) : StackFrame {
33+ if ( ! frame . filename ) {
34+ return frame ;
35+ }
36+
37+ const prefix = 'app:///' ;
38+
39+ // Check if the frame filename begins with `/` or a Windows-style prefix such as `C:\`
40+ const isWindowsFrame = / ^ [ a - z A - Z ] : \\ / . test ( frame . filename ) ;
41+ const startsWithSlash = / ^ \/ / . test ( frame . filename ) ;
42+ if ( isWindowsFrame || startsWithSlash ) {
43+ const filename = isWindowsFrame
44+ ? frame . filename
45+ . replace ( / ^ [ a - z A - Z ] : / , '' ) // remove Windows-style prefix
46+ . replace ( / \\ / g, '/' ) // replace all `\\` instances with `/`
47+ : frame . filename ;
48+
49+ const base = basename ( filename ) ;
50+ frame . filename = `${ prefix } ${ base } ` ;
51+ }
52+
53+ delete frame . module ;
54+
55+ return frame ;
56+ }
0 commit comments