Skip to content

Commit e3cb0da

Browse files
author
Timothy Wang
committed
add subscriptionId, swaCliVersion to telemetry reporting. add encrypted aiKey
1 parent 4e60df2 commit e3cb0da

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,12 @@ export const DEFAULT_CONFIG: SWACLIConfig = {
8383
// swa db options
8484
folderName: SWA_CLI_DATA_API_FOLDER || "swa-db-connections",
8585
};
86+
87+
export const getEnvVariablesForTelemetry = (): SWACLIEnv => {
88+
const { AZURE_SUBSCRIPTION_ID, SWA_CLI_VERSION } = swaCLIEnv();
89+
90+
return {
91+
AZURE_SUBSCRIPTION_ID,
92+
SWA_CLI_VERSION,
93+
};
94+
};

src/core/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,7 @@ export const TELEMETRY_RESPONSE_TYPES = {
291291
Failure: "Failure",
292292
Success: "Success",
293293
};
294+
295+
export const TELEMETRY_AI_KEY =
296+
"9928d14e7b98b148bdf662c107ad83a7:a52ec390fdb8602f2ae0f0d9d32f1a35ff925dad278eedb854ac0d00f8e77819abe0b37424fe536f160f8cc4142f77392d20e7d035134b2d23e03af772491a9749e9571300f86102c41b9bf8726814427db2a0f25926b743c83cddefd71ffa4cc8e77a9a1a214b14a323e5924a01c82664ee88387ae0a21f3d4ad78c86af45f161872b50671e032f28e849de2614de22c7b0497550a8cbdc64630528c6fb74865772774ec5370d5b8bdb1831e5a6bbfc10bd2b982da89e0d0f3915b7b60299fa7afd15bdd01dbc8ae7611f84b2b0845ad62f31b5082c7c9385bbb577aae8f1e1b239788ee363c8494d4c0e15ae735cf391cfce1086627440cd5cff912df384b3";
297+
export const TELEMETRY_SERVICE_HASH = "b5335dd37f994c4e2c5b4a78f7fc95e4";

src/core/telemetry/utils.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ dotenv.config();
44
import TelemetryReporter from "./telemetryReporter.js";
55
import type { TelemetryEventMeasurements, TelemetryEventProperties } from "./telemetryReporterTypes.js";
66
import { readCLIEnvFile } from "../utils/file.js";
7-
import { DEFAULT_CONFIG } from "../../config.js";
7+
import { getEnvVariablesForTelemetry } from "../../config.js";
88
import { logger } from "../utils/logger.js";
99
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";
1212

1313
export async function collectTelemetryEvent(event: string, properties?: TelemetryEventProperties, measurements?: TelemetryEventMeasurements) {
1414
const reporter = await GetTelemetryReporter();
1515

1616
if (reporter) {
17+
let environmentVariables = getEnvVariablesForTelemetry();
18+
1719
let extendedTelemetryEventProperties = {
18-
subscriptionId: DEFAULT_CONFIG.subscriptionId!,
20+
subscriptionId: environmentVariables.AZURE_SUBSCRIPTION_ID!,
21+
swaCliVersion: environmentVariables.SWA_CLI_VERSION!,
1922
} as TelemetryEventProperties;
2023

2124
logger.silly(`TELEMETRY REPORTING: ${event}, ${JSON.stringify({ ...properties, ...extendedTelemetryEventProperties })}, ${measurements}`);
@@ -26,8 +29,11 @@ export async function collectTelemetryEvent(event: string, properties?: Telemetr
2629
export async function collectTelemetryException(exception: Error, properties?: TelemetryEventProperties, measurements?: TelemetryEventMeasurements) {
2730
const reporter = await GetTelemetryReporter();
2831
if (reporter) {
32+
let environmentVariables = getEnvVariablesForTelemetry();
33+
2934
let extendedTelemetryEventProperties = {
30-
subscriptionId: DEFAULT_CONFIG.subscriptionId!,
35+
subscriptionId: environmentVariables.AZURE_SUBSCRIPTION_ID!,
36+
swaCliVersion: environmentVariables.SWA_CLI_VERSION!,
3137
} as TelemetryEventProperties;
3238

3339
logger.silly(
@@ -40,7 +46,9 @@ export async function collectTelemetryException(exception: Error, properties?: T
4046
export async function GetTelemetryReporter() {
4147
const config = await readCLIEnvFile();
4248
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);
4452
return reporter;
4553
}
4654
return undefined;

0 commit comments

Comments
 (0)