Skip to content

Commit ee014c9

Browse files
johnbleydyladan
andauthored
Allow zero/negative performance timings (#1769)
Co-authored-by: Daniel Dyla <[email protected]>
1 parent 6b1285c commit ee014c9

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

packages/opentelemetry-web/src/enums/PerformanceTimingNames.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export enum PerformanceTimingNames {
2727
FETCH_START = 'fetchStart',
2828
LOAD_EVENT_END = 'loadEventEnd',
2929
LOAD_EVENT_START = 'loadEventStart',
30+
NAVIGATION_START = 'navigationStart',
3031
REDIRECT_END = 'redirectEnd',
3132
REDIRECT_START = 'redirectStart',
3233
REQUEST_START = 'requestStart',

packages/opentelemetry-web/src/utils.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ export function addSpanNetworkEvent(
5656
hasKey(entries, performanceName) &&
5757
typeof entries[performanceName] === 'number'
5858
) {
59-
// some metrics are available but have value 0 which means they are invalid
60-
// for example "secureConnectionStart" is 0 which makes the events to be wrongly interpreted
61-
if (entries[performanceName] === 0) {
62-
return undefined;
63-
}
6459
span.addEvent(performanceName, entries[performanceName]);
6560
return span;
6661
}

packages/opentelemetry-web/test/utils.test.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,40 +164,46 @@ describe('utils', () => {
164164
});
165165
});
166166
describe('addSpanNetworkEvent', () => {
167-
describe('when entries contain the performance', () => {
168-
it('should add event to span', () => {
169-
const addEventSpy = sinon.spy();
170-
const span = ({
171-
addEvent: addEventSpy,
172-
} as unknown) as tracing.Span;
173-
const entries = {
174-
[PTN.FETCH_START]: 123,
175-
} as PerformanceEntries;
176-
177-
assert.strictEqual(addEventSpy.callCount, 0);
178-
179-
addSpanNetworkEvent(span, PTN.FETCH_START, entries);
180-
181-
assert.strictEqual(addEventSpy.callCount, 1);
182-
const args = addEventSpy.args[0];
183-
184-
assert.strictEqual(args[0], 'fetchStart');
185-
assert.strictEqual(args[1], 123);
167+
[0, -2, 123].forEach(value => {
168+
describe(`when entry is ${value}`, () => {
169+
it('should add event to span', () => {
170+
const addEventSpy = sinon.spy();
171+
const span = ({
172+
addEvent: addEventSpy,
173+
} as unknown) as tracing.Span;
174+
const entries = {
175+
[PTN.FETCH_START]: value,
176+
} as PerformanceEntries;
177+
178+
assert.strictEqual(addEventSpy.callCount, 0);
179+
180+
addSpanNetworkEvent(span, PTN.FETCH_START, entries);
181+
182+
assert.strictEqual(addEventSpy.callCount, 1);
183+
const args = addEventSpy.args[0];
184+
185+
assert.strictEqual(args[0], 'fetchStart');
186+
assert.strictEqual(args[1], value);
187+
});
186188
});
187189
});
188-
describe('when entry has time equal to 0', () => {
190+
describe('when entry is not numeric', () => {
189191
it('should NOT add event to span', () => {
190192
const addEventSpy = sinon.spy();
191193
const span = ({
192194
addEvent: addEventSpy,
193195
} as unknown) as tracing.Span;
194196
const entries = {
195-
[PTN.FETCH_START]: 0,
196-
} as PerformanceEntries;
197+
[PTN.FETCH_START]: 'non-numeric',
198+
} as unknown;
197199

198200
assert.strictEqual(addEventSpy.callCount, 0);
199201

200-
addSpanNetworkEvent(span, PTN.FETCH_START, entries);
202+
addSpanNetworkEvent(
203+
span,
204+
PTN.FETCH_START,
205+
entries as PerformanceEntries
206+
);
201207

202208
assert.strictEqual(addEventSpy.callCount, 0);
203209
});

0 commit comments

Comments
 (0)