Skip to content
Closed
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
8 changes: 4 additions & 4 deletions packages/core/src/telemetry/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,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();
});
Expand All @@ -138,7 +138,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' }),
);
});

Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/telemetry/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,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,
});
Expand Down