From 3cd8c0acf25db32219c27fe75ad60fe15c8c3565 Mon Sep 17 00:00:00 2001 From: Vladimir Adamic Date: Fri, 8 Dec 2023 17:47:56 +0100 Subject: [PATCH 1/7] fix(exporter-logs-otlp-proto): programatic headers take precedence over environment variables --- experimental/CHANGELOG.md | 1 + .../src/platform/node/OTLPLogExporter.ts | 3 ++- .../test/node/OTLPLogExporter.test.ts | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 0454299c684..4fb79597588 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to experimental packages in this project will be documented * fix(exporter-metrics-otlp-http): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4334) @Vunovati * fix(exporter-metrics-otlp-proto): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4334) @Vunovati +* fix(exporter-logs-otlp-proto): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4334) @Vunovati ### :rocket: (Enhancement) * feat(sdk-logs): add droppedAttributesCount field to ReadableLogRecord diff --git a/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts b/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts index 53191c06254..a8cdfc4c969 100644 --- a/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts +++ b/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts @@ -50,7 +50,8 @@ export class OTLPLogExporter this.headers, baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_LOGS_HEADERS - ) + ), + config.headers ); } convert(logs: ReadableLogRecord[]): IExportLogsServiceRequest { diff --git a/experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogExporter.test.ts b/experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogExporter.test.ts index 0810109e817..0fc32f5e890 100644 --- a/experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogExporter.test.ts +++ b/experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogExporter.test.ts @@ -92,6 +92,15 @@ describe('OTLPLogExporter - node with proto over http', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = ''; }); + it('should override url defined in env with url defined in constructor', () => { + envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/'; + const constructorDefinedEndpoint = 'http://constructor/v1/logs'; + const collectorExporter = new OTLPLogExporter({ + url: constructorDefinedEndpoint, + }); + assert.strictEqual(collectorExporter.url, constructorDefinedEndpoint); + envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = ''; + }); it('should add root path when signal url defined in env contains no path and no root path', () => { envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = 'http://foo.bar'; const collectorExporter = new OTLPLogExporter(); @@ -143,6 +152,17 @@ describe('OTLPLogExporter - node with proto over http', () => { envSource.OTEL_EXPORTER_OTLP_LOGS_HEADERS = ''; envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; }); + it('should override headers defined via env with headers defined in constructor', () => { + envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo'; + const collectorExporter = new OTLPLogExporter({ + headers: { + foo: 'constructor', + }, + }); + assert.strictEqual(collectorExporter.headers.foo, 'constructor'); + assert.strictEqual(collectorExporter.headers.bar, 'foo'); + envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; + }); }); describe('export', () => { From 9d5c77e219f4101f63e3c0b23b05554a5cf353f1 Mon Sep 17 00:00:00 2001 From: Vladimir Adamic Date: Fri, 8 Dec 2023 17:58:18 +0100 Subject: [PATCH 2/7] chore: update PR url in changelog --- experimental/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 4fb79597588..2d6d95e2bea 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to experimental packages in this project will be documented * fix(exporter-metrics-otlp-http): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4334) @Vunovati * fix(exporter-metrics-otlp-proto): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4334) @Vunovati -* fix(exporter-logs-otlp-proto): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4334) @Vunovati +* fix(exporter-logs-otlp-proto): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4351) @Vunovati ### :rocket: (Enhancement) * feat(sdk-logs): add droppedAttributesCount field to ReadableLogRecord From 839e0e651542e3413c08e151bd96056944bb2fd9 Mon Sep 17 00:00:00 2001 From: Vladimir Adamic Date: Fri, 8 Dec 2023 20:00:59 +0100 Subject: [PATCH 3/7] chore: fix deletion of env var --- .../exporter-logs-otlp-proto/test/node/OTLPLogExporter.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogExporter.test.ts b/experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogExporter.test.ts index 0fc32f5e890..ab918c992b6 100644 --- a/experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogExporter.test.ts +++ b/experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogExporter.test.ts @@ -99,7 +99,7 @@ describe('OTLPLogExporter - node with proto over http', () => { url: constructorDefinedEndpoint, }); assert.strictEqual(collectorExporter.url, constructorDefinedEndpoint); - envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = ''; + envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; }); it('should add root path when signal url defined in env contains no path and no root path', () => { envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = 'http://foo.bar'; From 77b3482e2f1b6c9659312b483950def5c75ba99d Mon Sep 17 00:00:00 2001 From: Vladimir Adamic Date: Fri, 8 Dec 2023 20:02:29 +0100 Subject: [PATCH 4/7] fix(exporter-logs-otlp-http): programatic headers take precedence over environment variables --- .../src/platform/node/OTLPLogExporter.ts | 9 +++++---- .../test/node/OTLPLogExporter.test.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/experimental/packages/exporter-logs-otlp-http/src/platform/node/OTLPLogExporter.ts b/experimental/packages/exporter-logs-otlp-http/src/platform/node/OTLPLogExporter.ts index 25a1b194ab9..56e4bad3d69 100644 --- a/experimental/packages/exporter-logs-otlp-http/src/platform/node/OTLPLogExporter.ts +++ b/experimental/packages/exporter-logs-otlp-http/src/platform/node/OTLPLogExporter.ts @@ -39,12 +39,13 @@ export class OTLPLogExporter timeoutMillis: getEnv().OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, ...config, }); - this.headers = { - ...this.headers, - ...baggageUtils.parseKeyPairsIntoRecord( + this.headers = Object.assign( + this.headers, + baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_LOGS_HEADERS ), - }; + config.headers + ); } convert(logRecords: ReadableLogRecord[]): IExportLogsServiceRequest { diff --git a/experimental/packages/exporter-logs-otlp-http/test/node/OTLPLogExporter.test.ts b/experimental/packages/exporter-logs-otlp-http/test/node/OTLPLogExporter.test.ts index 6dac23b5809..83b389628a4 100644 --- a/experimental/packages/exporter-logs-otlp-http/test/node/OTLPLogExporter.test.ts +++ b/experimental/packages/exporter-logs-otlp-http/test/node/OTLPLogExporter.test.ts @@ -94,6 +94,18 @@ describe('OTLPLogExporter', () => { delete envSource.OTEL_EXPORTER_OTLP_LOGS_HEADERS; delete envSource.OTEL_EXPORTER_OTLP_LOGS_TIMEOUT; }); + + it('should override headers defined via env with headers defined in constructor', () => { + envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo'; + const collectorExporter = new OTLPLogExporter({ + headers: { + foo: 'constructor', + }, + }); + assert.strictEqual(collectorExporter.headers.foo, 'constructor'); + assert.strictEqual(collectorExporter.headers.bar, 'foo'); + envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; + }); }); describe('getDefaultUrl', () => { From a3ac92012b1d98f362bafea92f54a2cff33cdb4c Mon Sep 17 00:00:00 2001 From: Vladimir Adamic Date: Fri, 8 Dec 2023 20:03:14 +0100 Subject: [PATCH 5/7] fix(exporter-trace-otlp-http): programatic headers take precedence over environment variables --- .../src/platform/node/OTLPTraceExporter.ts | 1 + .../test/node/CollectorTraceExporter.test.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts index e4d3273239a..aeb3b94ca72 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts @@ -49,6 +49,7 @@ export class OTLPTraceExporter ...baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS ), + ...config.headers, }; } diff --git a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts index 3de60027dc7..e9af4ec37b4 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts @@ -118,6 +118,15 @@ describe('OTLPTraceExporter - node with json over http', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); + it('should override url defined in env with url defined in constructor', () => { + envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar'; + const constructorDefinedEndpoint = 'http://constructor/v1/traces'; + const collectorExporter = new OTLPTraceExporter({ + url: constructorDefinedEndpoint, + }); + assert.strictEqual(collectorExporter.url, constructorDefinedEndpoint); + envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; + }); it('should add root path when signal url defined in env contains no path and no root path', () => { envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar'; const collectorExporter = new OTLPTraceExporter(); @@ -177,6 +186,17 @@ describe('OTLPTraceExporter - node with json over http', () => { envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = ''; envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; }); + it('should override headers defined via env with headers defined in constructor', () => { + envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo'; + const collectorExporter = new OTLPTraceExporter({ + headers: { + foo: 'constructor', + }, + }); + assert.strictEqual(collectorExporter.headers.foo, 'constructor'); + assert.strictEqual(collectorExporter.headers.bar, 'foo'); + envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; + }); it('should use compression defined via env', () => { envSource.OTEL_EXPORTER_OTLP_COMPRESSION = 'gzip'; const collectorExporter = new OTLPTraceExporter(); From d6afe0dc91d1493df43cd49f56e04ba5c3b88a10 Mon Sep 17 00:00:00 2001 From: Vladimir Adamic Date: Fri, 8 Dec 2023 20:03:35 +0100 Subject: [PATCH 6/7] fix(exporter-trace-otlp-proto): programatic headers take precedence over environment variable --- .../src/platform/node/OTLPTraceExporter.ts | 1 + .../test/node/OTLPTraceExporter.test.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/experimental/packages/exporter-trace-otlp-proto/src/platform/node/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-proto/src/platform/node/OTLPTraceExporter.ts index 210a16145a5..be115583cd6 100644 --- a/experimental/packages/exporter-trace-otlp-proto/src/platform/node/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-proto/src/platform/node/OTLPTraceExporter.ts @@ -52,6 +52,7 @@ export class OTLPTraceExporter ...baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS ), + ...config.headers, }; } diff --git a/experimental/packages/exporter-trace-otlp-proto/test/node/OTLPTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-proto/test/node/OTLPTraceExporter.test.ts index c0a604ce90b..b18c5a39deb 100644 --- a/experimental/packages/exporter-trace-otlp-proto/test/node/OTLPTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-proto/test/node/OTLPTraceExporter.test.ts @@ -103,6 +103,15 @@ describe('OTLPTraceExporter - node with proto over http', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); + it('should override url defined in env with url defined in constructor', () => { + envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/'; + const constructorDefinedEndpoint = 'http://constructor/v1/traces'; + const collectorExporter = new OTLPTraceExporter({ + url: constructorDefinedEndpoint, + }); + assert.strictEqual(collectorExporter.url, constructorDefinedEndpoint); + envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; + }); it('should add root path when signal url defined in env contains no path and no root path', () => { envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar'; const collectorExporter = new OTLPTraceExporter(); @@ -155,6 +164,17 @@ describe('OTLPTraceExporter - node with proto over http', () => { envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = ''; envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; }); + it('should override headers defined via env with headers defined in constructor', () => { + envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo'; + const collectorExporter = new OTLPTraceExporter({ + headers: { + foo: 'constructor', + }, + }); + assert.strictEqual(collectorExporter.headers.foo, 'constructor'); + assert.strictEqual(collectorExporter.headers.bar, 'foo'); + envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; + }); }); describe('export', () => { From 39c76d630af19acf7c06f4dcbda8584ac11df0f1 Mon Sep 17 00:00:00 2001 From: Vladimir Adamic Date: Fri, 8 Dec 2023 20:03:49 +0100 Subject: [PATCH 7/7] chore: update CHANGELOG --- experimental/CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 2d6d95e2bea..9aa36b32785 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -9,8 +9,11 @@ All notable changes to experimental packages in this project will be documented * fix(exporter-metrics-otlp-grpc): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4334) @Vunovati * fix(exporter-metrics-otlp-http): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4334) @Vunovati * fix(exporter-metrics-otlp-proto): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4334) @Vunovati - +* fix(exporter-logs-otlp-http): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4351) @Vunovati * fix(exporter-logs-otlp-proto): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4351) @Vunovati +* fix(exporter-trace-otlp-http): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4351) @Vunovati +* fix(exporter-trace-otlp-proto): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4351) @Vunovati + ### :rocket: (Enhancement) * feat(sdk-logs): add droppedAttributesCount field to ReadableLogRecord