Skip to content

Commit

Permalink
test(http): add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud committed Apr 18, 2020
1 parent 4717ebd commit ef451f6
Showing 1 changed file with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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);
});
});
});
});
});

0 comments on commit ef451f6

Please sign in to comment.