Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow zero/negative performance timings #1769

Merged
merged 7 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export enum PerformanceTimingNames {
FETCH_START = 'fetchStart',
LOAD_EVENT_END = 'loadEventEnd',
LOAD_EVENT_START = 'loadEventStart',
NAVIGATION_START = 'navigationStart',
REDIRECT_END = 'redirectEnd',
REDIRECT_START = 'redirectStart',
REQUEST_START = 'requestStart',
Expand Down
5 changes: 0 additions & 5 deletions packages/opentelemetry-web/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ export function addSpanNetworkEvent(
hasKey(entries, performanceName) &&
typeof entries[performanceName] === 'number'
) {
// some metrics are available but have value 0 which means they are invalid
// for example "secureConnectionStart" is 0 which makes the events to be wrongly interpreted
if (entries[performanceName] === 0) {
return undefined;
}
span.addEvent(performanceName, entries[performanceName]);
return span;
}
Expand Down
52 changes: 29 additions & 23 deletions packages/opentelemetry-web/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,40 +164,46 @@ describe('utils', () => {
});
});
describe('addSpanNetworkEvent', () => {
describe('when entries contain the performance', () => {
it('should add event to span', () => {
const addEventSpy = sinon.spy();
const span = ({
addEvent: addEventSpy,
} as unknown) as tracing.Span;
const entries = {
[PTN.FETCH_START]: 123,
} as PerformanceEntries;

assert.strictEqual(addEventSpy.callCount, 0);

addSpanNetworkEvent(span, PTN.FETCH_START, entries);

assert.strictEqual(addEventSpy.callCount, 1);
const args = addEventSpy.args[0];

assert.strictEqual(args[0], 'fetchStart');
assert.strictEqual(args[1], 123);
[0, -2, 123].forEach(value => {
describe(`when entry is ${value}`, () => {
it('should add event to span', () => {
const addEventSpy = sinon.spy();
const span = ({
addEvent: addEventSpy,
} as unknown) as tracing.Span;
const entries = {
[PTN.FETCH_START]: value,
} as PerformanceEntries;

assert.strictEqual(addEventSpy.callCount, 0);

addSpanNetworkEvent(span, PTN.FETCH_START, entries);

assert.strictEqual(addEventSpy.callCount, 1);
const args = addEventSpy.args[0];

assert.strictEqual(args[0], 'fetchStart');
assert.strictEqual(args[1], value);
});
});
});
describe('when entry has time equal to 0', () => {
describe('when entry is not numeric', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should still have unit test when time is 0 - this is basically what you are fixing in this PR right ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call; I updated the positive test to check 0, a negative number, and a positive number.

it('should NOT add event to span', () => {
const addEventSpy = sinon.spy();
const span = ({
addEvent: addEventSpy,
} as unknown) as tracing.Span;
const entries = {
[PTN.FETCH_START]: 0,
} as PerformanceEntries;
[PTN.FETCH_START]: 'non-numeric',
} as unknown;

assert.strictEqual(addEventSpy.callCount, 0);

addSpanNetworkEvent(span, PTN.FETCH_START, entries);
addSpanNetworkEvent(
span,
PTN.FETCH_START,
entries as PerformanceEntries
);

assert.strictEqual(addEventSpy.callCount, 0);
});
Expand Down