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 Distributed Tracing and Smart Apply to cody #6178

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
83 changes: 53 additions & 30 deletions vscode/src/chat/chat-view/ChatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ import { getChatPanelTitle } from './chat-helpers'
import { type HumanInput, getPriorityContext } from './context'
import { DefaultPrompter, type PromptInfo } from './prompt'
import { getPromptsMigrationInfo, startPromptsMigration } from './prompts-migration'
const { context, propagation, ROOT_CONTEXT } = require('@opentelemetry/api')

export interface ChatControllerOptions {
extensionUri: vscode.Uri
Expand Down Expand Up @@ -281,6 +282,8 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
this.setWebviewToChat()
break
case 'submit': {
const traceparent = message.traceparent

await this.handleUserMessageSubmission({
requestID: uuid.v4(),
inputText: PromptString.unsafe_fromUserQuery(message.text),
Expand All @@ -291,6 +294,7 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
intent: message.intent,
intentScores: message.intentScores,
manuallySelectedIntent: message.manuallySelectedIntent,
traceparent,
})
break
}
Expand Down Expand Up @@ -322,7 +326,8 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
message.code,
currentAuthStatus(),
message.instruction,
message.fileName
message.fileName,
message.traceparent
)
break
case 'trace-export':
Expand Down Expand Up @@ -620,6 +625,7 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
intent: detectedIntent,
intentScores: detectedIntentScores,
manuallySelectedIntent,
traceparent,
}: {
requestID: string
inputText: PromptString
Expand All @@ -631,41 +637,58 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
intent?: ChatMessage['intent'] | undefined | null
intentScores?: { intent: string; score: number }[] | undefined | null
manuallySelectedIntent?: boolean | undefined | null
traceparent?: string | undefined | null
}): Promise<void> {
return tracer.startActiveSpan('chat.submit', async (span): Promise<void> => {
span.setAttribute('sampled', true)
const carrier = {
traceparent: traceparent,
} as Record<string, any>
const getter = {
get(carrier: Record<string, any>, key: string) {
return carrier[key]
},
keys(carrier: Record<string, any>) {
return Object.keys(carrier)
},
}

if (inputText.toString().match(/^\/reset$/)) {
span.addEvent('clearAndRestartSession')
span.end()
return this.clearAndRestartSession()
}
const extractedContext = propagation.extract(ROOT_CONTEXT, carrier, getter)

this.chatBuilder.addHumanMessage({
text: inputText,
editorState,
intent: detectedIntent,
})
this.postViewTranscript({ speaker: 'assistant' })

await this.saveSession()
signal.throwIfAborted()
return context.with(extractedContext, () => {
Copy link
Contributor Author

@arafatkatze arafatkatze Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding distributed tracing in chat so now the trace looks like

image

This has both UX and extension host stuff together. See related comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tracer.startActiveSpan('chat.submit', async (span): Promise<void> => {
span.setAttribute('sampled', true)
span.setAttribute('continued', true)
if (inputText.toString().match(/^\/reset$/)) {
span.addEvent('clearAndRestartSession')
span.end()
return this.clearAndRestartSession()
}

return this.sendChat(
{
requestID,
inputText,
mentions,
this.chatBuilder.addHumanMessage({
text: inputText,
editorState,
signal,
source,
command,
intent: detectedIntent,
intentScores: detectedIntentScores,
manuallySelectedIntent,
},
span
)
})
this.postViewTranscript({ speaker: 'assistant' })

await this.saveSession()
signal.throwIfAborted()

return this.sendChat(
{
requestID,
inputText,
mentions,
editorState,
signal,
source,
command,
intent: detectedIntent,
intentScores: detectedIntentScores,
manuallySelectedIntent,
},
span
)
})
})
}

Expand Down
2 changes: 2 additions & 0 deletions vscode/src/chat/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type WebviewMessage =
code: string
instruction?: string | undefined | null
fileName?: string | undefined | null
traceparent?: string | undefined | null
}
| {
command: 'trace-export'
Expand Down Expand Up @@ -206,6 +207,7 @@ export interface WebviewSubmitMessage extends WebviewContextMessage {
intent?: ChatMessage['intent'] | undefined | null
intentScores?: { intent: string; score: number }[] | undefined | null
manuallySelectedIntent?: boolean | undefined | null
traceparent?: string | undefined | null
}

interface WebviewEditMessage extends WebviewContextMessage {
Expand Down
Loading