mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
fix(telemetry): disable OTLP when telemetry-outfile is set (#9117)
This commit is contained in:
+2
-2
@@ -52,12 +52,12 @@ All telemetry behavior is controlled through your `.gemini/settings.json` file
|
|||||||
and can be overridden with CLI flags:
|
and can be overridden with CLI flags:
|
||||||
|
|
||||||
| Setting | Values | Default | CLI Override | Description |
|
| Setting | Values | Default | CLI Override | Description |
|
||||||
| -------------- | ----------------- | ----------------------- | -------------------------------------------------------- | ---------------------------------------------------- |
|
| -------------- | ----------------- | ----------------------- | -------------------------------------------------------- | ------------------------------------------------- |
|
||||||
| `enabled` | `true`/`false` | `false` | `--telemetry` / `--no-telemetry` | Enable or disable telemetry |
|
| `enabled` | `true`/`false` | `false` | `--telemetry` / `--no-telemetry` | Enable or disable telemetry |
|
||||||
| `target` | `"gcp"`/`"local"` | `"local"` | `--telemetry-target <local\|gcp>` | Where to send telemetry data |
|
| `target` | `"gcp"`/`"local"` | `"local"` | `--telemetry-target <local\|gcp>` | Where to send telemetry data |
|
||||||
| `otlpEndpoint` | URL string | `http://localhost:4317` | `--telemetry-otlp-endpoint <URL>` | OTLP collector endpoint |
|
| `otlpEndpoint` | URL string | `http://localhost:4317` | `--telemetry-otlp-endpoint <URL>` | OTLP collector endpoint |
|
||||||
| `otlpProtocol` | `"grpc"`/`"http"` | `"grpc"` | `--telemetry-otlp-protocol <grpc\|http>` | OTLP transport protocol |
|
| `otlpProtocol` | `"grpc"`/`"http"` | `"grpc"` | `--telemetry-otlp-protocol <grpc\|http>` | OTLP transport protocol |
|
||||||
| `outfile` | file path | - | `--telemetry-outfile <path>` | Save telemetry to file (requires `otlpEndpoint: ""`) |
|
| `outfile` | file path | - | `--telemetry-outfile <path>` | Save telemetry to file (overrides `otlpEndpoint`) |
|
||||||
| `logPrompts` | `true`/`false` | `true` | `--telemetry-log-prompts` / `--no-telemetry-log-prompts` | Include prompts in telemetry logs |
|
| `logPrompts` | `true`/`false` | `true` | `--telemetry-log-prompts` / `--no-telemetry-log-prompts` | Include prompts in telemetry logs |
|
||||||
| `useCollector` | `true`/`false` | `false` | - | Use external OTLP collector (advanced) |
|
| `useCollector` | `true`/`false` | `false` | - | Use external OTLP collector (advanced) |
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ import {
|
|||||||
} from './gcp-exporters.js';
|
} from './gcp-exporters.js';
|
||||||
import { TelemetryTarget } from './index.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-trace-otlp-grpc');
|
||||||
vi.mock('@opentelemetry/exporter-logs-otlp-grpc');
|
vi.mock('@opentelemetry/exporter-logs-otlp-grpc');
|
||||||
vi.mock('@opentelemetry/exporter-metrics-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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -95,8 +95,8 @@ export function initializeTelemetry(config: Config): void {
|
|||||||
const telemetryTarget = config.getTelemetryTarget();
|
const telemetryTarget = config.getTelemetryTarget();
|
||||||
const useCollector = config.getTelemetryUseCollector();
|
const useCollector = config.getTelemetryUseCollector();
|
||||||
const parsedEndpoint = parseOtlpEndpoint(otlpEndpoint, otlpProtocol);
|
const parsedEndpoint = parseOtlpEndpoint(otlpEndpoint, otlpProtocol);
|
||||||
const useOtlp = !!parsedEndpoint;
|
|
||||||
const telemetryOutfile = config.getTelemetryOutfile();
|
const telemetryOutfile = config.getTelemetryOutfile();
|
||||||
|
const useOtlp = !!parsedEndpoint && !telemetryOutfile;
|
||||||
|
|
||||||
const gcpProjectId =
|
const gcpProjectId =
|
||||||
process.env['OTLP_GOOGLE_CLOUD_PROJECT'] ||
|
process.env['OTLP_GOOGLE_CLOUD_PROJECT'] ||
|
||||||
|
|||||||
Reference in New Issue
Block a user