From ef451f62fa3afb34d75074e00acefd18d71443e7 Mon Sep 17 00:00:00 2001 From: vmarchaud Date: Sat, 18 Apr 2020 14:09:33 +0200 Subject: [PATCH] test(http): add test case --- .../test/functionals/http-enable.test.ts | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts index 1707db8c4e3..aad52ce4508 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts @@ -698,13 +698,13 @@ describe('HttpPlugin', () => { }); describe('with require parent span', () => { - beforeEach(() => { + beforeEach(done => { memoryExporter.reset(); plugin.enable(http, provider, provider.logger, {}); server = http.createServer((request, response) => { response.end('Test Server Response'); }); - server.listen(serverPort); + server.listen(serverPort, done); }); afterEach(() => { @@ -774,6 +774,47 @@ describe('HttpPlugin', () => { true ); }); + + it(`should trace with parent with both requireParent options enabled`, done => { + plugin.disable(); + const config: HttpPluginConfig = { + requireParentforIncomingSpans: true, + requireParentforOutgoingSpans: true, + }; + plugin.enable(http, provider, provider.logger, config); + const testPath = `/test/test`; + const tracer = provider.getTracer('default'); + const span = tracer.startSpan('parentSpan', { + kind: SpanKind.INTERNAL, + }); + tracer.withSpan(span, () => { + httpRequest + .get(`${protocol}://${hostname}:${serverPort}${testPath}`) + .then(result => { + span.end(); + assert( + result.reqHeaders[DummyPropagation.TRACE_CONTEXT_KEY] !== + undefined + ); + assert( + result.reqHeaders[DummyPropagation.SPAN_CONTEXT_KEY] !== + undefined + ); + const spans = memoryExporter.getFinishedSpans(); + assert.strictEqual(spans.length, 2); + assert.strictEqual( + spans.filter(span => span.kind === SpanKind.CLIENT).length, + 1 + ); + assert.strictEqual( + spans.filter(span => span.kind === SpanKind.INTERNAL).length, + 1 + ); + return done(); + }) + .catch(done); + }); + }); }); }); });