Skip to content

Commit fcd97c4

Browse files
authored
ref(tracing): Remove script evaluation span (#4433)
Tracking the script evaluation span is inconsistent, and often doesn't show up in most pageload transactions. In addition, the value of this span is not clear. To reduce bundle size and complexity, this patch removes the script evaluation span.
1 parent 2252c5c commit fcd97c4

File tree

2 files changed

+4
-41
lines changed

2 files changed

+4
-41
lines changed

packages/tracing/src/browser/metrics.ts

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,7 @@ export class MetricsInstrumentation {
4444
logger.log('[Tracing] Adding & adjusting spans using Performance API');
4545

4646
const timeOrigin = msToSec(browserPerformanceTimeOrigin);
47-
let entryScriptSrc = '';
48-
49-
if (global.document && global.document.scripts) {
50-
// eslint-disable-next-line @typescript-eslint/prefer-for-of
51-
for (let i = 0; i < global.document.scripts.length; i++) {
52-
// We go through all scripts on the page and look for 'data-entry'
53-
// We remember the name and measure the time between this script finished loading and
54-
// our mark 'sentry-tracing-init'
55-
if (global.document.scripts[i].dataset.entry === 'true') {
56-
entryScriptSrc = global.document.scripts[i].src;
57-
break;
58-
}
59-
}
60-
}
6147

62-
let entryScriptStartTimestamp: number | undefined;
63-
let tracingInitMarkStartTime: number | undefined;
6448
let responseStartTimestamp: number | undefined;
6549
let requestStartTimestamp: number | undefined;
6650

@@ -86,10 +70,6 @@ export class MetricsInstrumentation {
8670
case 'paint':
8771
case 'measure': {
8872
const startTimestamp = addMeasureSpans(transaction, entry, startTime, duration, timeOrigin);
89-
if (tracingInitMarkStartTime === undefined && entry.name === 'sentry-tracing-init') {
90-
tracingInitMarkStartTime = startTimestamp;
91-
}
92-
9373
// capture web vitals
9474

9575
const firstHidden = getVisibilityWatcher();
@@ -112,27 +92,14 @@ export class MetricsInstrumentation {
11292
}
11393
case 'resource': {
11494
const resourceName = (entry.name as string).replace(global.location.origin, '');
115-
const endTimestamp = addResourceSpans(transaction, entry, resourceName, startTime, duration, timeOrigin);
116-
// We remember the entry script end time to calculate the difference to the first init mark
117-
if (entryScriptStartTimestamp === undefined && entryScriptSrc.indexOf(resourceName) > -1) {
118-
entryScriptStartTimestamp = endTimestamp;
119-
}
95+
addResourceSpans(transaction, entry, resourceName, startTime, duration, timeOrigin);
12096
break;
12197
}
12298
default:
12399
// Ignore other entry types.
124100
}
125101
});
126102

127-
if (entryScriptStartTimestamp !== undefined && tracingInitMarkStartTime !== undefined) {
128-
_startChild(transaction, {
129-
description: 'evaluation',
130-
endTimestamp: tracingInitMarkStartTime,
131-
op: 'script',
132-
startTimestamp: entryScriptStartTimestamp,
133-
});
134-
}
135-
136103
this._performanceCursor = Math.max(performance.getEntries().length - 1, 0);
137104

138105
this._trackNavigator(transaction);
@@ -335,11 +302,11 @@ export function addResourceSpans(
335302
startTime: number,
336303
duration: number,
337304
timeOrigin: number,
338-
): number | undefined {
305+
): void {
339306
// we already instrument based on fetch and xhr, so we don't need to
340307
// duplicate spans here.
341308
if (entry.initiatorType === 'xmlhttprequest' || entry.initiatorType === 'fetch') {
342-
return undefined;
309+
return;
343310
}
344311

345312
const data: Record<string, any> = {};
@@ -363,8 +330,6 @@ export function addResourceSpans(
363330
startTimestamp,
364331
data,
365332
});
366-
367-
return endTimestamp;
368333
}
369334

370335
/** Create performance navigation related spans */

packages/tracing/test/browser/metrics.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('addResourceSpans', () => {
9494
const startTime = 23;
9595
const duration = 356;
9696

97-
const endTimestamp = addResourceSpans(transaction, entry, '/assets/to/css', startTime, duration, timeOrigin);
97+
addResourceSpans(transaction, entry, '/assets/to/css', startTime, duration, timeOrigin);
9898

9999
// eslint-disable-next-line @typescript-eslint/unbound-method
100100
expect(transaction.startChild).toHaveBeenCalledTimes(1);
@@ -110,8 +110,6 @@ describe('addResourceSpans', () => {
110110
op: 'resource.css',
111111
startTimestamp: timeOrigin + startTime,
112112
});
113-
114-
expect(endTimestamp).toBe(timeOrigin + startTime + duration);
115113
});
116114

117115
it('creates a variety of resource spans', () => {

0 commit comments

Comments
 (0)