Add support for HTTP OpenTelemetry exporters (#6357)

This commit is contained in:
Billy Biggs
2025-08-15 18:10:21 -07:00
committed by GitHub
parent 4896c7739f
commit d57cc0b930
10 changed files with 301 additions and 34 deletions

View File

@@ -536,6 +536,60 @@ describe('loadCliConfig telemetry', () => {
const config = await loadCliConfig(settings, [], 'test-session', argv);
expect(config.getTelemetryLogPromptsEnabled()).toBe(true);
});
it('should use telemetry OTLP protocol from settings if CLI flag is not present', async () => {
process.argv = ['node', 'script.js'];
const argv = await parseArguments();
const settings: Settings = {
telemetry: { otlpProtocol: 'http' },
};
const config = await loadCliConfig(settings, [], 'test-session', argv);
expect(config.getTelemetryOtlpProtocol()).toBe('http');
});
it('should prioritize --telemetry-otlp-protocol CLI flag over settings', async () => {
process.argv = ['node', 'script.js', '--telemetry-otlp-protocol', 'http'];
const argv = await parseArguments();
const settings: Settings = {
telemetry: { otlpProtocol: 'grpc' },
};
const config = await loadCliConfig(settings, [], 'test-session', argv);
expect(config.getTelemetryOtlpProtocol()).toBe('http');
});
it('should use default protocol if no OTLP protocol is provided via CLI or settings', async () => {
process.argv = ['node', 'script.js'];
const argv = await parseArguments();
const settings: Settings = { telemetry: { enabled: true } };
const config = await loadCliConfig(settings, [], 'test-session', argv);
expect(config.getTelemetryOtlpProtocol()).toBe('grpc');
});
it('should reject invalid --telemetry-otlp-protocol values', async () => {
process.argv = [
'node',
'script.js',
'--telemetry-otlp-protocol',
'invalid',
];
const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit called');
});
const mockConsoleError = vi
.spyOn(console, 'error')
.mockImplementation(() => {});
await expect(parseArguments()).rejects.toThrow('process.exit called');
expect(mockConsoleError).toHaveBeenCalledWith(
expect.stringContaining('Invalid values:'),
);
mockExit.mockRestore();
mockConsoleError.mockRestore();
});
});
describe('Hierarchical Memory Loading (config.ts) - Placeholder Suite', () => {

View File

@@ -64,6 +64,7 @@ export interface CliArgs {
checkpointing: boolean | undefined;
telemetryTarget: string | undefined;
telemetryOtlpEndpoint: string | undefined;
telemetryOtlpProtocol: string | undefined;
telemetryLogPrompts: boolean | undefined;
telemetryOutfile: string | undefined;
allowedMcpServerNames: string[] | undefined;
@@ -172,6 +173,12 @@ export async function parseArguments(): Promise<CliArgs> {
description:
'Set the OTLP endpoint for telemetry. Overrides environment variables and settings files.',
})
.option('telemetry-otlp-protocol', {
type: 'string',
choices: ['grpc', 'http'],
description:
'Set the OTLP protocol for telemetry (grpc or http). Overrides settings files.',
})
.option('telemetry-log-prompts', {
type: 'boolean',
description:
@@ -491,6 +498,11 @@ export async function loadCliConfig(
argv.telemetryOtlpEndpoint ??
process.env.OTEL_EXPORTER_OTLP_ENDPOINT ??
settings.telemetry?.otlpEndpoint,
otlpProtocol: (['grpc', 'http'] as const).find(
(p) =>
p ===
(argv.telemetryOtlpProtocol ?? settings.telemetry?.otlpProtocol),
),
logPrompts: argv.telemetryLogPrompts ?? settings.telemetry?.logPrompts,
outfile: argv.telemetryOutfile ?? settings.telemetry?.outfile,
},