diff options
| author | Jerop Kipruto <[email protected]> | 2025-06-05 16:04:25 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-05 13:04:25 -0700 |
| commit | 2ebf2fbc82ba998f0369f17b56f99d0b25680cb4 (patch) | |
| tree | f2cfb0991e4781f99618d5b2fbff607f52aead81 /packages/core/src/config | |
| parent | d3e43437a00cfe64790cc60c9c8aa82c85f520c3 (diff) | |
OpenTelemetry Integration & Telemetry Control Flag (#762)
Diffstat (limited to 'packages/core/src/config')
| -rw-r--r-- | packages/core/src/config/config.test.ts | 52 | ||||
| -rw-r--r-- | packages/core/src/config/config.ts | 27 |
2 files changed, 79 insertions, 0 deletions
diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts index 85ec9541..9cacdbbb 100644 --- a/packages/core/src/config/config.test.ts +++ b/packages/core/src/config/config.test.ts @@ -48,6 +48,7 @@ describe('Server Config (config.ts)', () => { const FULL_CONTEXT = false; const USER_AGENT = 'ServerTestAgent/1.0'; const USER_MEMORY = 'Test User Memory'; + const TELEMETRY = false; const baseParams: ConfigParameters = { apiKey: API_KEY, model: MODEL, @@ -58,6 +59,7 @@ describe('Server Config (config.ts)', () => { fullContext: FULL_CONTEXT, userAgent: USER_AGENT, userMemory: USER_MEMORY, + telemetry: TELEMETRY, }; beforeEach(() => { @@ -161,6 +163,56 @@ describe('Server Config (config.ts)', () => { expect(config.getFileFilteringAllowBuildArtifacts()).toBe(true); }); + it('Config constructor should set telemetry to true when provided as true', () => { + const paramsWithTelemetry: ConfigParameters = { + ...baseParams, + telemetry: true, + }; + const config = new Config(paramsWithTelemetry); + expect(config.getTelemetryEnabled()).toBe(true); + }); + + it('Config constructor should set telemetry to false when provided as false', () => { + const paramsWithTelemetry: ConfigParameters = { + ...baseParams, + telemetry: false, + }; + const config = new Config(paramsWithTelemetry); + expect(config.getTelemetryEnabled()).toBe(false); + }); + + it('Config constructor should default telemetry to default value if not provided', () => { + const paramsWithoutTelemetry: ConfigParameters = { ...baseParams }; + delete paramsWithoutTelemetry.telemetry; + const config = new Config(paramsWithoutTelemetry); + expect(config.getTelemetryEnabled()).toBe(TELEMETRY); + }); + + it('createServerConfig should pass telemetry to Config constructor when true', () => { + const paramsWithTelemetry: ConfigParameters = { + ...baseParams, + telemetry: true, + }; + const config = createServerConfig(paramsWithTelemetry); + expect(config.getTelemetryEnabled()).toBe(true); + }); + + it('createServerConfig should pass telemetry to Config constructor when false', () => { + const paramsWithTelemetry: ConfigParameters = { + ...baseParams, + telemetry: false, + }; + const config = createServerConfig(paramsWithTelemetry); + expect(config.getTelemetryEnabled()).toBe(false); + }); + + it('createServerConfig should default telemetry (to false via Config constructor) if omitted', () => { + const paramsWithoutTelemetry: ConfigParameters = { ...baseParams }; + delete paramsWithoutTelemetry.telemetry; + const config = createServerConfig(paramsWithoutTelemetry); + expect(config.getTelemetryEnabled()).toBe(TELEMETRY); + }); + it('should have a getFileService method that returns FileDiscoveryService', async () => { const config = new Config(baseParams); const fileService = await config.getFileService(); diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 92a929cc..bd744093 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -24,6 +24,7 @@ import { WebSearchTool } from '../tools/web-search.js'; import { GeminiClient } from '../core/client.js'; import { GEMINI_CONFIG_DIR as GEMINI_DIR } from '../tools/memoryTool.js'; import { FileDiscoveryService } from '../services/fileDiscoveryService.js'; +import { initializeTelemetry } from '../telemetry/index.js'; export enum ApprovalMode { DEFAULT = 'default', @@ -72,6 +73,8 @@ export interface ConfigParameters { contextFileName?: string; geminiIgnorePatterns?: string[]; accessibility?: AccessibilitySettings; + telemetry?: boolean; + telemetryLogUserPromptsEnabled?: boolean; fileFilteringRespectGitIgnore?: boolean; fileFilteringAllowBuildArtifacts?: boolean; } @@ -97,6 +100,9 @@ export class Config { private readonly vertexai: boolean | undefined; private readonly showMemoryUsage: boolean; private readonly accessibility: AccessibilitySettings; + private readonly telemetry: boolean; + private readonly telemetryLogUserPromptsEnabled: boolean; + private readonly telemetryOtlpEndpoint: string; private readonly geminiClient: GeminiClient; private readonly geminiIgnorePatterns: string[] = []; private readonly fileFilteringRespectGitIgnore: boolean; @@ -123,6 +129,11 @@ export class Config { this.vertexai = params.vertexai; this.showMemoryUsage = params.showMemoryUsage ?? false; this.accessibility = params.accessibility ?? {}; + this.telemetry = params.telemetry ?? false; + this.telemetryLogUserPromptsEnabled = + params.telemetryLogUserPromptsEnabled ?? true; + this.telemetryOtlpEndpoint = + process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? 'http://localhost:4317'; this.fileFilteringRespectGitIgnore = params.fileFilteringRespectGitIgnore ?? true; this.fileFilteringAllowBuildArtifacts = @@ -137,6 +148,10 @@ export class Config { this.toolRegistry = createToolRegistry(this); this.geminiClient = new GeminiClient(this); + + if (this.telemetry) { + initializeTelemetry(this); + } } getApiKey(): string { @@ -230,6 +245,18 @@ export class Config { return this.accessibility; } + getTelemetryEnabled(): boolean { + return this.telemetry; + } + + getTelemetryLogUserPromptsEnabled(): boolean { + return this.telemetryLogUserPromptsEnabled; + } + + getTelemetryOtlpEndpoint(): string { + return this.telemetryOtlpEndpoint; + } + getGeminiClient(): GeminiClient { return this.geminiClient; } |
