Skip to content

Commit a68731c

Browse files
committed
fix: Account for case where they are 0
1 parent 02dc78d commit a68731c

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

packages/tracing/src/browser/metrics.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,13 @@ export function addResourceSpans(
233233
}
234234

235235
const data: Record<string, any> = {};
236-
if (entry.transferSize) {
236+
if ('transferSize' in entry) {
237237
data.transferSize = entry.transferSize;
238238
}
239-
if (entry.encodedBodySize) {
239+
if ('encodedBodySize' in entry) {
240240
data.encodedBodySize = entry.encodedBodySize;
241241
}
242-
if (entry.decodedBodySize) {
242+
if ('decodedBodySize' in entry) {
243243
data.decodedBodySize = entry.decodedBodySize;
244244
}
245245

@@ -249,7 +249,7 @@ export function addResourceSpans(
249249
_startChild(transaction, {
250250
description: resourceName,
251251
endTimestamp,
252-
op: entry.initiatorType && entry.initiatorType !== '' ? `resource.${entry.initiatorType}` : 'resource',
252+
op: entry.initiatorType ? `resource.${entry.initiatorType}` : 'resource',
253253
startTimestamp,
254254
data,
255255
});

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,28 @@ describe('addResourceSpans', () => {
142142
);
143143
}
144144
});
145+
146+
it('allows for enter size of 0', () => {
147+
const entry: ResourceEntry = {
148+
initiatorType: 'css',
149+
transferSize: 0,
150+
encodedBodySize: 0,
151+
decodedBodySize: 0,
152+
};
153+
154+
addResourceSpans(transaction, entry, '/assets/to/css', 100, 23, 345);
155+
156+
// eslint-disable-next-line @typescript-eslint/unbound-method
157+
expect(transaction.startChild).toHaveBeenCalledTimes(1);
158+
// eslint-disable-next-line @typescript-eslint/unbound-method
159+
expect(transaction.startChild).toHaveBeenLastCalledWith(
160+
expect.objectContaining({
161+
data: {
162+
decodedBodySize: entry.decodedBodySize,
163+
encodedBodySize: entry.encodedBodySize,
164+
transferSize: entry.transferSize,
165+
},
166+
}),
167+
);
168+
});
145169
});

0 commit comments

Comments
 (0)