Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding agentVersion clientPlatform to OpenTelemetryService #6436

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -8,6 +8,7 @@ import {
FeatureFlag,
type ResolvedConfiguration,
type Unsubscribable,
clientCapabilities,
combineLatest,
featureFlagProvider,
resolvedConfig,
Expand Down Expand Up @@ -72,14 +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: clientCapabilities().agentIDE,
agentVersion: clientCapabilities().agentExtensionVersion,
})
)
)
Expand Down
Loading