diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index c437d9eec67..8a19a85904b 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -10,6 +10,9 @@ All notable changes to experimental packages in this project will be documented ### :bug: (Bug Fix) +* fix(exporter-*-otlp-*): use parseHeaders() to ensure header-values are not 'undefined' #4540 + * Fixes a bug where passing `undefined` as a header value would crash the end-user app after the export timeout elapsed. + ### :books: (Refine Doc) ### :house: (Internal) 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 9181b082cf9..0a020cb0593 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 @@ -21,7 +21,10 @@ import type { import type { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'; import type { IExportLogsServiceRequest } from '@opentelemetry/otlp-transformer'; import { getEnv, baggageUtils } from '@opentelemetry/core'; -import { OTLPExporterNodeBase } from '@opentelemetry/otlp-exporter-base'; +import { + OTLPExporterNodeBase, + parseHeaders, +} from '@opentelemetry/otlp-exporter-base'; import { createExportLogsServiceRequest } from '@opentelemetry/otlp-transformer'; import { getDefaultUrl } from '../config'; @@ -50,7 +53,7 @@ export class OTLPLogExporter ...baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_LOGS_HEADERS ), - ...config.headers, + ...parseHeaders(config?.headers), }; } 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 caec7352fff..16e86fc21e0 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 @@ -19,6 +19,7 @@ import { OTLPExporterConfigBase, appendResourcePathToUrl, appendRootPathToUrlIfNeeded, + parseHeaders, } from '@opentelemetry/otlp-exporter-base'; import { OTLPProtoExporterNodeBase, @@ -57,7 +58,7 @@ export class OTLPLogExporter ...baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_LOGS_HEADERS ), - ...config.headers, + ...parseHeaders(config?.headers), }; } convert(logs: ReadableLogRecord[]): IExportLogsServiceRequest { 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 aeb3b94ca72..892e5c5b692 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 @@ -16,7 +16,10 @@ import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'; import { getEnv, baggageUtils } from '@opentelemetry/core'; -import { OTLPExporterNodeBase } from '@opentelemetry/otlp-exporter-base'; +import { + OTLPExporterNodeBase, + parseHeaders, +} from '@opentelemetry/otlp-exporter-base'; import { OTLPExporterNodeConfigBase, appendResourcePathToUrl, @@ -49,7 +52,7 @@ export class OTLPTraceExporter ...baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS ), - ...config.headers, + ...parseHeaders(config?.headers), }; } 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 be115583cd6..48191660ecc 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 @@ -20,6 +20,7 @@ import { OTLPExporterNodeConfigBase, appendResourcePathToUrl, appendRootPathToUrlIfNeeded, + parseHeaders, } from '@opentelemetry/otlp-exporter-base'; import { OTLPProtoExporterNodeBase, @@ -52,7 +53,7 @@ export class OTLPTraceExporter ...baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS ), - ...config.headers, + ...parseHeaders(config?.headers), }; } 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 77d68d60a67..4151dbd5396 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts @@ -33,6 +33,7 @@ import { IExportMetricsServiceResponse, } from '@opentelemetry/otlp-transformer'; import { VERSION } from './version'; +import { parseHeaders } from '@opentelemetry/otlp-exporter-base'; const USER_AGENT = { 'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`, @@ -49,7 +50,7 @@ class OTLPMetricExporterProxy extends OTLPGRPCExporterNodeBase< ...baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS ), - ...config?.headers, + ...parseHeaders(config?.headers), }; super( config, 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 cd648ce8753..5831f74cf9a 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 @@ -23,6 +23,7 @@ import { OTLPExporterNodeConfigBase, appendResourcePathToUrl, appendRootPathToUrlIfNeeded, + parseHeaders, } from '@opentelemetry/otlp-exporter-base'; import { createExportMetricsServiceRequest, @@ -48,7 +49,7 @@ class OTLPExporterNodeProxy extends OTLPExporterNodeBase< ...baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS ), - ...config?.headers, + ...parseHeaders(config?.headers), }; } 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 52c9991e30a..9d424687cf6 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -26,6 +26,7 @@ import { OTLPExporterNodeConfigBase, appendResourcePathToUrl, appendRootPathToUrlIfNeeded, + parseHeaders, } from '@opentelemetry/otlp-exporter-base'; import { createExportMetricsServiceRequest, @@ -51,7 +52,7 @@ class OTLPMetricExporterNodeProxy extends OTLPProtoExporterNodeBase< ...baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS ), - ...config?.headers, + ...parseHeaders(config?.headers), }; } diff --git a/experimental/packages/otlp-exporter-base/src/util.ts b/experimental/packages/otlp-exporter-base/src/util.ts index f5dc70c9e88..2824752e100 100644 --- a/experimental/packages/otlp-exporter-base/src/util.ts +++ b/experimental/packages/otlp-exporter-base/src/util.ts @@ -35,7 +35,9 @@ export function parseHeaders( if (typeof value !== 'undefined') { headers[key] = String(value); } else { - diag.warn(`Header "${key}" has wrong value and will be ignored`); + diag.warn( + `Header "${key}" has invalid value (${value}) and will be ignored` + ); } }); return headers; diff --git a/experimental/packages/otlp-exporter-base/test/common/util.test.ts b/experimental/packages/otlp-exporter-base/test/common/util.test.ts index e1e539273ef..4448ec06da0 100644 --- a/experimental/packages/otlp-exporter-base/test/common/util.test.ts +++ b/experimental/packages/otlp-exporter-base/test/common/util.test.ts @@ -46,7 +46,7 @@ describe('utils', () => { const args = spyWarn.args[0]; assert.strictEqual( args[0], - 'Header "foo1" has wrong value and will be ignored' + 'Header "foo1" has invalid value (undefined) and will be ignored' ); });