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

Merged
merged 7 commits into from
Dec 5, 2024
Merged

Conversation

arafatkatze
Copy link
Contributor

@arafatkatze arafatkatze commented Nov 22, 2024

This PR introduces distributed tracing to connect traces originating in the UX with those starting in the extension host. This ensures unified and all-encompassing traces for operations spanning both the web view and the extension host.

NOTE: this PR has been rebased to the main and is ready for review

Changes Made

  1. Distributed Tracing for Chat Interaction: Traces starting in the UX are now connected to corresponding traces in the extension host for chat interactions.
  2. Distributed Tracing for Smart Apply: Similarly, traces for Smart Apply now span both the UX and the extension host.

These changes are in alignment with the milestone goals and aim to deliver foundational support for distributed tracing in these areas.

Next Steps

  • Immediate Goal: Ensure distributed tracing is functional and provides value for chat interaction and Smart Apply use cases.
  • I will rebase the PR and resolve merge conflicts AFTER the proper merge of Integrate OpenTelemetry tracing in Cody Webview #6100 it was reverted last time because of some issues
  • Follow-Up Work for next PR:
  • Refactor naming conventions for better consistency.
  • Eliminate redundant metric names.

Test plan

  • Run sourcegraph instance locally
  • Run sg start otel
  • Run the debugger for vscode cody locally on this branch
  • Perform some chat operations
  • Go to http://localhost:16686 to see if Jaegar is running
  • Select Cody-Client as the service
  • See a trace with the title chat-interaction this is a collection of spans that show a single trace for spans from both webview and extension host
image

Changelog

@arafatkatze arafatkatze changed the title Dist tracing Adding Distributed Tracing and Smart Apply to cody Nov 25, 2024

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.

Copy link

github-actions bot commented Dec 2, 2024

‼️ Hey @sourcegraph/cody-security, please review this PR carefully as it introduces the usage of an unsafe_ function or abuses PromptString.

@arafatkatze
Copy link
Contributor Author

arafatkatze commented Dec 2, 2024

image Initially, I encountered a strange race condition where the traces didn’t always “link up” as they should, which meant some traces weren’t visible in the expected order. You can see the traces with Handleusermessage as the title and they are from the Cody extension host alone whereas the traces with chat-interaction as the title are the "full traces".

However, the issue resolved itself over time—I just had to wait.

The underlying problem stemmed from the way buffering happens differently on the Cody client side versus the webview side. Occasionally, the trace from the webview would arrive first, while other times the trace from the extension host would arrive first. This discrepancy in buffering cadence caused the traces to appear mismatched initially.

Eventually, Jaeger’s trace-linking mechanism kicks in and aligns all the traces correctly in the user interface. After some time, you end up with a properly linked view, like this:
image

@arafatkatze arafatkatze marked this pull request as ready for review December 3, 2024 06:38
if (rootSpan === null) {
// the child of the root is sampled but root is not and the span is continued
const rootChildSpan = getRootChildSpan(spanMap, span)
if (rootChildSpan && isSampled(rootChildSpan) && isContinued(rootChildSpan)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The naming conventions in this part could use some improvement because the logic I’m applying here is essential for linking the traces where the root is actually located in the webview. The key idea is that if the root isn’t present in the traces here, I want to measure the child of the root (the trace located in the extension host) and then send that one, as it effectively serves as the ‘root’ in this context. Hopefully, that clarifies things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@dominiccooney dominiccooney left a comment

Choose a reason for hiding this comment

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

Some feedback inline.

It is GREAT that we're joining traces across these domains.

vscode/src/chat/chat-view/ChatController.ts Outdated Show resolved Hide resolved
vscode/src/edit/manager.ts Outdated Show resolved Hide resolved
vscode/src/edit/provider.ts Outdated Show resolved Hide resolved
vscode/src/edit/provider.ts Outdated Show resolved Hide resolved
vscode/src/edit/provider.ts Outdated Show resolved Hide resolved
vscode/src/services/open-telemetry/CodyTraceExport.ts Outdated Show resolved Hide resolved
vscode/src/services/open-telemetry/CodyTraceExport.ts Outdated Show resolved Hide resolved
vscode/src/services/open-telemetry/CodyTraceExport.ts Outdated Show resolved Hide resolved
vscode/src/services/open-telemetry/CodyTraceExport.ts Outdated Show resolved Hide resolved
vscode/webviews/Chat.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@dominiccooney dominiccooney left a comment

Choose a reason for hiding this comment

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

Looks good, nice cleanup.

Can you remove the questions and concerns from the PR description? (If you still have questions and concerns, let's go through those.)

lib/shared/src/prompt/prompt-string.ts Show resolved Hide resolved
@arafatkatze arafatkatze enabled auto-merge (squash) December 5, 2024 01:56
@arafatkatze
Copy link
Contributor Author

Can you remove the questions and concerns from the PR description? (If you still have questions and concerns, let's go through those.)

Removed

@arafatkatze arafatkatze merged commit 5686699 into main Dec 5, 2024
17 of 20 checks passed
@arafatkatze arafatkatze deleted the dist-tracing branch December 5, 2024 02:02
dominiccooney added a commit that referenced this pull request Dec 6, 2024
dominiccooney added a commit that referenced this pull request Dec 6, 2024
This reverts commits 5686699 and
6bf801b. They cause stdout logspam.

## Test plan

CI

## Changelog

- fix/edits: Distributed tracing of webview and Smart Apply, recently
added, is reverted.
dominiccooney added a commit that referenced this pull request Dec 6, 2024
This reverts commits 5686699 and
6bf801b. They cause stdout logspam.

## Test plan

CI

## Changelog

- fix/edits: Distributed tracing of webview and Smart Apply, recently
added, is reverted.
arafatkatze added a commit that referenced this pull request Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants