Skip to content

Commit 7d31d5f

Browse files
fix(core): append correct OTLP paths for HTTP exporters (#16836)
1 parent 1a7d418 commit 7d31d5f

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

packages/core/src/telemetry/sdk.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ describe('Telemetry SDK', () => {
113113
await initializeTelemetry(mockConfig);
114114

115115
expect(OTLPTraceExporterHttp).toHaveBeenCalledWith({
116-
url: 'http://localhost:4318/',
116+
url: 'http://localhost:4318/v1/traces',
117117
});
118118
expect(OTLPLogExporterHttp).toHaveBeenCalledWith({
119-
url: 'http://localhost:4318/',
119+
url: 'http://localhost:4318/v1/logs',
120120
});
121121
expect(OTLPMetricExporterHttp).toHaveBeenCalledWith({
122-
url: 'http://localhost:4318/',
122+
url: 'http://localhost:4318/v1/metrics',
123123
});
124124
expect(NodeSDK.prototype.start).toHaveBeenCalled();
125125
});
@@ -141,7 +141,7 @@ describe('Telemetry SDK', () => {
141141
);
142142
await initializeTelemetry(mockConfig);
143143
expect(OTLPTraceExporterHttp).toHaveBeenCalledWith(
144-
expect.objectContaining({ url: 'https://my-collector.com/' }),
144+
expect.objectContaining({ url: 'https://my-collector.com/v1/traces' }),
145145
);
146146
});
147147

packages/core/src/telemetry/sdk.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,21 @@ export async function initializeTelemetry(
275275
});
276276
} else if (useOtlp) {
277277
if (otlpProtocol === 'http') {
278+
const buildUrl = (path: string) => {
279+
const url = new URL(parsedEndpoint);
280+
// Join the existing pathname with the new path, handling trailing slashes.
281+
url.pathname = [url.pathname.replace(/\/$/, ''), path].join('/');
282+
return url.href;
283+
};
278284
spanExporter = new OTLPTraceExporterHttp({
279-
url: parsedEndpoint,
285+
url: buildUrl('v1/traces'),
280286
});
281287
logExporter = new OTLPLogExporterHttp({
282-
url: parsedEndpoint,
288+
url: buildUrl('v1/logs'),
283289
});
284290
metricReader = new PeriodicExportingMetricReader({
285291
exporter: new OTLPMetricExporterHttp({
286-
url: parsedEndpoint,
292+
url: buildUrl('v1/metrics'),
287293
}),
288294
exportIntervalMillis: 10000,
289295
});

0 commit comments

Comments
 (0)