From a89e6b35bc30ce71e79541603ef28fa96747367f Mon Sep 17 00:00:00 2001 From: Ryan Eberhardt Date: Wed, 12 Jun 2024 15:37:26 -0700 Subject: [PATCH] fix(instr-http): respect requireParent flag when INVALID_SPAN_CONTEXT is used --- experimental/CHANGELOG.md | 1 + .../src/http.ts | 2 +- .../test/functionals/http-enable.test.ts | 19 ++++++++++++++++++ package-lock.json | 20 +++++++++---------- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index c46df852a2a..cf15ba81466 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to experimental packages in this project will be documented ### :bug: (Bug Fix) * fix(sdk-node): register context manager if no tracer options are provided [#4781](https://github.com/open-telemetry/opentelemetry-js/pull/4781) @pichlermarc +* fix(instrumentation-http): respect requireParent flag when INVALID_SPAN_CONTEXT is used [#4788](https://github.com/open-telemetry/opentelemetry-js/pull/4788) @reberhardt7 ### :books: (Refine Doc) diff --git a/experimental/packages/opentelemetry-instrumentation-http/src/http.ts b/experimental/packages/opentelemetry-instrumentation-http/src/http.ts index a42927fff5e..400a8744164 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/src/http.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/src/http.ts @@ -765,7 +765,7 @@ 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({ diff --git a/package-lock.json b/package-lock.json index 99b0b22d0f1..21f2df14066 100644 --- a/package-lock.json +++ b/package-lock.json @@ -785,7 +785,7 @@ "version": "0.52.0", "license": "Apache-2.0", "dependencies": { - "@grpc/grpc-js": "^1.10.9", + "@grpc/grpc-js": "^1.7.1", "@opentelemetry/core": "1.25.0", "@opentelemetry/otlp-grpc-exporter-base": "0.52.0", "@opentelemetry/otlp-transformer": "0.52.0", @@ -1217,7 +1217,7 @@ "version": "0.52.0", "license": "Apache-2.0", "dependencies": { - "@grpc/grpc-js": "^1.10.9", + "@grpc/grpc-js": "^1.7.1", "@opentelemetry/core": "1.25.0", "@opentelemetry/otlp-grpc-exporter-base": "0.52.0", "@opentelemetry/otlp-transformer": "0.52.0", @@ -1817,7 +1817,7 @@ "version": "0.52.0", "license": "Apache-2.0", "dependencies": { - "@grpc/grpc-js": "^1.10.9", + "@grpc/grpc-js": "^1.7.1", "@opentelemetry/core": "1.25.0", "@opentelemetry/exporter-metrics-otlp-http": "0.52.0", "@opentelemetry/otlp-exporter-base": "0.52.0", @@ -2451,7 +2451,7 @@ }, "devDependencies": { "@bufbuild/buf": "1.21.0-1", - "@grpc/grpc-js": "^1.10.9", + "@grpc/grpc-js": "^1.7.1", "@grpc/proto-loader": "^0.7.10", "@opentelemetry/api": "1.9.0", "@opentelemetry/context-async-hooks": "1.25.0", @@ -3176,7 +3176,7 @@ "version": "0.52.0", "license": "Apache-2.0", "dependencies": { - "@grpc/grpc-js": "^1.10.9", + "@grpc/grpc-js": "^1.7.1", "@opentelemetry/core": "1.25.0", "@opentelemetry/otlp-exporter-base": "0.52.0", "@opentelemetry/otlp-transformer": "0.52.0" @@ -37597,7 +37597,7 @@ "@opentelemetry/exporter-logs-otlp-grpc": { "version": "file:experimental/packages/exporter-logs-otlp-grpc", "requires": { - "@grpc/grpc-js": "1.10.9", + "@grpc/grpc-js": "^1.7.1", "@grpc/proto-loader": "^0.7.10", "@opentelemetry/api": "1.9.0", "@opentelemetry/api-logs": "0.52.0", @@ -37904,7 +37904,7 @@ "@opentelemetry/exporter-metrics-otlp-grpc": { "version": "file:experimental/packages/opentelemetry-exporter-metrics-otlp-grpc", "requires": { - "@grpc/grpc-js": "^1.10.9", + "@grpc/grpc-js": "^1.7.1", "@grpc/proto-loader": "^0.7.10", "@opentelemetry/api": "1.9.0", "@opentelemetry/core": "1.25.0", @@ -38193,7 +38193,7 @@ "@opentelemetry/exporter-trace-otlp-grpc": { "version": "file:experimental/packages/exporter-trace-otlp-grpc", "requires": { - "@grpc/grpc-js": "^1.10.9", + "@grpc/grpc-js": "^1.7.1", "@grpc/proto-loader": "^0.7.10", "@opentelemetry/api": "1.9.0", "@opentelemetry/core": "1.25.0", @@ -38875,7 +38875,7 @@ "version": "file:experimental/packages/opentelemetry-instrumentation-grpc", "requires": { "@bufbuild/buf": "1.21.0-1", - "@grpc/grpc-js": "^1.10.9", + "@grpc/grpc-js": "^1.7.1", "@grpc/proto-loader": "^0.7.10", "@opentelemetry/api": "1.9.0", "@opentelemetry/context-async-hooks": "1.25.0", @@ -39415,7 +39415,7 @@ "@opentelemetry/otlp-grpc-exporter-base": { "version": "file:experimental/packages/otlp-grpc-exporter-base", "requires": { - "@grpc/grpc-js": "^1.10.9", + "@grpc/grpc-js": "^1.7.1", "@opentelemetry/api": "1.9.0", "@opentelemetry/core": "1.25.0", "@opentelemetry/otlp-exporter-base": "0.52.0",