Skip to content

Commit 46b6775

Browse files
authored
test(instr-document-load): fix test to allow missing network span events (#2145)
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.
1 parent 931318c commit 46b6775

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

plugins/web/opentelemetry-instrumentation-document-load/test/documentLoad.test.ts

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -555,43 +555,44 @@ describe('DocumentLoad Instrumentation', () => {
555555
assert.strictEqual(rootSpan.attributes['http.user_agent'], userAgent);
556556

557557
ensureNetworkEventsExists(fsEvents);
558+
assert.strictEqual(fsEvents.length, 8);
558559

559-
assert.strictEqual(rsEvents[0].name, PTN.FETCH_START);
560-
assert.strictEqual(rsEvents[1].name, PTN.UNLOAD_EVENT_START);
561-
assert.strictEqual(rsEvents[2].name, PTN.UNLOAD_EVENT_END);
562-
assert.strictEqual(rsEvents[3].name, PTN.DOM_INTERACTIVE);
563-
assert.strictEqual(
564-
rsEvents[4].name,
565-
PTN.DOM_CONTENT_LOADED_EVENT_START
566-
);
567-
assert.strictEqual(rsEvents[5].name, PTN.DOM_CONTENT_LOADED_EVENT_END);
568-
assert.strictEqual(rsEvents[6].name, PTN.DOM_COMPLETE);
569-
assert.strictEqual(rsEvents[7].name, PTN.LOAD_EVENT_START);
570-
assert.strictEqual(rsEvents[8].name, PTN.LOAD_EVENT_END);
560+
const rsEventNames = rsEvents.map(e => e.name);
561+
// Allow the unloadEvent{Start,End} events to be missing. Tests that
562+
// are simulating a fallback to window.performance.timing are using
563+
// values (entriesFallback) for that result in those network span
564+
// events being dropped after https://github.com/open-telemetry/opentelemetry-js/pull/4486
565+
// (@opentelemetry/[email protected]).
566+
const expectedRsEventNames =
567+
rsEventNames[1] === PTN.UNLOAD_EVENT_START
568+
? [
569+
PTN.FETCH_START,
570+
PTN.UNLOAD_EVENT_START,
571+
PTN.UNLOAD_EVENT_END,
572+
PTN.DOM_INTERACTIVE,
573+
PTN.DOM_CONTENT_LOADED_EVENT_START,
574+
PTN.DOM_CONTENT_LOADED_EVENT_END,
575+
PTN.DOM_COMPLETE,
576+
PTN.LOAD_EVENT_START,
577+
PTN.LOAD_EVENT_END,
578+
]
579+
: [
580+
PTN.FETCH_START,
581+
PTN.DOM_INTERACTIVE,
582+
PTN.DOM_CONTENT_LOADED_EVENT_START,
583+
PTN.DOM_CONTENT_LOADED_EVENT_END,
584+
PTN.DOM_COMPLETE,
585+
PTN.LOAD_EVENT_START,
586+
PTN.LOAD_EVENT_END,
587+
];
588+
assert.deepStrictEqual(rsEventNames, expectedRsEventNames);
571589

572-
assert.strictEqual(fsEvents.length, 8);
573-
assert.strictEqual(rsEvents.length, 9);
574590
assert.strictEqual(exporter.getFinishedSpans().length, 2);
575591
done();
576592
});
577593
});
578594
}
579595

580-
describe('when navigation entries types are NOT available then fallback to "performance.timing"', () => {
581-
const sandbox = sinon.createSandbox();
582-
beforeEach(() => {
583-
sandbox.stub(window.performance, 'getEntriesByType').value(undefined);
584-
sandbox.stub(window.performance, 'timing').get(() => {
585-
return entriesFallback;
586-
});
587-
});
588-
afterEach(() => {
589-
sandbox.restore();
590-
});
591-
592-
shouldExportCorrectSpan();
593-
});
594-
595596
describe('when getEntriesByType is not defined then fallback to "performance.timing"', () => {
596597
const sandbox = sinon.createSandbox();
597598
beforeEach(() => {

0 commit comments

Comments
 (0)