Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(exporters): use parseHeaders() to ensure header-values are not 'undefined' #4540

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -50,7 +53,7 @@ export class OTLPLogExporter
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_LOGS_HEADERS
),
...config.headers,
...parseHeaders(config?.headers),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
OTLPExporterConfigBase,
appendResourcePathToUrl,
appendRootPathToUrlIfNeeded,
parseHeaders,
} from '@opentelemetry/otlp-exporter-base';
import {
OTLPProtoExporterNodeBase,
Expand Down Expand Up @@ -57,7 +58,7 @@ export class OTLPLogExporter
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_LOGS_HEADERS
),
...config.headers,
...parseHeaders(config?.headers),
};
}
convert(logs: ReadableLogRecord[]): IExportLogsServiceRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -49,7 +52,7 @@ export class OTLPTraceExporter
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS
),
...config.headers,
...parseHeaders(config?.headers),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
OTLPExporterNodeConfigBase,
appendResourcePathToUrl,
appendRootPathToUrlIfNeeded,
parseHeaders,
} from '@opentelemetry/otlp-exporter-base';
import {
OTLPProtoExporterNodeBase,
Expand Down Expand Up @@ -52,7 +53,7 @@ export class OTLPTraceExporter
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS
),
...config.headers,
...parseHeaders(config?.headers),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand All @@ -49,7 +50,7 @@ class OTLPMetricExporterProxy extends OTLPGRPCExporterNodeBase<
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS
),
...config?.headers,
...parseHeaders(config?.headers),
};
super(
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
OTLPExporterNodeConfigBase,
appendResourcePathToUrl,
appendRootPathToUrlIfNeeded,
parseHeaders,
} from '@opentelemetry/otlp-exporter-base';
import {
createExportMetricsServiceRequest,
Expand All @@ -48,7 +49,7 @@ class OTLPExporterNodeProxy extends OTLPExporterNodeBase<
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS
),
...config?.headers,
...parseHeaders(config?.headers),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
OTLPExporterNodeConfigBase,
appendResourcePathToUrl,
appendRootPathToUrlIfNeeded,
parseHeaders,
} from '@opentelemetry/otlp-exporter-base';
import {
createExportMetricsServiceRequest,
Expand All @@ -51,7 +52,7 @@ class OTLPMetricExporterNodeProxy extends OTLPProtoExporterNodeBase<
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS
),
...config?.headers,
...parseHeaders(config?.headers),
};
}

Expand Down
4 changes: 3 additions & 1 deletion experimental/packages/otlp-exporter-base/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});

Expand Down