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

feat(telemetry): improve tracking for docs chatbot VSCODE-660 #900

Merged
merged 60 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
86d25b7
WIP
gagik Nov 21, 2024
6feac32
add query codelens and shorten wording
gagik Nov 22, 2024
b1adb2a
Merge branch 'main' of github.com:mongodb-js/vscode into gagik/query-…
gagik Nov 22, 2024
474beb3
revert vscode change
gagik Nov 22, 2024
e915b3f
wording change
gagik Nov 22, 2024
e17008f
Add icons to connect to MongoDB
gagik Nov 25, 2024
27f0aad
Fix tests
gagik Nov 25, 2024
a8bcf84
Merge branch 'main' of github.com:mongodb-js/vscode into gagik/query-…
gagik Nov 25, 2024
bce4de9
check for copilot extension, not chat
gagik Nov 25, 2024
99128f5
Add namespacing
gagik Nov 26, 2024
b7f9618
add codelens telemetry
gagik Nov 27, 2024
245121f
WIP demo icons
gagik Nov 27, 2024
a9c2836
Update src/editors/queryWithCopilotCodeLensProvider.ts
gagik Nov 27, 2024
d4c9d6d
WIP
gagik Nov 28, 2024
b0ca543
use DocumentSource
gagik Nov 28, 2024
c870786
use document source
gagik Nov 28, 2024
145af8d
use sendMessage in extensionController
gagik Nov 28, 2024
692dc1c
change srv text
gagik Nov 28, 2024
fb02705
Merge branch 'gagik/query-codelens' of github.com:mongodb-js/vscode i…
gagik Nov 28, 2024
1d1f0a3
Merge branch 'gagik/query-codelens' of github.com:mongodb-js/vscode i…
gagik Nov 28, 2024
f827164
Merge branch 'gagik/add-icons' of github.com:mongodb-js/vscode into g…
gagik Nov 28, 2024
3e8bd0e
WIP
gagik Nov 28, 2024
2b079ce
Merge branch 'main' of github.com:mongodb-js/vscode into gagik/add-pl…
gagik Nov 28, 2024
f22248f
move to participant
gagik Nov 28, 2024
44a7eea
remove test related changes
gagik Nov 28, 2024
68c4482
remove more test code
gagik Nov 29, 2024
efb1432
fix test
gagik Nov 29, 2024
93fb8f8
add tests
gagik Nov 29, 2024
aeee828
only range
gagik Nov 29, 2024
a1f262a
refactor telemetry to standardize data structure
gagik Nov 29, 2024
a349f94
fix tests
gagik Nov 29, 2024
42c810a
add metadata to tests
gagik Nov 29, 2024
476dcd4
rename to telemetry
gagik Nov 29, 2024
9ba8092
adjust test
gagik Nov 29, 2024
6c37d5f
rename submitted
gagik Nov 29, 2024
14e36e2
use Promise<void>
gagik Dec 2, 2024
68255cf
use satisfies
gagik Dec 2, 2024
f30c1f4
use Promise<void>
gagik Dec 2, 2024
e7a1d08
Apply changes from feedback
gagik Dec 3, 2024
8c9347e
remove playground shortcut
gagik Dec 3, 2024
7fa46fe
use new database name
gagik Dec 3, 2024
4a6df5a
Remove redundant changes
gagik Dec 3, 2024
09c68ee
changes from feedback
gagik Dec 4, 2024
9c9ffc0
expect one call
gagik Dec 4, 2024
9d2ae41
Merge branch 'gagik/add-playground-buttons' of github.com:mongodb-js/…
gagik Dec 4, 2024
5f0cdca
fix args check
gagik Dec 4, 2024
11cf234
fix tests
gagik Dec 4, 2024
ac7a3b5
Merge branch 'gagik/add-playground-buttons' of github.com:mongodb-js/…
gagik Dec 5, 2024
fc2a8bc
feat(copilot): optimize namespace for export to playground VSCODE-654…
alenakhineika Dec 3, 2024
ca177f5
chore: add automatic font generation and fix VSCode settings (#893)
gagik Dec 3, 2024
7a9b075
fix(playground): hide playground export menu item if GitHub Copilot i…
gagik Dec 4, 2024
c8d9fc6
add submission to the tracking
gagik Dec 5, 2024
06f1119
track first test
gagik Dec 6, 2024
647ced6
fix test
gagik Dec 6, 2024
e4922b2
Merge branch 'main' of github.com:mongodb-js/vscode into gagik/add-te…
gagik Dec 6, 2024
32a4c52
assert stricter
gagik Dec 6, 2024
081be7c
skip length check for docs
gagik Dec 6, 2024
34b10d2
Merge branch 'gagik/add-telemetry-to-tree-view-buttons' into gagik/be…
gagik Dec 6, 2024
4cb1227
Merge branch 'main' of github.com:mongodb-js/vscode into gagik/better…
gagik Dec 9, 2024
57eaebe
fix tests
gagik Dec 9, 2024
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
11 changes: 1 addition & 10 deletions src/participant/constants.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import type * as vscode from 'vscode';
import { ChatMetadataStore } from './chatMetadata';
import type { ParticipantResponseType } from './participantTypes';

export const CHAT_PARTICIPANT_ID = 'mongodb.participant';
export const CHAT_PARTICIPANT_MODEL = 'gpt-4o';
export const COPILOT_EXTENSION_ID = 'GitHub.copilot';
export const COPILOT_CHAT_EXTENSION_ID = 'GitHub.copilot-chat';

export type ParticipantResponseType =
| 'query'
| 'schema'
| 'docs'
| 'generic'
| 'emptyRequest'
| 'cancelledRequest'
| 'askToConnect'
| 'askForNamespace';

export const codeBlockIdentifier = {
start: '```javascript',
end: '```',
Expand Down
11 changes: 8 additions & 3 deletions src/participant/participant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1540,22 +1540,23 @@ export default class ParticipantController {
}

async _handleDocsRequestWithChatbot({
prompt,
request,
chatId,
token,
stream,
context,
}: {
prompt: string;
chatId: string;
token: vscode.CancellationToken;
context: vscode.ChatContext;
request: vscode.ChatRequest;
stream: vscode.ChatResponseStream;
}): Promise<{
responseContent: string;
responseReferences?: Reference[];
docsChatbotMessageId: string;
}> {
const prompt = request.prompt;
stream.push(
new vscode.ChatResponseProgressPart('Consulting MongoDB documentation...')
);
Expand Down Expand Up @@ -1597,6 +1598,10 @@ export default class ParticipantController {
signal: abortController.signal,
});

const stats = Prompts.docs.getStats(history, { request, context });

this._telemetryService.trackParticipantPrompt(stats);

log.info('Docs chatbot message sent', {
chatId,
docsChatbotConversationId,
Expand Down Expand Up @@ -1694,7 +1699,7 @@ export default class ParticipantController {

try {
docsResult = await this._handleDocsRequestWithChatbot({
prompt: request.prompt,
request,
chatId,
token,
stream,
Expand Down
17 changes: 17 additions & 0 deletions src/participant/prompts/docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { ParticipantPromptProperties } from '../../telemetry/telemetryService';
import type { PromptArgsBase } from './promptBase';
import { PromptBase } from './promptBase';
import type * as vscode from 'vscode';

export class DocsPrompt extends PromptBase<PromptArgsBase> {
protected getAssistantPrompt(): string {
throw new Error('Method not implemented.');
}

public getStats(
messages: vscode.LanguageModelChatMessage[],
{ request, context }: PromptArgsBase
): ParticipantPromptProperties {
return super.getStats(messages, { request, context }, false);
}
}
2 changes: 2 additions & 0 deletions src/participant/prompts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { SchemaPrompt } from './schema';
import { ExportToPlaygroundPrompt } from './exportToPlayground';
import { ExportToLanguagePrompt } from './exportToLanguage';
import { isContentEmpty } from './promptBase';
import { DocsPrompt } from './docs';

export { getContentLength } from './promptBase';

export class Prompts {
public static generic = new GenericPrompt();
public static docs = new DocsPrompt();
public static intent = new IntentPrompt();
public static namespace = new NamespacePrompt();
public static query = new QueryPrompt();
Expand Down
26 changes: 19 additions & 7 deletions src/test/suite/participant/participant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import {
import EditDocumentCodeLensProvider from '../../../editors/editDocumentCodeLensProvider';
import PlaygroundResultProvider from '../../../editors/playgroundResultProvider';
import { CollectionTreeItem, DatabaseTreeItem } from '../../../explorer';
import type { SendMessageToParticipantOptions } from '../../../participant/participantTypes';
import type {
ParticipantRequestType,
SendMessageToParticipantOptions,
} from '../../../participant/participantTypes';
import { DocumentSource } from '../../../documentSource';

// The Copilot's model in not available in tests,
Expand Down Expand Up @@ -121,7 +124,7 @@ suite('Participant Controller Test Suite', function () {
);

const assertCommandTelemetry = (
command: string,
command: ParticipantRequestType,
chatRequest: vscode.ChatRequest,
{
expectSampleDocs = false,
Expand All @@ -144,10 +147,13 @@ suite('Participant Controller Test Suite', function () {
expect(properties.has_sample_documents).to.equal(expectSampleDocs);
expect(properties.history_size).to.equal(chatContextStub.history.length);

// Total message length includes participant as well as user prompt
expect(properties.total_message_length).to.be.greaterThan(
properties.user_input_length
);
/** For docs chatbot requests, the length of the prompt would be longer as it gets the prompt history prepended.*/
if (command !== 'docs') {
// Total message length includes participant as well as user prompt
expect(properties.total_message_length).to.be.greaterThan(
properties.user_input_length
);
}

// User prompt length should be at least equal to the supplied user prompt, but my occasionally
// be greater - e.g. when we enhance the context.
Expand Down Expand Up @@ -1660,8 +1666,14 @@ Schema:
expect(fetchStub).to.have.been.called;
expect(sendRequestStub).to.have.not.been.called;

assertResponseTelemetry('docs/chatbot', {
assertCommandTelemetry('docs', chatRequestMock, {
expectSampleDocs: false,
callIndex: 0,
expectedInternalPurpose: undefined,
});

assertResponseTelemetry('docs/chatbot', {
callIndex: 1,
});
});

Expand Down
Loading