diff --git a/packages/core/src/telemetry/sdk.test.ts b/packages/core/src/telemetry/sdk.test.ts index e6d3f26ae7..9636212e2c 100644 --- a/packages/core/src/telemetry/sdk.test.ts +++ b/packages/core/src/telemetry/sdk.test.ts @@ -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' }), ); }); diff --git a/packages/core/src/telemetry/sdk.ts b/packages/core/src/telemetry/sdk.ts index 66b89523db..3752d3e40f 100644 --- a/packages/core/src/telemetry/sdk.ts +++ b/packages/core/src/telemetry/sdk.ts @@ -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, });