Skip to content

Commit 49a5d6e

Browse files
committed
fix: Account for case where they are 0
1 parent 1dffa3e commit 49a5d6e

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

.eslintrc.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/tracing/src/browser/metrics.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ export function addResourceSpans(
235235
}
236236

237237
const data: Record<string, any> = {};
238-
if (entry.transferSize) {
238+
if ('transferSize' in entry) {
239239
data.transferSize = entry.transferSize;
240240
}
241-
if (entry.encodedBodySize) {
241+
if ('encodedBodySize' in entry) {
242242
data.encodedBodySize = entry.encodedBodySize;
243243
}
244-
if (entry.decodedBodySize) {
244+
if ('decodedBodySize' in entry) {
245245
data.decodedBodySize = entry.decodedBodySize;
246246
}
247247

@@ -251,7 +251,7 @@ export function addResourceSpans(
251251
_startChild(transaction, {
252252
description: resourceName,
253253
endTimestamp,
254-
op: entry.initiatorType && entry.initiatorType !== '' ? `resource.${entry.initiatorType}` : 'resource',
254+
op: entry.initiatorType ? `resource.${entry.initiatorType}` : 'resource',
255255
startTimestamp,
256256
data,
257257
});

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)