Skip to content

Commit

Permalink
Adding agent version client Platform to OpenTelemetryService
Browse files Browse the repository at this point in the history
  • Loading branch information
arafatkatze committed Dec 21, 2024
1 parent 7e359e3 commit b48ac6d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion vscode/src/services/open-telemetry/CodyTraceExport.ts
Original file line number Diff line number Diff line change
@@ -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<string, { span: ReadableSpan; enqueuedAt: number }> = 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 },
Expand All @@ -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 {
Expand All @@ -44,6 +57,8 @@ export class CodyTraceExporter extends OTLPTraceExporter {
const spanMap = new Map<string, ReadableSpan>()
for (const span of spans) {
spanMap.set(span.spanContext().spanId, span)
span.attributes.clientPlatform = this.clientPlatform
span.attributes.agentVersion = this.agentVersion
}

const spansToExport: ReadableSpan[] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -80,6 +81,8 @@ export class OpenTelemetryService {
traceUrl,
isTracingEnabled: this.isTracingEnabled,
accessToken: auth.accessToken,
clientPlatform: configuration.agentIDE ?? ('defaultIDE' as CodyIDE),
agentVersion: configuration.agentExtensionVersion,
})
)
)
Expand Down

0 comments on commit b48ac6d

Please sign in to comment.