Skip to content

Commit

Permalink
Fixing repetivie calls to span expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
arafatkatze committed Nov 20, 2024
1 parent 0de24aa commit d46b975
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 16 additions & 7 deletions vscode/src/services/open-telemetry/CodyTraceExportWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export class CodyTraceExporterWeb extends OTLPTraceExporter {
private queuedSpans: Map<string, { span: ReadableSpan; enqueuedAt: number }> = new Map()
private agentIDE: CodyIDE
private extensionAgentVersion?: string
private lastExpiryCheck: number = 0;

constructor({
isTracingEnabled,
agentIDE,
Expand All @@ -31,18 +33,25 @@ export class CodyTraceExporterWeb extends OTLPTraceExporter {
this.extensionAgentVersion = extensionAgentVersion
}

export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {
if (!this.isTracingEnabled) {
return
}

const now = Date.now()
private removeExpiredSpans(now: number): void {
for (const [spanId, { enqueuedAt }] of this.queuedSpans.entries()) {
if (now - enqueuedAt > MAX_TRACE_RETAIN_MS) {
this.queuedSpans.delete(spanId)
logDebug('[CodyTraceExporterWeb] Removed expired span from queue:', spanId)
}
}
}

export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {
if (!this.isTracingEnabled) {
return
}

const now = performance.now()
if (now - this.lastExpiryCheck > MAX_TRACE_RETAIN_MS) {
this.removeExpiredSpans(now)
this.lastExpiryCheck = now
}

// Include queued spans for re-evaluation
const allSpans = [...spans, ...Array.from(this.queuedSpans.values()).map(q => q.span)]
Expand Down Expand Up @@ -140,7 +149,7 @@ export class CodyTraceExporterWeb extends OTLPTraceExporter {
})) ?? [],
},
})),
timestamp: Date.now(),
timestamp: performance.now(),
}

// Send the validated and cleaned data
Expand Down
1 change: 0 additions & 1 deletion vscode/webviews/chat/Transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
const spanManager = new SpanManager('cody-webview')
const renderSpan = useRef<Span>()
const timeToFirstTokenSpan = useRef<Span>()
const renderStartTime = useRef<number>()
const hasRecordedFirstToken = useRef(false)

// State to track loading status
Expand Down

0 comments on commit d46b975

Please sign in to comment.