From b48ac6da328158ec449fbea415e1d48616710ee8 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sat, 21 Dec 2024 11:49:45 +0400 Subject: [PATCH 1/2] Adding agent version client Platform to OpenTelemetryService --- .../services/open-telemetry/CodyTraceExport.ts | 17 ++++++++++++++++- .../open-telemetry/OpenTelemetryService.node.ts | 3 +++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/vscode/src/services/open-telemetry/CodyTraceExport.ts b/vscode/src/services/open-telemetry/CodyTraceExport.ts index b0e0d482daab..81c72550f965 100644 --- a/vscode/src/services/open-telemetry/CodyTraceExport.ts +++ b/vscode/src/services/open-telemetry/CodyTraceExport.ts @@ -1,18 +1,29 @@ import type { ExportResult } from '@opentelemetry/core' import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http' import type { ReadableSpan } from '@opentelemetry/sdk-trace-base' +import type { CodyIDE } from '@sourcegraph/cody-shared' const MAX_TRACE_RETAIN_MS = 60 * 1000 export class CodyTraceExporter extends OTLPTraceExporter { private isTracingEnabled = false private queuedSpans: Map = new Map() + private clientPlatform: CodyIDE + private agentVersion?: string constructor({ traceUrl, accessToken, isTracingEnabled, - }: { traceUrl: string; accessToken: string | null; isTracingEnabled: boolean }) { + clientPlatform, + agentVersion, + }: { + traceUrl: string + accessToken: string | null + isTracingEnabled: boolean + clientPlatform: CodyIDE + agentVersion?: string + }) { super({ url: traceUrl, httpAgentOptions: { rejectUnauthorized: false }, @@ -21,6 +32,8 @@ export class CodyTraceExporter extends OTLPTraceExporter { }, }) this.isTracingEnabled = isTracingEnabled + this.clientPlatform = clientPlatform + this.agentVersion = agentVersion } export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void { @@ -44,6 +57,8 @@ export class CodyTraceExporter extends OTLPTraceExporter { const spanMap = new Map() for (const span of spans) { spanMap.set(span.spanContext().spanId, span) + span.attributes.clientPlatform = this.clientPlatform + span.attributes.agentVersion = this.agentVersion } const spansToExport: ReadableSpan[] = [] diff --git a/vscode/src/services/open-telemetry/OpenTelemetryService.node.ts b/vscode/src/services/open-telemetry/OpenTelemetryService.node.ts index 49ba2d4ac170..ad6001472b17 100644 --- a/vscode/src/services/open-telemetry/OpenTelemetryService.node.ts +++ b/vscode/src/services/open-telemetry/OpenTelemetryService.node.ts @@ -5,6 +5,7 @@ import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node' import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions' import { + type CodyIDE, FeatureFlag, type ResolvedConfiguration, type Unsubscribable, @@ -80,6 +81,8 @@ export class OpenTelemetryService { traceUrl, isTracingEnabled: this.isTracingEnabled, accessToken: auth.accessToken, + clientPlatform: configuration.agentIDE ?? ('defaultIDE' as CodyIDE), + agentVersion: configuration.agentExtensionVersion, }) ) ) From 7b4229581017519775d29259d00b54f1a05f9137 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sun, 22 Dec 2024 13:50:11 +0400 Subject: [PATCH 2/2] Adding jetbrains test --- .../services/open-telemetry/OpenTelemetryService.node.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vscode/src/services/open-telemetry/OpenTelemetryService.node.ts b/vscode/src/services/open-telemetry/OpenTelemetryService.node.ts index ad6001472b17..1499aae5b43f 100644 --- a/vscode/src/services/open-telemetry/OpenTelemetryService.node.ts +++ b/vscode/src/services/open-telemetry/OpenTelemetryService.node.ts @@ -5,10 +5,10 @@ import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node' import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions' import { - type CodyIDE, FeatureFlag, type ResolvedConfiguration, type Unsubscribable, + clientCapabilities, combineLatest, featureFlagProvider, resolvedConfig, @@ -73,16 +73,16 @@ export class OpenTelemetryService { [SemanticResourceAttributes.SERVICE_VERSION]: version, }), }) - // Add the default tracer exporter used in production. + this.tracerProvider.addSpanProcessor( new BatchSpanProcessor( new CodyTraceExporter({ traceUrl, isTracingEnabled: this.isTracingEnabled, accessToken: auth.accessToken, - clientPlatform: configuration.agentIDE ?? ('defaultIDE' as CodyIDE), - agentVersion: configuration.agentExtensionVersion, + clientPlatform: clientCapabilities().agentIDE, + agentVersion: clientCapabilities().agentExtensionVersion, }) ) )