|
| 1 | +/** |
| 2 | + * @beta |
| 3 | + * @hidden |
| 4 | + * User information required by specific apps |
| 5 | + * @internal |
| 6 | + * Limited to Microsoft-internal use |
| 7 | + * @module |
| 8 | + */ |
| 9 | + |
| 10 | +import { callFunctionInHost } from '../../internal/communication'; |
| 11 | +import { ensureInitialized } from '../../internal/internalAPIs'; |
| 12 | +import { ApiName, ApiVersionNumber, getApiVersionTag, getLogger } from '../../internal/telemetry'; |
| 13 | +import { getCurrentTimestamp } from '../../internal/utils'; |
| 14 | +import { runtime } from '../../public/runtime'; |
| 15 | +import { UUID } from '../../public/uuidObject'; |
| 16 | + |
| 17 | +const copilotTelemetryVersionNumber: ApiVersionNumber = ApiVersionNumber.V_2; |
| 18 | +const copilotLogger = getLogger('copilot'); |
| 19 | + |
| 20 | +/** |
| 21 | + * Sends custom telemetry data to the host. |
| 22 | + * |
| 23 | + * @param { UUID } stageNameIdentifier - The stageName UUID identifier for the telemetry data. |
| 24 | + * @param { number } [timestamp=getCurrentTimestamp() ?? Date.now()] - The timestamp of the telemetry data. Defaults to the current timestamp. |
| 25 | + * @returns { Promise<void> } - promise resolves when the host SDK acknowledges that it has received the message. |
| 26 | + * @throws { Error } - Throws an error if the app has not been successfully initialized or the host SDK returns an error as a response to this call |
| 27 | + * |
| 28 | + * @hidden |
| 29 | + * @internal |
| 30 | + * Limited to Microsoft-internal use |
| 31 | + * @beta |
| 32 | + */ |
| 33 | +export async function sendCustomTelemetryData( |
| 34 | + stageNameIdentifier: UUID, |
| 35 | + timestamp: number = getCurrentTimestamp() ?? Date.now(), |
| 36 | +): Promise<void> { |
| 37 | + ensureInitialized(runtime); |
| 38 | + copilotLogger( |
| 39 | + 'Sending custom telemetry data to host for stage: %s to record timestamp: %s', |
| 40 | + stageNameIdentifier, |
| 41 | + timestamp, |
| 42 | + ); |
| 43 | + return callFunctionInHost( |
| 44 | + ApiName.Copilot_CustomTelemetry_SendCustomTelemetryData, |
| 45 | + [stageNameIdentifier.toString(), timestamp], |
| 46 | + getApiVersionTag(copilotTelemetryVersionNumber, ApiName.Copilot_CustomTelemetry_SendCustomTelemetryData), |
| 47 | + ); |
| 48 | +} |
0 commit comments