Skip to content

Commit e54597e

Browse files
authored
Merge 03abf7a into c981558
2 parents c981558 + 03abf7a commit e54597e

File tree

5 files changed

+188
-279
lines changed

5 files changed

+188
-279
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
3333

3434
### :bug: (Bug Fix)
3535

36+
* fix(sdk-trace-web): add secureConnectionStart to https only [#3879](https://github.com/open-telemetry/opentelemetry-js/pull/3879) @Abinet18
3637
* fix(http-instrumentation): stop listening to `request`'s `close` event once it has emitted `response` [#3625](https://github.com/open-telemetry/opentelemetry-js/pull/3625) @SimenB
3738
* fix(sdk-node): fix initialization in bundled environments by not loading @opentelemetry/exporter-jaeger [#3739](https://github.com/open-telemetry/opentelemetry-js/pull/3739) @pichlermarc
3839

experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

+95-93
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ function createFakePerformanceObs(url: string) {
139139
return FakePerfObs;
140140
}
141141

142+
function testForCorrectEvents(
143+
events: tracing.TimedEvent[],
144+
eventNames: string[]
145+
) {
146+
for (let i = 0; i < events.length; i++) {
147+
assert.strictEqual(
148+
events[i].name,
149+
eventNames[i],
150+
`event ${eventNames[i]} is not defined`
151+
);
152+
}
153+
}
154+
142155
describe('fetch', () => {
143156
let contextManager: ZoneContextManager;
144157
let lastResponse: any | undefined;
@@ -152,6 +165,7 @@ describe('fetch', () => {
152165
let fetchInstrumentation: FetchInstrumentation;
153166

154167
const url = 'http://localhost:8090/get';
168+
const secureUrl = 'https://localhost:8090/get';
155169
const badUrl = 'http://foo.bar.com/get';
156170

157171
const clearData = () => {
@@ -399,53 +413,17 @@ describe('fetch', () => {
399413
it('span should have correct events', () => {
400414
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
401415
const events = span.events;
402-
assert.strictEqual(events.length, 9, 'number of events is wrong');
403-
404-
assert.strictEqual(
405-
events[0].name,
416+
assert.strictEqual(events.length, 8, 'number of events is wrong');
417+
testForCorrectEvents(events, [
406418
PTN.FETCH_START,
407-
`event ${PTN.FETCH_START} is not defined`
408-
);
409-
assert.strictEqual(
410-
events[1].name,
411419
PTN.DOMAIN_LOOKUP_START,
412-
`event ${PTN.DOMAIN_LOOKUP_START} is not defined`
413-
);
414-
assert.strictEqual(
415-
events[2].name,
416420
PTN.DOMAIN_LOOKUP_END,
417-
`event ${PTN.DOMAIN_LOOKUP_END} is not defined`
418-
);
419-
assert.strictEqual(
420-
events[3].name,
421421
PTN.CONNECT_START,
422-
`event ${PTN.CONNECT_START} is not defined`
423-
);
424-
assert.strictEqual(
425-
events[4].name,
426-
PTN.SECURE_CONNECTION_START,
427-
`event ${PTN.SECURE_CONNECTION_START} is not defined`
428-
);
429-
assert.strictEqual(
430-
events[5].name,
431422
PTN.CONNECT_END,
432-
`event ${PTN.CONNECT_END} is not defined`
433-
);
434-
assert.strictEqual(
435-
events[6].name,
436423
PTN.REQUEST_START,
437-
`event ${PTN.REQUEST_START} is not defined`
438-
);
439-
assert.strictEqual(
440-
events[7].name,
441424
PTN.RESPONSE_START,
442-
`event ${PTN.RESPONSE_START} is not defined`
443-
);
444-
assert.strictEqual(
445-
events[8].name,
446425
PTN.RESPONSE_END,
447-
`event ${PTN.RESPONSE_END} is not defined`
448-
);
426+
]);
449427
});
450428

451429
it('should create a span for preflight request', () => {
@@ -479,53 +457,17 @@ describe('fetch', () => {
479457
it('preflight request span should have correct events', () => {
480458
const span: tracing.ReadableSpan = exportSpy.args[0][0][0];
481459
const events = span.events;
482-
assert.strictEqual(events.length, 9, 'number of events is wrong');
483-
484-
assert.strictEqual(
485-
events[0].name,
460+
assert.strictEqual(events.length, 8, 'number of events is wrong');
461+
testForCorrectEvents(events, [
486462
PTN.FETCH_START,
487-
`event ${PTN.FETCH_START} is not defined`
488-
);
489-
assert.strictEqual(
490-
events[1].name,
491463
PTN.DOMAIN_LOOKUP_START,
492-
`event ${PTN.DOMAIN_LOOKUP_START} is not defined`
493-
);
494-
assert.strictEqual(
495-
events[2].name,
496464
PTN.DOMAIN_LOOKUP_END,
497-
`event ${PTN.DOMAIN_LOOKUP_END} is not defined`
498-
);
499-
assert.strictEqual(
500-
events[3].name,
501465
PTN.CONNECT_START,
502-
`event ${PTN.CONNECT_START} is not defined`
503-
);
504-
assert.strictEqual(
505-
events[4].name,
506-
PTN.SECURE_CONNECTION_START,
507-
`event ${PTN.SECURE_CONNECTION_START} is not defined`
508-
);
509-
assert.strictEqual(
510-
events[5].name,
511466
PTN.CONNECT_END,
512-
`event ${PTN.CONNECT_END} is not defined`
513-
);
514-
assert.strictEqual(
515-
events[6].name,
516467
PTN.REQUEST_START,
517-
`event ${PTN.REQUEST_START} is not defined`
518-
);
519-
assert.strictEqual(
520-
events[7].name,
521468
PTN.RESPONSE_START,
522-
`event ${PTN.RESPONSE_START} is not defined`
523-
);
524-
assert.strictEqual(
525-
events[8].name,
526469
PTN.RESPONSE_END,
527-
`event ${PTN.RESPONSE_END} is not defined`
528-
);
470+
]);
529471
});
530472

531473
it('should set trace headers', () => {
@@ -639,6 +581,51 @@ describe('fetch', () => {
639581
});
640582
});
641583

584+
describe('when request is secure and successful', () => {
585+
beforeEach(async () => {
586+
const propagateTraceHeaderCorsUrls = [secureUrl];
587+
await prepareData(secureUrl, { propagateTraceHeaderCorsUrls });
588+
});
589+
590+
afterEach(() => {
591+
clearData();
592+
});
593+
594+
it('span should have correct events', () => {
595+
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
596+
const events = span.events;
597+
assert.strictEqual(events.length, 9, 'number of events is wrong');
598+
testForCorrectEvents(events, [
599+
PTN.FETCH_START,
600+
PTN.DOMAIN_LOOKUP_START,
601+
PTN.DOMAIN_LOOKUP_END,
602+
PTN.CONNECT_START,
603+
PTN.SECURE_CONNECTION_START,
604+
PTN.CONNECT_END,
605+
PTN.REQUEST_START,
606+
PTN.RESPONSE_START,
607+
PTN.RESPONSE_END,
608+
]);
609+
});
610+
611+
it('preflight request span should have correct events', () => {
612+
const span: tracing.ReadableSpan = exportSpy.args[0][0][0];
613+
const events = span.events;
614+
assert.strictEqual(events.length, 9, 'number of events is wrong');
615+
testForCorrectEvents(events, [
616+
PTN.FETCH_START,
617+
PTN.DOMAIN_LOOKUP_START,
618+
PTN.DOMAIN_LOOKUP_END,
619+
PTN.CONNECT_START,
620+
PTN.SECURE_CONNECTION_START,
621+
PTN.CONNECT_END,
622+
PTN.REQUEST_START,
623+
PTN.RESPONSE_START,
624+
PTN.RESPONSE_END,
625+
]);
626+
});
627+
});
628+
642629
describe('applyCustomAttributesOnSpan option', () => {
643630
const prepare = async (
644631
url: string,
@@ -815,13 +802,18 @@ describe('fetch', () => {
815802
`Wrong number of spans: ${exportSpy.args.length}`
816803
);
817804

818-
assert.strictEqual(events.length, 9, 'number of events is wrong');
805+
assert.strictEqual(events.length, 8, 'number of events is wrong');
819806

820-
assert.strictEqual(
821-
events[6].name,
807+
testForCorrectEvents(events, [
808+
PTN.FETCH_START,
809+
PTN.DOMAIN_LOOKUP_START,
810+
PTN.DOMAIN_LOOKUP_END,
811+
PTN.CONNECT_START,
812+
PTN.CONNECT_END,
822813
PTN.REQUEST_START,
823-
`event ${PTN.REQUEST_START} is not defined`
824-
);
814+
PTN.RESPONSE_START,
815+
PTN.RESPONSE_END,
816+
]);
825817
});
826818
});
827819

@@ -844,12 +836,17 @@ describe('fetch', () => {
844836
`Wrong number of spans: ${exportSpy.args.length}`
845837
);
846838

847-
assert.strictEqual(events.length, 9, 'number of events is wrong');
848-
assert.strictEqual(
849-
events[6].name,
839+
assert.strictEqual(events.length, 8, 'number of events is wrong');
840+
testForCorrectEvents(events, [
841+
PTN.FETCH_START,
842+
PTN.DOMAIN_LOOKUP_START,
843+
PTN.DOMAIN_LOOKUP_END,
844+
PTN.CONNECT_START,
845+
PTN.CONNECT_END,
850846
PTN.REQUEST_START,
851-
`event ${PTN.REQUEST_START} is not defined`
852-
);
847+
PTN.RESPONSE_START,
848+
PTN.RESPONSE_END,
849+
]);
853850
});
854851

855852
it('should have an absolute http.url attribute', () => {
@@ -882,12 +879,17 @@ describe('fetch', () => {
882879
2,
883880
`Wrong number of spans: ${exportSpy.args.length}`
884881
);
885-
assert.strictEqual(events.length, 9, 'number of events is wrong');
886-
assert.strictEqual(
887-
events[6].name,
882+
assert.strictEqual(events.length, 8, 'number of events is wrong');
883+
testForCorrectEvents(events, [
884+
PTN.FETCH_START,
885+
PTN.DOMAIN_LOOKUP_START,
886+
PTN.DOMAIN_LOOKUP_END,
887+
PTN.CONNECT_START,
888+
PTN.CONNECT_END,
888889
PTN.REQUEST_START,
889-
`event ${PTN.REQUEST_START} is not defined`
890-
);
890+
PTN.RESPONSE_START,
891+
PTN.RESPONSE_END,
892+
]);
891893
});
892894
});
893895

0 commit comments

Comments
 (0)