Skip to content

Commit de822c7

Browse files
authored
Implements github telemetry forwarding (#272)
1 parent 421854e commit de822c7

File tree

5 files changed

+68
-5
lines changed

5 files changed

+68
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"icon": "assets/copilot.png",
2323
"pricing": "Trial",
2424
"engines": {
25-
"vscode": "^1.103.0-insider",
25+
"vscode": "^1.103.0-20250717",
2626
"npm": ">=9.0.0",
2727
"node": ">=22.14.0"
2828
},
@@ -130,7 +130,8 @@
130130
"contribLanguageModelToolSets",
131131
"textDocumentChangeReason",
132132
"resolvers",
133-
"taskExecutionTerminal"
133+
"taskExecutionTerminal",
134+
"dataChannels"
134135
],
135136
"contributes": {
136137
"languageModelTools": [

src/extension/extension/vscode/contributions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { asContributionFactory, IExtensionContributionFactory } from '../../common/contributions';
7-
import { LifecycleTelemetryContrib } from '../../telemetry/common/lifecycleTelemetryContrib';
86
import { NesActivationTelemetryContribution } from '../../../platform/inlineEdits/common/nesActivationStatusTelemetry.contribution';
7+
import { asContributionFactory, IExtensionContributionFactory } from '../../common/contributions';
98
import * as contextContribution from '../../context/vscode/context.contribution';
9+
import { LifecycleTelemetryContrib } from '../../telemetry/common/lifecycleTelemetryContrib';
10+
import { GithubTelemetryForwardingContrib } from '../../telemetry/vscode/githubTelemetryForwardingContrib';
1011

1112
// ###############################################################################
1213
// ### ###
@@ -19,6 +20,7 @@ import * as contextContribution from '../../context/vscode/context.contribution'
1920
const vscodeContributions: IExtensionContributionFactory[] = [
2021
asContributionFactory(LifecycleTelemetryContrib),
2122
asContributionFactory(NesActivationTelemetryContribution),
23+
asContributionFactory(GithubTelemetryForwardingContrib),
2224
contextContribution,
2325
];
2426

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { env } from 'vscode';
7+
import { ITelemetryService } from '../../../platform/telemetry/common/telemetry';
8+
import { Disposable } from '../../../util/vs/base/common/lifecycle';
9+
import { IExtensionContribution } from '../../common/contributions';
10+
11+
export class GithubTelemetryForwardingContrib extends Disposable implements IExtensionContribution {
12+
constructor(
13+
@ITelemetryService private readonly _telemetryService: ITelemetryService,
14+
) {
15+
super();
16+
17+
const channel = env.getDataChannel<IEditTelemetryData>('editTelemetry');
18+
this._register(channel.onDidReceiveData((args) => {
19+
const { properties, measurements } = dataToPropsAndMeasurements(args.data.data);
20+
this._telemetryService.sendGHTelemetryEvent('vscode.' + args.data.eventName, properties, measurements);
21+
}));
22+
}
23+
}
24+
25+
function dataToPropsAndMeasurements(data: Record<string, unknown>): { properties: Record<string, string>; measurements: Record<string, number> } {
26+
const properties: Record<string, string> = {};
27+
const measurements: Record<string, number> = {};
28+
for (const [key, value] of Object.entries(data)) {
29+
if (typeof value === 'number') {
30+
measurements[key] = value;
31+
} else if (typeof value === 'string') {
32+
properties[key] = value;
33+
}
34+
}
35+
return { properties, measurements };
36+
}
37+
38+
interface IEditTelemetryData {
39+
eventName: string;
40+
data: Record<string, unknown>;
41+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
declare module 'vscode' {
7+
8+
export namespace env {
9+
export function getDataChannel<T>(channelId: string): DataChannel<T>;
10+
}
11+
12+
export interface DataChannel<T = unknown> {
13+
onDidReceiveData: Event<DataChannelEvent<T>>;
14+
}
15+
16+
export interface DataChannelEvent<T> {
17+
data: T;
18+
}
19+
}

0 commit comments

Comments
 (0)