fix(core): append correct OTLP paths for HTTP exporters (#16836)

This commit is contained in:
Sébastien Prud'homme
2026-03-06 20:58:00 +01:00
committed by GitHub
parent 1a7d4184cd
commit 7d31d5f4ec
2 changed files with 13 additions and 7 deletions

View File

@@ -113,13 +113,13 @@ describe('Telemetry SDK', () => {
await initializeTelemetry(mockConfig);
expect(OTLPTraceExporterHttp).toHaveBeenCalledWith({
url: 'http://localhost:4318/',
url: 'http://localhost:4318/v1/traces',
});
expect(OTLPLogExporterHttp).toHaveBeenCalledWith({
url: 'http://localhost:4318/',
url: 'http://localhost:4318/v1/logs',
});
expect(OTLPMetricExporterHttp).toHaveBeenCalledWith({
url: 'http://localhost:4318/',
url: 'http://localhost:4318/v1/metrics',
});
expect(NodeSDK.prototype.start).toHaveBeenCalled();
});
@@ -141,7 +141,7 @@ describe('Telemetry SDK', () => {
);
await initializeTelemetry(mockConfig);
expect(OTLPTraceExporterHttp).toHaveBeenCalledWith(
expect.objectContaining({ url: 'https://my-collector.com/' }),
expect.objectContaining({ url: 'https://my-collector.com/v1/traces' }),
);
});

View File

@@ -275,15 +275,21 @@ export async function initializeTelemetry(
});
} else if (useOtlp) {
if (otlpProtocol === 'http') {
const buildUrl = (path: string) => {
const url = new URL(parsedEndpoint);
// Join the existing pathname with the new path, handling trailing slashes.
url.pathname = [url.pathname.replace(/\/$/, ''), path].join('/');
return url.href;
};
spanExporter = new OTLPTraceExporterHttp({
url: parsedEndpoint,
url: buildUrl('v1/traces'),
});
logExporter = new OTLPLogExporterHttp({
url: parsedEndpoint,
url: buildUrl('v1/logs'),
});
metricReader = new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporterHttp({
url: parsedEndpoint,
url: buildUrl('v1/metrics'),
}),
exportIntervalMillis: 10000,
});