Skip to content

Commit

Permalink
fix(tracing): Don't attach resource size if null (#9669)
Browse files Browse the repository at this point in the history
Resource size can be null in some browsers, so don't set it if it's null
(only set integers).
  • Loading branch information
AbhiPrasad committed Nov 28, 2023
1 parent c29caa8 commit 3476772
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/tracing-internal/src/browser/metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ function setResourceEntrySizeData(
dataKey: 'http.response_transfer_size' | 'http.response_content_length' | 'http.decoded_response_content_length',
): void {
const entryVal = entry[key];
if (entryVal !== undefined && entryVal < MAX_INT_AS_BYTES) {
if (entryVal != null && entryVal < MAX_INT_AS_BYTES) {
data[dataKey] = entryVal;
}
}
22 changes: 22 additions & 0 deletions packages/tracing-internal/test/browser/metrics/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,26 @@ describe('_addResourceSpans', () => {
}),
);
});

// resource sizes can be set as null on some browsers
// https://github.com/getsentry/sentry/pull/60601
it('does not attach null resource sizes', () => {
const entry = {
initiatorType: 'css',
transferSize: null,
encodedBodySize: null,
decodedBodySize: null,
} as unknown as ResourceEntry;

_addResourceSpans(transaction, entry, '/assets/to/css', 100, 23, 345);

// eslint-disable-next-line @typescript-eslint/unbound-method
expect(transaction.startChild).toHaveBeenCalledTimes(1);
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(transaction.startChild).toHaveBeenLastCalledWith(
expect.objectContaining({
data: {},
}),
);
});
});

0 comments on commit 3476772

Please sign in to comment.