diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 9731438b287..bbbffb3e3f1 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -12,6 +12,8 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2 ### :bug: Bug Fixes +* fix(instrumentation-http): respect requireParent flag when INVALID_SPAN_CONTEXT is used [#4788](https://github.com/open-telemetry/opentelemetry-js/pull/4788) @reberhardt7 + ### :books: Documentation ### :house: Internal diff --git a/experimental/packages/opentelemetry-instrumentation-http/src/http.ts b/experimental/packages/opentelemetry-instrumentation-http/src/http.ts index 4c0f0173258..dc47fe0c891 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/src/http.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/src/http.ts @@ -979,7 +979,10 @@ export class HttpInstrumentation extends InstrumentationBase { ); }); + it('should not trace with INVALID_SPAN_CONTEXT parent with requireParent options enabled', async () => { + instrumentation.disable(); + instrumentation.setConfig({ + requireParentforIncomingSpans: true, + requireParentforOutgoingSpans: true, + }); + instrumentation.enable(); + const root = trace.wrapSpanContext(INVALID_SPAN_CONTEXT); + await context.with(trace.setSpan(context.active(), root), async () => { + const testPath = '/test/test'; + await httpRequest.get( + `${protocol}://${hostname}:${serverPort}${testPath}` + ); + }); + const spans = memoryExporter.getFinishedSpans(); + assert.strictEqual(spans.length, 0); + }); + it('should trace with parent with both requireParent options enabled', done => { instrumentation.disable(); instrumentation.setConfig({