Skip to content

Commit ad9ec93

Browse files
committed
More de-duplication
1 parent 100c173 commit ad9ec93

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

packages/browser/src/profiling/utils.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { DebugImage, Envelope, Event, EventEnvelope, Profile, Span, ThreadC
55
import {
66
browserPerformanceTimeOrigin,
77
forEachEnvelopeItem,
8-
getFilenameToDebugIdMap,
8+
getDebugImagesForResources,
99
logger,
1010
timestampInSeconds,
1111
uuid4,
@@ -354,21 +354,7 @@ export function applyDebugMetadata(resource_paths: ReadonlyArray<string>): Debug
354354
return [];
355355
}
356356

357-
// Build a map of filename -> debug_id
358-
const filenameDebugIdMap = getFilenameToDebugIdMap(stackParser);
359-
360-
const images: DebugImage[] = [];
361-
for (const path of resource_paths) {
362-
if (path && filenameDebugIdMap[path]) {
363-
images.push({
364-
type: 'sourcemap',
365-
code_file: path,
366-
debug_id: filenameDebugIdMap[path] as string,
367-
});
368-
}
369-
}
370-
371-
return images;
357+
return getDebugImagesForResources(stackParser, resource_paths);
372358
}
373359

374360
/**

packages/profiling-node/src/utils.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
createEnvelope,
2121
dsnToString,
2222
forEachEnvelopeItem,
23-
getFilenameToDebugIdMap,
23+
getDebugImagesForResources,
2424
logger,
2525
uuid4,
2626
} from '@sentry/utils';
@@ -432,20 +432,5 @@ export function applyDebugMetadata(client: Client, resource_paths: ReadonlyArray
432432
return [];
433433
}
434434

435-
// Build a map of filename -> debug_id.
436-
const filenameDebugIdMap = getFilenameToDebugIdMap(options.stackParser);
437-
438-
const images: DebugImage[] = [];
439-
440-
for (const resource of resource_paths) {
441-
if (resource && filenameDebugIdMap[resource]) {
442-
images.push({
443-
type: 'sourcemap',
444-
code_file: resource,
445-
debug_id: filenameDebugIdMap[resource] as string,
446-
});
447-
}
448-
}
449-
450-
return images;
435+
return getDebugImagesForResources(options.stackParser, resource_paths);
451436
}

packages/utils/src/debug-ids.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { StackFrame, StackParser } from '@sentry/types';
1+
import type { DebugImage, StackFrame, StackParser } from '@sentry/types';
22
import { GLOBAL_OBJ } from './worldwide';
33

44
const debugIdStackParserCache = new WeakMap<StackParser, Map<string, StackFrame[]>>();
@@ -45,3 +45,26 @@ export function getFilenameToDebugIdMap(stackParser: StackParser): Record<string
4545
return acc;
4646
}, {});
4747
}
48+
49+
/**
50+
* Returns a list of debug images for the given resources.
51+
*/
52+
export function getDebugImagesForResources(
53+
stackParser: StackParser,
54+
resource_paths: ReadonlyArray<string>,
55+
): DebugImage[] {
56+
const filenameDebugIdMap = getFilenameToDebugIdMap(stackParser);
57+
58+
const images: DebugImage[] = [];
59+
for (const path of resource_paths) {
60+
if (path && filenameDebugIdMap[path]) {
61+
images.push({
62+
type: 'sourcemap',
63+
code_file: path,
64+
debug_id: filenameDebugIdMap[path] as string,
65+
});
66+
}
67+
}
68+
69+
return images;
70+
}

0 commit comments

Comments
 (0)