@@ -4,18 +4,21 @@ dotenv.config();
4
4
import TelemetryReporter from "./telemetryReporter.js" ;
5
5
import type { TelemetryEventMeasurements , TelemetryEventProperties } from "./telemetryReporterTypes.js" ;
6
6
import { readCLIEnvFile } from "../utils/file.js" ;
7
- import { DEFAULT_CONFIG } from "../../config.js" ;
7
+ import { getEnvVariablesForTelemetry } from "../../config.js" ;
8
8
import { logger } from "../utils/logger.js" ;
9
9
import crypto from "crypto" ;
10
-
11
- const aiKey = "TODO ";
10
+ import { CryptoService } from "../swa-cli-persistence-plugin/impl/crypto.js" ;
11
+ import { TELEMETRY_AI_KEY , TELEMETRY_SERVICE_HASH } from "../constants.js ";
12
12
13
13
export async function collectTelemetryEvent ( event : string , properties ?: TelemetryEventProperties , measurements ?: TelemetryEventMeasurements ) {
14
14
const reporter = await GetTelemetryReporter ( ) ;
15
15
16
16
if ( reporter ) {
17
+ let environmentVariables = getEnvVariablesForTelemetry ( ) ;
18
+
17
19
let extendedTelemetryEventProperties = {
18
- subscriptionId : DEFAULT_CONFIG . subscriptionId ! ,
20
+ subscriptionId : environmentVariables . AZURE_SUBSCRIPTION_ID ! ,
21
+ swaCliVersion : environmentVariables . SWA_CLI_VERSION ! ,
19
22
} as TelemetryEventProperties ;
20
23
21
24
logger . silly ( `TELEMETRY REPORTING: ${ event } , ${ JSON . stringify ( { ...properties , ...extendedTelemetryEventProperties } ) } , ${ measurements } ` ) ;
@@ -26,8 +29,11 @@ export async function collectTelemetryEvent(event: string, properties?: Telemetr
26
29
export async function collectTelemetryException ( exception : Error , properties ?: TelemetryEventProperties , measurements ?: TelemetryEventMeasurements ) {
27
30
const reporter = await GetTelemetryReporter ( ) ;
28
31
if ( reporter ) {
32
+ let environmentVariables = getEnvVariablesForTelemetry ( ) ;
33
+
29
34
let extendedTelemetryEventProperties = {
30
- subscriptionId : DEFAULT_CONFIG . subscriptionId ! ,
35
+ subscriptionId : environmentVariables . AZURE_SUBSCRIPTION_ID ! ,
36
+ swaCliVersion : environmentVariables . SWA_CLI_VERSION ! ,
31
37
} as TelemetryEventProperties ;
32
38
33
39
logger . silly (
@@ -40,7 +46,9 @@ export async function collectTelemetryException(exception: Error, properties?: T
40
46
export async function GetTelemetryReporter ( ) {
41
47
const config = await readCLIEnvFile ( ) ;
42
48
if ( ! config [ "SWA_CLI_CAPTURE_TELEMETRY" ] || config [ "SWA_CLI_CAPTURE_TELEMETRY" ] . toLowerCase ( ) === "true" ) {
43
- const reporter : TelemetryReporter = new TelemetryReporter ( aiKey ) ;
49
+ const cryptoService = new CryptoService ( TELEMETRY_SERVICE_HASH ) ;
50
+ const decryptedAiKey = await cryptoService . decrypt ( TELEMETRY_AI_KEY ) ;
51
+ const reporter : TelemetryReporter = new TelemetryReporter ( decryptedAiKey ) ;
44
52
return reporter ;
45
53
}
46
54
return undefined ;
0 commit comments