(stackParser: StackParser)
| 27 | * Supports both proprietary _sentryDebugIds and native _debugIds (e.g., from Vercel) formats. |
| 28 | */ |
| 29 | export function getFilenameToDebugIdMap(stackParser: StackParser): Record<string, string> { |
| 30 | const sentryDebugIdMap = GLOBAL_OBJ._sentryDebugIds; |
| 31 | const nativeDebugIdMap = GLOBAL_OBJ._debugIds; |
| 32 | |
| 33 | if (!sentryDebugIdMap && !nativeDebugIdMap) { |
| 34 | return {}; |
| 35 | } |
| 36 | |
| 37 | const sentryDebugIdKeys = sentryDebugIdMap ? Object.keys(sentryDebugIdMap) : []; |
| 38 | const nativeDebugIdKeys = nativeDebugIdMap ? Object.keys(nativeDebugIdMap) : []; |
| 39 | |
| 40 | // If the count of registered globals hasn't changed since the last call, we |
| 41 | // can just return the cached result. |
| 42 | if ( |
| 43 | cachedFilenameDebugIds && |
| 44 | sentryDebugIdKeys.length === lastSentryKeysCount && |
| 45 | nativeDebugIdKeys.length === lastNativeKeysCount |
| 46 | ) { |
| 47 | return cachedFilenameDebugIds; |
| 48 | } |
| 49 | |
| 50 | lastSentryKeysCount = sentryDebugIdKeys.length; |
| 51 | lastNativeKeysCount = nativeDebugIdKeys.length; |
| 52 | |
| 53 | // Build a map of filename -> debug_id from both sources |
| 54 | cachedFilenameDebugIds = {}; |
| 55 | |
| 56 | if (!parsedStackResults) { |
| 57 | parsedStackResults = {}; |
| 58 | } |
| 59 | |
| 60 | const processDebugIds = (debugIdKeys: string[], debugIdMap: Record<string, string>): void => { |
| 61 | for (const key of debugIdKeys) { |
| 62 | const debugId = debugIdMap[key]; |
| 63 | const result = parsedStackResults?.[key]; |
| 64 | |
| 65 | if (result && cachedFilenameDebugIds && debugId) { |
| 66 | // Use cached filename but update with current debug ID |
| 67 | cachedFilenameDebugIds[result[0]] = debugId; |
| 68 | // Update cached result with new debug ID |
| 69 | if (parsedStackResults) { |
| 70 | parsedStackResults[key] = [result[0], debugId]; |
| 71 | } |
| 72 | } else if (debugId) { |
| 73 | const parsedStack = stackParser(key); |
| 74 | |
| 75 | for (let i = parsedStack.length - 1; i >= 0; i--) { |
| 76 | const stackFrame = parsedStack[i]; |
| 77 | const filename = stackFrame?.filename; |
| 78 | |
| 79 | if (filename && cachedFilenameDebugIds && parsedStackResults) { |
| 80 | cachedFilenameDebugIds[filename] = debugId; |
| 81 | parsedStackResults[key] = [filename, debugId]; |
| 82 | break; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | } |
no test coverage detected