From 38bd83af372fec22188da195b4ba1d85f3485dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B2=92=E7=B2=92=E6=A9=99?= Date: Wed, 17 May 2023 16:57:58 +0800 Subject: [PATCH] Revert "feat(otlp-metric-exporters): Add User-Agent header to OTLP metric exporters (#3806)" This reverts commit 6a876a053fdcaeea20e53c2fa0d829c8a6819826. --- experimental/CHANGELOG.md | 2 +- .../src/OTLPMetricExporter.ts | 15 +++------------ .../test/OTLPMetricExporter.test.ts | 8 -------- .../src/platform/node/OTLPMetricExporter.ts | 15 +++++---------- .../test/node/CollectorMetricExporter.test.ts | 8 -------- .../src/OTLPMetricExporter.ts | 15 +++++---------- .../test/OTLPMetricExporter.test.ts | 11 ----------- 7 files changed, 14 insertions(+), 60 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 19a69846ed5..4c965835ac4 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -7,7 +7,7 @@ All notable changes to experimental packages in this project will be documented ### :rocket: (Enhancement) * feat(otlp-trace-exporters): Add User-Agent header to OTLP trace exporters. [#3790](https://github.com/open-telemetry/opentelemetry-js/pull/3790) @JamieDanielson -* feat(otlp-metric-exporters): Add User-Agent header to OTLP metric exporters. [#3806](https://github.com/open-telemetry/opentelemetry-js/pull/3806) @JamieDanielson +* * feat(otlp-metric-exporters): Add User-Agent header to OTLP metric exporters. [#3806](https://github.com/open-telemetry/opentelemetry-js/pull/3806) @JamieDanielson ### :boom: Breaking Change diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts index 0ada75d4375..20f917e5439 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts @@ -32,11 +32,6 @@ import { createExportMetricsServiceRequest, IExportMetricsServiceRequest, } from '@opentelemetry/otlp-transformer'; -import { VERSION } from './version'; - -const USER_AGENT = { - 'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`, -}; class OTLPMetricExporterProxy extends OTLPGRPCExporterNodeBase< ResourceMetrics, @@ -44,13 +39,9 @@ class OTLPMetricExporterProxy extends OTLPGRPCExporterNodeBase< > { constructor(config?: OTLPGRPCExporterConfigNode & OTLPMetricExporterOptions) { super(config); - const headers = { - ...USER_AGENT, - ...baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS - ), - }; - + const headers = baggageUtils.parseKeyPairsIntoRecord( + getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS + ); this.metadata ||= new Metadata(); for (const [k, v] of Object.entries(headers)) { this.metadata.set(k, v); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts index 9e4e27ecb0a..4b8d3265459 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts @@ -43,7 +43,6 @@ import { IExportMetricsServiceRequest, IResourceMetrics, } from '@opentelemetry/otlp-transformer'; -import { VERSION } from '../src/version'; const metricsServiceProtoPath = 'opentelemetry/proto/collector/metrics/v1/metrics_service.proto'; @@ -315,13 +314,6 @@ describe('when configuring via environment', () => { ); envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; }); - it('should include user agent in header', () => { - const collectorExporter = new OTLPMetricExporter(); - assert.deepStrictEqual( - collectorExporter._otlpExporter.metadata?.get('User-Agent'), - [`OTel-OTLP-Exporter-JavaScript/${VERSION}`] - ); - }); it('should override global headers config with signal headers defined via env', () => { const metadata = new grpc.Metadata(); metadata.set('foo', 'bar'); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts index f83e414e701..980931a6cb0 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts @@ -28,13 +28,9 @@ import { createExportMetricsServiceRequest, IExportMetricsServiceRequest, } from '@opentelemetry/otlp-transformer'; -import { VERSION } from '../../version'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/metrics'; const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; -const USER_AGENT = { - 'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`, -}; class OTLPExporterNodeProxy extends OTLPExporterNodeBase< ResourceMetrics, @@ -42,13 +38,12 @@ class OTLPExporterNodeProxy extends OTLPExporterNodeBase< > { constructor(config?: OTLPExporterNodeConfigBase & OTLPMetricExporterOptions) { super(config); - this.headers = { - ...this.headers, - ...USER_AGENT, - ...baggageUtils.parseKeyPairsIntoRecord( + this.headers = Object.assign( + this.headers, + baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS - ), - }; + ) + ); } convert(metrics: ResourceMetrics[]): IExportMetricsServiceRequest { diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts index 042e5ebb4be..d23ca628f70 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -50,7 +50,6 @@ import { OTLPExporterNodeConfigBase, } from '@opentelemetry/otlp-exporter-base'; import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; -import { VERSION } from '../../src/version'; let fakeRequest: PassThrough; @@ -189,13 +188,6 @@ describe('OTLPMetricExporter - node with json over http', () => { assert.strictEqual(collectorExporter._otlpExporter.headers.foo, 'bar'); envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; }); - it('should include user agent in header', () => { - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual( - collectorExporter._otlpExporter.headers['User-Agent'], - `OTel-OTLP-Exporter-JavaScript/${VERSION}` - ); - }); it('should override global headers config with signal headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo'; envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo'; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts index 8d1fb114b3f..c29ae0085ca 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -31,13 +31,9 @@ import { createExportMetricsServiceRequest, IExportMetricsServiceRequest, } from '@opentelemetry/otlp-transformer'; -import { VERSION } from './version'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/metrics'; const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; -const USER_AGENT = { - 'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`, -}; class OTLPMetricExporterNodeProxy extends OTLPProtoExporterNodeBase< ResourceMetrics, @@ -45,13 +41,12 @@ class OTLPMetricExporterNodeProxy extends OTLPProtoExporterNodeBase< > { constructor(config?: OTLPExporterNodeConfigBase & OTLPMetricExporterOptions) { super(config); - this.headers = { - ...this.headers, - ...USER_AGENT, - ...baggageUtils.parseKeyPairsIntoRecord( + this.headers = Object.assign( + this.headers, + baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS - ), - }; + ) + ); } convert(metrics: ResourceMetrics[]): IExportMetricsServiceRequest { diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts index d3270b6a9f3..05ca183dcc8 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts @@ -46,7 +46,6 @@ import { OTLPMetricExporterOptions } from '@opentelemetry/exporter-metrics-otlp- import { Stream, PassThrough } from 'stream'; import { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'; import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; -import { VERSION } from '../src/version'; let fakeRequest: PassThrough; @@ -61,16 +60,6 @@ describe('OTLPMetricExporter - node with proto over http', () => { sinon.restore(); }); - describe('default behavior for headers', () => { - const collectorExporter = new OTLPMetricExporter(); - it('should include user agent in header', () => { - assert.strictEqual( - collectorExporter._otlpExporter.headers['User-Agent'], - `OTel-OTLP-Exporter-JavaScript/${VERSION}` - ); - }); - }); - describe('when configuring via environment', () => { const envSource = process.env; it('should use url defined in env that ends with root path and append version and signal path', () => {