fix(telemetry): disable OTLP when telemetry-outfile is set (#9117)

This commit is contained in:
Jerop Kipruto
2025-09-23 01:40:30 +09:00
committed by GitHub
parent 9abb165f7b
commit 57272f84b1
3 changed files with 28 additions and 10 deletions
+18
View File
@@ -21,6 +21,9 @@ import {
} from './gcp-exporters.js';
import { TelemetryTarget } from './index.js';
import * as os from 'node:os';
import * as path from 'node:path';
vi.mock('@opentelemetry/exporter-trace-otlp-grpc');
vi.mock('@opentelemetry/exporter-logs-otlp-grpc');
vi.mock('@opentelemetry/exporter-metrics-otlp-grpc');
@@ -218,4 +221,19 @@ describe('Telemetry SDK', () => {
}
}
});
it('should not use OTLP exporters when telemetryOutfile is set', () => {
vi.spyOn(mockConfig, 'getTelemetryOutfile').mockReturnValue(
path.join(os.tmpdir(), 'test.log'),
);
initializeTelemetry(mockConfig);
expect(OTLPTraceExporter).not.toHaveBeenCalled();
expect(OTLPLogExporter).not.toHaveBeenCalled();
expect(OTLPMetricExporter).not.toHaveBeenCalled();
expect(OTLPTraceExporterHttp).not.toHaveBeenCalled();
expect(OTLPLogExporterHttp).not.toHaveBeenCalled();
expect(OTLPMetricExporterHttp).not.toHaveBeenCalled();
expect(NodeSDK.prototype.start).toHaveBeenCalled();
});
});
+1 -1
View File
@@ -95,8 +95,8 @@ export function initializeTelemetry(config: Config): void {
const telemetryTarget = config.getTelemetryTarget();
const useCollector = config.getTelemetryUseCollector();
const parsedEndpoint = parseOtlpEndpoint(otlpEndpoint, otlpProtocol);
const useOtlp = !!parsedEndpoint;
const telemetryOutfile = config.getTelemetryOutfile();
const useOtlp = !!parsedEndpoint && !telemetryOutfile;
const gcpProjectId =
process.env['OTLP_GOOGLE_CLOUD_PROJECT'] ||