From 361c1acab4f70c2829b06b608f902ada182f3026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B2=92=E7=B2=92=E6=A9=99?= Date: Thu, 18 May 2023 12:26:26 +0800 Subject: [PATCH] chore(otlp-exporter): add `user-agent` header/metadata tests --- .../exporter-logs-otlp-grpc/test/OTLPLogExporter.test.ts | 7 +++++++ .../test/OTLPTraceExporter.test.ts | 7 +++++++ .../test/node/CollectorTraceExporter.test.ts | 8 ++++++++ .../test/node/OTLPTraceExporter.test.ts | 8 ++++++++ .../test/OTLPMetricExporter.test.ts | 8 ++++++++ .../test/node/CollectorMetricExporter.test.ts | 8 ++++++++ .../test/OTLPMetricExporter.test.ts | 8 ++++++++ 7 files changed, 54 insertions(+) diff --git a/experimental/packages/exporter-logs-otlp-grpc/test/OTLPLogExporter.test.ts b/experimental/packages/exporter-logs-otlp-grpc/test/OTLPLogExporter.test.ts index 35fafff96a..7884f47a46 100644 --- a/experimental/packages/exporter-logs-otlp-grpc/test/OTLPLogExporter.test.ts +++ b/experimental/packages/exporter-logs-otlp-grpc/test/OTLPLogExporter.test.ts @@ -37,6 +37,7 @@ import { IExportLogsServiceRequest, IResourceLogs, } from '@opentelemetry/otlp-transformer'; +import { VERSION } from '../src/version'; const logsServiceProtoPath = 'opentelemetry/proto/collector/logs/v1/logs_service.proto'; @@ -320,6 +321,12 @@ describe('when configuring via environment', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = ''; }); + it('should have user-agent header', () => { + const collectorExporter = new OTLPLogExporter(); + assert.deepStrictEqual(collectorExporter.metadata?.get('User-Agent'), [ + `OTel-OTLP-Exporter-JavaScript/${VERSION}`, + ]); + }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPLogExporter(); diff --git a/experimental/packages/exporter-trace-otlp-grpc/test/OTLPTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-grpc/test/OTLPTraceExporter.test.ts index ea0d6ec212..f9cae3ea97 100644 --- a/experimental/packages/exporter-trace-otlp-grpc/test/OTLPTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-grpc/test/OTLPTraceExporter.test.ts @@ -41,6 +41,7 @@ import { IExportTraceServiceRequest, IResourceSpans, } from '@opentelemetry/otlp-transformer'; +import { VERSION } from '../src/version'; const traceServiceProtoPath = 'opentelemetry/proto/collector/trace/v1/trace_service.proto'; @@ -330,6 +331,12 @@ describe('when configuring via environment', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); + it('should have user-agent header', () => { + const collectorExporter = new OTLPTraceExporter(); + assert.deepStrictEqual(collectorExporter.metadata?.get('User-Agent'), [ + `OTel-OTLP-Exporter-JavaScript/${VERSION}`, + ]); + }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPTraceExporter(); 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 8f6dc67738..4838f0eca2 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 @@ -36,6 +36,7 @@ import { import { nextTick } from 'process'; import { MockedResponse } from './nodeHelpers'; import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer'; +import { VERSION } from '../../src/version'; let fakeRequest: PassThrough; @@ -154,6 +155,13 @@ describe('OTLPTraceExporter - node with json over http', () => { ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); + it('should have user-agent header', () => { + const collectorExporter = new OTLPTraceExporter(); + assert.deepStrictEqual( + collectorExporter.headers['user-agent'], + `OTel-OTLP-Exporter-JavaScript/${VERSION}` + ); + }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPTraceExporter(); 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 c80cdf8ea2..7ccbe18f10 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 @@ -39,6 +39,7 @@ import { ServiceClientType, } from '@opentelemetry/otlp-proto-exporter-base'; import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer'; +import { VERSION } from '../../src/version'; let fakeRequest: PassThrough; @@ -129,6 +130,13 @@ describe('OTLPTraceExporter - node with proto over http', () => { ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); + it('should have user-agent header', () => { + const collectorExporter = new OTLPTraceExporter(); + assert.deepStrictEqual( + collectorExporter.headers['user-agent'], + `OTel-OTLP-Exporter-JavaScript/${VERSION}` + ); + }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPTraceExporter(); 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 be17daa09b..b81bffb8d9 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,6 +43,7 @@ import { IExportMetricsServiceRequest, IResourceMetrics, } from '@opentelemetry/otlp-transformer'; +import { VERSION } from '../src/version'; const metricsServiceProtoPath = 'opentelemetry/proto/collector/metrics/v1/metrics_service.proto'; @@ -305,6 +306,13 @@ describe('when configuring via environment', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); + it('should have user-agent header', () => { + const collectorExporter = new OTLPMetricExporter(); + assert.deepStrictEqual( + collectorExporter._otlpExporter.metadata?.get('User-Agent'), + [`OTel-OTLP-Exporter-JavaScript/${VERSION}`] + ); + }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPMetricExporter(); 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 1f972b6796..196eae4c1a 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,6 +50,7 @@ import { OTLPExporterNodeConfigBase, } from '@opentelemetry/otlp-exporter-base'; import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { VERSION } from '../../src/version'; let fakeRequest: PassThrough; @@ -182,6 +183,13 @@ describe('OTLPMetricExporter - node with json over http', () => { ); envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); + it('should have user-agent header', () => { + const collectorExporter = new OTLPMetricExporter(); + assert.deepStrictEqual( + collectorExporter._otlpExporter.headers['user-agent'], + `OTel-OTLP-Exporter-JavaScript/${VERSION}` + ); + }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPMetricExporter(); 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 2f98e46492..9b9c61e4c3 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,6 +46,7 @@ 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; @@ -138,6 +139,13 @@ describe('OTLPMetricExporter - node with proto over http', () => { ); envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); + it('should have user-agent header', () => { + const collectorExporter = new OTLPMetricExporter(); + assert.deepStrictEqual( + collectorExporter._otlpExporter.headers['user-agent'], + `OTel-OTLP-Exporter-JavaScript/${VERSION}` + ); + }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPMetricExporter();