agentHostMicrosoftTelemetry.ts ×7

Frontier kind: Code frontier

unlabeled · c_c4c68468e90a

688 tests · 8105 LOC · 47 files · introduces 0 tests · 127 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
18 ranges127 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1067 ranges8105 lines · 47 files · Browse complete extent
All tests (intent)
688 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

3 files ranked by introduced lines: 127 introduced LOC across 18 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/agentHostMicrosoftTelemetry.ts 47 introduced LOC · 7 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- agentHostMicrosoftTelemetry.ts
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 { Disposable, MutableDisposable, toDisposable } from '../../../base/common/lifecycle.js';
7 > import type { IRequestService } from '../../request/common/request.js';
8 > import type { ICommonProperties } from '../../telemetry/common/telemetry.js';
9 > import { OneDataSystemAppender } from '../../telemetry/node/1dsAppender.js';
10 > import type { IAgentHostInternalTelemetryContext, IAgentHostInternalTelemetrySink, TelemetryMeasurements, TelemetryProps } from './agentHostRestrictedTelemetry.js';
11 >
12 > // Public instrumentation key shipped as internalLargeStorageAriaKey in extensions/copilot/package.json.
13 > const INTERNAL_LARGE_STORAGE_ARIA_KEY = 'ec712b3202c5462fb6877acae7f1f9d7-c19ad55e-3e3c-4f99-984b-827f6d95bd9e-6917';
14 > const INTERNAL_EVENT_PREFIX = 'GitHub.copilot-chat';
15 > const INTERNAL_EXTENSION_ID = 'GitHub.copilot-chat';
16 >
17 > interface IInternalTelemetryAppender {
18 > log(eventName: string, data?: object): void;
19 > flush(): Promise<void>;
20 > }
21 >
22 > interface IAgentHostInternalTelemetrySenderOptions {
23 > readonly requestService?: IRequestService;
24 > readonly commonProperties?: ICommonProperties;
25 > readonly extensionVersion?: string;
26 > readonly createAppender?: (requestService: IRequestService | undefined, commonProperties: ICommonProperties | undefined, eventPrefix: string) => IInternalTelemetryAppender;
27 > }
28 >
29 function getInternalCommonProperties(commonProperties: ICommonProperties | undefined, extensionVersion: string | undefined): ICommonProperties | undefined {
30 if (!commonProperties) {
41 return result;
42 }
44 > class InternalTelemetryAppender extends Disposable {
45 >
46 > constructor(readonly appender: IInternalTelemetryAppender) {
47 super();
48 this._register(toDisposable(() => { void appender.flush(); }));
49 }
51 >
52 > export class AgentHostInternalTelemetrySender extends Disposable implements IAgentHostInternalTelemetrySink {
53 >
54 > private readonly _appender = this._register(new MutableDisposable<InternalTelemetryAppender>());
55 > private _context: IAgentHostInternalTelemetryContext | undefined;
56 >
57 > constructor(private readonly _options: IAgentHostInternalTelemetrySenderOptions = {}) {
58 super();
59 }
61 > setContext(context: IAgentHostInternalTelemetryContext | undefined): void {
62 this._context = context?.isInternal ? context : undefined;
63 if (!this._context) {
68 this._appender.value ??= new InternalTelemetryAppender(createAppender(this._options.requestService, getInternalCommonProperties(this._options.commonProperties, this._options.extensionVersion), INTERNAL_EVENT_PREFIX));
69 }
71 > send(eventName: string, properties?: TelemetryProps, measurements?: TelemetryMeasurements): void {
72 if (!this._context) {
73 return;
75 this.sendForContext(this._context, eventName, properties, measurements);
76 }
78 > sendForContext(context: IAgentHostInternalTelemetryContext, eventName: string, properties?: TelemetryProps, measurements?: TelemetryMeasurements): void {
79 if (!context.isInternal) {
80 return;
src/vs/platform/telemetry/common/1dsAppender.ts 41 introduced LOC · 6 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- 1dsAppender.ts
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 type { IExtendedConfiguration, IExtendedTelemetryItem, ITelemetryItem, ITelemetryUnloadState } from '@microsoft/1ds-core-js';
7 > import type { IChannelConfiguration, IXHROverride, PostChannel } from '@microsoft/1ds-post-js';
8 > import { importAMDNodeModule } from '../../../amdX.js';
9 > import { onUnexpectedError } from '../../../base/common/errors.js';
10 > import { mixin } from '../../../base/common/objects.js';
11 > import { isWeb } from '../../../base/common/platform.js';
12 > import { ITelemetryAppender, validateTelemetryData } from './telemetryUtils.js';
13 >
14 > // Interface type which is a subset of @microsoft/1ds-core-js AppInsightsCore.
15 > // Allows us to more easily build mock objects for testing as the interface is quite large and we only need a few properties.
16 > export interface IAppInsightsCore {
17 > pluginVersionString: string;
18 > track(item: ITelemetryItem | IExtendedTelemetryItem): void;
19 > unload(isAsync: boolean, unloadComplete: (unloadState: ITelemetryUnloadState) => void): void;
20 > }
21 >
22 > const endpointUrl = 'https://mobile.events.data.microsoft.com/OneCollector/1.0';
23 > const endpointHealthUrl = 'https://mobile.events.data.microsoft.com/ping';
24 >
25 async function getClient(instrumentationKey: string, addInternalFlag?: boolean, xhrOverride?: IXHROverride): Promise<IAppInsightsCore> {
26 // eslint-disable-next-line local/code-amd-node-module
73 return appInsightsCore;
74 }
76 > // TODO @lramos15 maybe make more in line with src/vs/platform/telemetry/browser/appInsightsAppender.ts with caching support
77 > export abstract class AbstractOneDataSystemAppender implements ITelemetryAppender {
78 >
79 > protected _aiCoreOrKey: IAppInsightsCore | string | undefined;
80 > private _asyncAiCore: Promise<IAppInsightsCore> | null;
81 > protected readonly endPointUrl = endpointUrl;
82 > protected readonly endPointHealthUrl = endpointHealthUrl;
83 >
84 > constructor(
85 private readonly _isInternalTelemetry: boolean,
86 private _eventPrefix: string,
100 this._asyncAiCore = null;
101 }
103 > private _withAIClient(callback: (aiCore: IAppInsightsCore) => void): void {
104 if (!this._aiCoreOrKey) {
105 return;
125 );
126 }
128 > log(eventName: string, data?: unknown): void {
129 if (!this._aiCoreOrKey) {
130 return;
144 } catch { }
145 }
147 > flush(): Promise<void> {
148 if (this._aiCoreOrKey) {
149 return new Promise(resolve => {
src/vs/platform/telemetry/node/1dsAppender.ts 39 introduced LOC · 5 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- 1dsAppender.ts
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 type { IPayloadData, IXHROverride } from '@microsoft/1ds-post-js';
7 > import { streamToBuffer } from '../../../base/common/buffer.js';
8 > import { CancellationToken } from '../../../base/common/cancellation.js';
9 > import { IRequestOptions } from '../../../base/parts/request/common/request.js';
10 > import { IRequestService, NO_FETCH_TELEMETRY } from '../../request/common/request.js';
11 > import { AbstractOneDataSystemAppender, IAppInsightsCore } from '../common/1dsAppender.js';
12 >
13 > type OnCompleteFunc = (status: number, headers: { [headerName: string]: string }, response?: string) => void;
14 >
15 > interface IResponseData {
16 > headers: { [headerName: string]: string };
17 > statusCode: number;
18 > responseData: string;
19 > }
20 >
21 > /**
22 > * Completes a request to submit telemetry to the server utilizing the request service
23 > * @param options The options which will be used to make the request
24 > * @param requestService The request service
25 > * @returns An object containing the headers, statusCode, and responseData
26 > */
27 async function makeTelemetryRequest(options: IRequestOptions, requestService: IRequestService): Promise<IResponseData> {
28 const response = await requestService.request(options, CancellationToken.None);
36 };
37 }
39 > /**
40 > * Complete a request to submit telemetry to the server utilizing the https module. Only used when the request service is not available
41 > * @param options The options which will be used to make the request
42 > * @returns An object containing the headers, statusCode, and responseData
43 > */
44 async function makeLegacyTelemetryRequest(options: IRequestOptions): Promise<IResponseData> {
45 const https = await import('https'); // Lazy due to https://github.com/nodejs/node/issues/59686
71 return responsePromise;
72 }
74 async function sendPostAsync(requestService: IRequestService | undefined, payload: IPayloadData, oncomplete: OnCompleteFunc) {
75 const telemetryRequestData = typeof payload.data === 'string' ? payload.data : new TextDecoder().decode(payload.data);
94 }
95 }
97 >
98 > export class OneDataSystemAppender extends AbstractOneDataSystemAppender {
99 >
100 > constructor(
101 requestService: IRequestService | undefined,
102 isInternalTelemetry: boolean,
115 super(isInternalTelemetry, eventPrefix, defaultData, iKeyOrClientFactory, customHttpXHROverride);
116 }
117 > } 1dsAppender.ts