forked from open-telemetry/opentelemetry-js-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(instr-document-load): fix test to allow missing network span events
The change in open-telemetry/opentelemetry-js#4486 means that a addSpanNetworkEvent() in v1.24.0 and later might get dropped -- if its time value is before the fetchStart time. Typically this happens if the event time value is 0.
- Loading branch information
Showing
1 changed file
with
30 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -555,43 +555,44 @@ describe('DocumentLoad Instrumentation', () => { | |
assert.strictEqual(rootSpan.attributes['http.user_agent'], userAgent); | ||
|
||
ensureNetworkEventsExists(fsEvents); | ||
assert.strictEqual(fsEvents.length, 8); | ||
|
||
assert.strictEqual(rsEvents[0].name, PTN.FETCH_START); | ||
assert.strictEqual(rsEvents[1].name, PTN.UNLOAD_EVENT_START); | ||
assert.strictEqual(rsEvents[2].name, PTN.UNLOAD_EVENT_END); | ||
assert.strictEqual(rsEvents[3].name, PTN.DOM_INTERACTIVE); | ||
assert.strictEqual( | ||
rsEvents[4].name, | ||
PTN.DOM_CONTENT_LOADED_EVENT_START | ||
); | ||
assert.strictEqual(rsEvents[5].name, PTN.DOM_CONTENT_LOADED_EVENT_END); | ||
assert.strictEqual(rsEvents[6].name, PTN.DOM_COMPLETE); | ||
assert.strictEqual(rsEvents[7].name, PTN.LOAD_EVENT_START); | ||
assert.strictEqual(rsEvents[8].name, PTN.LOAD_EVENT_END); | ||
const rsEventNames = rsEvents.map(e => e.name); | ||
// Allow the unloadEvent{Start,End} events to be missing. Tests that | ||
// are simulating a fallback to window.performance.timing are using | ||
// values (entriesFallback) for that result in those network span | ||
// events being dropped after https://github.com/open-telemetry/opentelemetry-js/pull/4486 | ||
// (@opentelemetry/[email protected]). | ||
const expectedRsEventNames = | ||
rsEventNames[1] === PTN.UNLOAD_EVENT_START | ||
? [ | ||
PTN.FETCH_START, | ||
PTN.UNLOAD_EVENT_START, | ||
PTN.UNLOAD_EVENT_END, | ||
PTN.DOM_INTERACTIVE, | ||
PTN.DOM_CONTENT_LOADED_EVENT_START, | ||
PTN.DOM_CONTENT_LOADED_EVENT_END, | ||
PTN.DOM_COMPLETE, | ||
PTN.LOAD_EVENT_START, | ||
PTN.LOAD_EVENT_END, | ||
] | ||
: [ | ||
PTN.FETCH_START, | ||
PTN.DOM_INTERACTIVE, | ||
PTN.DOM_CONTENT_LOADED_EVENT_START, | ||
PTN.DOM_CONTENT_LOADED_EVENT_END, | ||
PTN.DOM_COMPLETE, | ||
PTN.LOAD_EVENT_START, | ||
PTN.LOAD_EVENT_END, | ||
]; | ||
assert.deepStrictEqual(rsEventNames, expectedRsEventNames); | ||
|
||
assert.strictEqual(fsEvents.length, 8); | ||
assert.strictEqual(rsEvents.length, 9); | ||
assert.strictEqual(exporter.getFinishedSpans().length, 2); | ||
done(); | ||
}); | ||
}); | ||
} | ||
|
||
describe('when navigation entries types are NOT available then fallback to "performance.timing"', () => { | ||
const sandbox = sinon.createSandbox(); | ||
beforeEach(() => { | ||
sandbox.stub(window.performance, 'getEntriesByType').value(undefined); | ||
sandbox.stub(window.performance, 'timing').get(() => { | ||
return entriesFallback; | ||
}); | ||
}); | ||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
shouldExportCorrectSpan(); | ||
}); | ||
|
||
describe('when getEntriesByType is not defined then fallback to "performance.timing"', () => { | ||
const sandbox = sinon.createSandbox(); | ||
beforeEach(() => { | ||
|