Skip to content

Commit 28d0fef

Browse files
committed
refactor
1 parent 999dd9f commit 28d0fef

File tree

1 file changed

+11
-11
lines changed
  • packages/tracing-internal/src/browser/metrics

1 file changed

+11
-11
lines changed

packages/tracing-internal/src/browser/metrics/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,7 @@ export function addPerformanceEntries(transaction: Transaction): void {
225225
break;
226226
}
227227
case 'resource': {
228-
const resourceName = (entry.name as string).replace(WINDOW.location.origin, '');
229-
const resourceUrl = parseUrl(entry.name as string);
230-
_addResourceSpans(transaction, entry, resourceName, resourceUrl, startTime, duration, timeOrigin);
228+
_addResourceSpans(transaction, entry, entry.name as string, startTime, duration, timeOrigin);
231229
break;
232230
}
233231
default:
@@ -402,8 +400,7 @@ export interface ResourceEntry extends Record<string, unknown> {
402400
export function _addResourceSpans(
403401
transaction: Transaction,
404402
entry: ResourceEntry,
405-
resourceName: string,
406-
resourceUrl: ReturnType<typeof parseUrl>,
403+
resourceUrl: string,
407404
startTime: number,
408405
duration: number,
409406
timeOrigin: number,
@@ -414,29 +411,32 @@ export function _addResourceSpans(
414411
return;
415412
}
416413

414+
const parsedUrl = parseUrl(resourceUrl);
415+
417416
// eslint-disable-next-line @typescript-eslint/no-explicit-any
418417
const data: Record<string, any> = {};
419418
setResourceEntrySizeData(data, entry, 'transferSize', 'http.response_transfer_size');
420419
setResourceEntrySizeData(data, entry, 'encodedBodySize', 'http.response_content_length');
421420
setResourceEntrySizeData(data, entry, 'decodedBodySize', 'http.decoded_response_content_length');
421+
422422
if ('renderBlockingStatus' in entry) {
423423
data['resource.render_blocking_status'] = entry.renderBlockingStatus;
424424
}
425-
if (resourceUrl.protocol) {
426-
data['url.scheme'] = resourceUrl.protocol;
425+
if (parsedUrl.protocol) {
426+
data['url.scheme'] = parsedUrl.protocol;
427427
}
428428

429-
if (resourceUrl.host) {
430-
data['server.address'] = resourceUrl.host;
429+
if (parsedUrl.host) {
430+
data['server.address'] = parsedUrl.host;
431431
}
432432

433-
data['url.same_origin'] = resourceUrl.host === WINDOW.location.host;
433+
data['url.same_origin'] = resourceUrl.includes(WINDOW.location.origin);
434434

435435
const startTimestamp = timeOrigin + startTime;
436436
const endTimestamp = startTimestamp + duration;
437437

438438
_startChild(transaction, {
439-
description: resourceName,
439+
description: resourceUrl.replace(WINDOW.location.origin, ''),
440440
endTimestamp,
441441
op: entry.initiatorType ? `resource.${entry.initiatorType}` : 'resource.other',
442442
origin: 'auto.resource.browser.metrics',

0 commit comments

Comments
 (0)