Skip to content

Commit 11b0cda

Browse files
refactor(core): use native URL object for OTLP HTTP path construction
1 parent 3905e81 commit 11b0cda

File tree

1 file changed

+9
-5
lines changed
  • packages/core/src/telemetry

1 file changed

+9
-5
lines changed

packages/core/src/telemetry/sdk.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,21 @@ export async function initializeTelemetry(
240240
});
241241
} else if (useOtlp) {
242242
if (otlpProtocol === 'http') {
243-
// Trim trailing slashes
244-
const baseUrl = parsedEndpoint.replace(/\/+$/, '');
243+
const buildUrl = (path: string) => {
244+
const url = new URL(parsedEndpoint);
245+
// Join the existing pathname with the new path, handling trailing slashes.
246+
url.pathname = [url.pathname.replace(/\/$/, ''), path].join('/');
247+
return url.href;
248+
};
245249
spanExporter = new OTLPTraceExporterHttp({
246-
url: `${baseUrl}/v1/traces`,
250+
url: buildUrl('v1/traces'),
247251
});
248252
logExporter = new OTLPLogExporterHttp({
249-
url: `${baseUrl}/v1/logs`,
253+
url: buildUrl('v1/logs'),
250254
});
251255
metricReader = new PeriodicExportingMetricReader({
252256
exporter: new OTLPMetricExporterHttp({
253-
url: `${baseUrl}/v1/metrics`,
257+
url: buildUrl('v1/metrics'),
254258
}),
255259
exportIntervalMillis: 10000,
256260
});

0 commit comments

Comments
 (0)