Skip to content

Commit 3476772

Browse files
authored
fix(tracing): Don't attach resource size if null (#9669)
Resource size can be null in some browsers, so don't set it if it's null (only set integers).
1 parent c29caa8 commit 3476772

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ function setResourceEntrySizeData(
497497
dataKey: 'http.response_transfer_size' | 'http.response_content_length' | 'http.decoded_response_content_length',
498498
): void {
499499
const entryVal = entry[key];
500-
if (entryVal !== undefined && entryVal < MAX_INT_AS_BYTES) {
500+
if (entryVal != null && entryVal < MAX_INT_AS_BYTES) {
501501
data[dataKey] = entryVal;
502502
}
503503
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,26 @@ describe('_addResourceSpans', () => {
189189
}),
190190
);
191191
});
192+
193+
// resource sizes can be set as null on some browsers
194+
// https://github.com/getsentry/sentry/pull/60601
195+
it('does not attach null resource sizes', () => {
196+
const entry = {
197+
initiatorType: 'css',
198+
transferSize: null,
199+
encodedBodySize: null,
200+
decodedBodySize: null,
201+
} as unknown as ResourceEntry;
202+
203+
_addResourceSpans(transaction, entry, '/assets/to/css', 100, 23, 345);
204+
205+
// eslint-disable-next-line @typescript-eslint/unbound-method
206+
expect(transaction.startChild).toHaveBeenCalledTimes(1);
207+
// eslint-disable-next-line @typescript-eslint/unbound-method
208+
expect(transaction.startChild).toHaveBeenLastCalledWith(
209+
expect.objectContaining({
210+
data: {},
211+
}),
212+
);
213+
});
192214
});

0 commit comments

Comments
 (0)