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 { generateUuid } from '../../../base/common/uuid.js';
7
>
import { ILogService } from '../../log/common/log.js';
8
>
import { ICommonProperties } from '../../telemetry/common/telemetry.js';
9
>
10
>
/**
11
>
* Public GitHub Copilot telemetry ingestion keys. These are instrumentation keys, not
12
>
* secrets; the iKey selects the destination hydro table:
13
>
* - standard -> `copilot_v0_copilot_event`
14
>
* - enhanced -> `copilot_v0_restricted_copilot_event`
15
>
*/
16
>
const GH_STANDARD_IKEY = '7d7048df-6dd0-4048-bb23-b716c1461f8f';
17
>
const GH_ENHANCED_IKEY = '3fdd7f28-937a-48c8-9a21-ba337db23bd1';
18
>
19
>
/**
20
>
* Fallback Copilot telemetry endpoint (the dotcom value of the CAPI token's
21
>
* `endpoints.telemetry`, with the `/telemetry` path the Copilot CLI/runtime appends).
22
>
* Used until {@link IAgentHostRestrictedTelemetry.setRestrictedTelemetryEndpoint} supplies
23
>
* the user's discovered endpoint (dotcom, GHE, or proxy). Accepts unauthenticated POSTs.
24
>
*/
25
>
const GH_TELEMETRY_URL = 'https://copilot-telemetry.githubusercontent.com/telemetry';
26
>
27
>
/** Event names are namespaced by client category; the CTS name filter requires this. */
28
>
const NAMESPACE = 'copilot-chat';
29
>
30
>
export type TelemetryProps = Record<string, string | undefined>;
31
>
export type TelemetryMeasurements = Record<string, number | undefined>;
32
>
33
>
export interface IAgentHostInternalTelemetryContext {
34
>
readonly isInternal: boolean;
35
>
readonly trackingId: string | undefined;
36
>
readonly userName: string | undefined;
37
>
readonly isVscodeTeamMember: boolean;
38
>
}
39
>
40
>
export interface IAgentHostRestrictedTelemetryContext extends IAgentHostInternalTelemetryContext {
41
>
readonly restrictedTelemetryEnabled: boolean;
42
>
readonly telemetryEndpoint: string | undefined;
43
>
/** Whether content exclusion is enabled; undefined when account discovery could not determine it. */
44
>
readonly copilotIgnoreEnabled?: boolean;
45
>
}
46
>
47
>
export interface IAgentHostInternalTelemetrySink {
48
>
setContext(context: IAgentHostInternalTelemetryContext | undefined): void;
49
>
send(eventName: string, properties?: TelemetryProps, measurements?: TelemetryMeasurements): void;
50
>
sendForContext(context: IAgentHostInternalTelemetryContext, eventName: string, properties?: TelemetryProps, measurements?: TelemetryMeasurements): void;
51
>
}
52
>
53
>
/** The subset of the global `fetch` used to POST envelopes; injectable so tests avoid live network calls. */
54
>
export type FetchFn = typeof globalThis.fetch;
55
>
56
>
/**
57
>
* App Insights caps a single property value at ~8192 chars. Long values are split across
58
>
* numbered keys (`key`, `key_02`, `key_03`, …) so the Copilot Telemetry Service reassembles
59
>
* them, mirroring the Copilot extension's `multiplexProperties` so events look identical on the
60
>
* wire and downstream.
61
>
*/
62
>
const MAX_PROPERTY_LENGTH = 8192;
63
>
const MAX_CONCATENATED_PROPERTIES = 50;
64
>
65
>
export function multiplexProperties(properties: TelemetryProps): TelemetryProps {
66
const newProperties: TelemetryProps = { ...properties };
67
for (const key in properties) {