Skip to content

Commit 6a96fce

Browse files
committed
chore: enrich and improve telemetry events
1 parent fc7cdaa commit 6a96fce

File tree

10 files changed

+108
-63
lines changed

10 files changed

+108
-63
lines changed

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
"eslint-plugin-import": "^2.32.0",
138138
"fs-extra": "^11.3.1",
139139
"ms": "^2.1.3",
140+
"node-machine-id": "^1.1.12",
140141
"npm-run-all": "^4.1.5",
141142
"p-min-delay": "^4.1.0",
142143
"typescript": "^5.9.2",

src/extension.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import statusBar from "./plugins/status-bar.ts";
1111
import { PluginManager } from "./plugins.ts";
1212
import { createContainerStatusTracker } from "./utils/container-status.ts";
1313
import { createLocalStackStatusTracker } from "./utils/localstack-status.ts";
14-
import { getOrCreateExtensionSessionId } from "./utils/manage.ts";
14+
import {
15+
getOrCreateExtensionSessionId,
16+
getOrCreateMachineId,
17+
} from "./utils/manage.ts";
1518
import { createSetupStatusTracker } from "./utils/setup-status.ts";
1619
import { createTelemetry } from "./utils/telemetry.ts";
1720
import { createTimeTracker } from "./utils/time-tracker.ts";
@@ -80,7 +83,8 @@ export async function activate(context: ExtensionContext) {
8083
const startTelemetry = Date.now();
8184
outputChannel.trace(`[telemetry]: Starting...`);
8285
const sessionId = await getOrCreateExtensionSessionId(context);
83-
const telemetry = createTelemetry(outputChannel, sessionId);
86+
const machineId = await getOrCreateMachineId(context);
87+
const telemetry = createTelemetry(outputChannel, sessionId, machineId);
8488
const endTelemetry = Date.now();
8589
outputChannel.trace(
8690
`[telemetry]: Completed in ${ms(endTelemetry - startTelemetry, {

src/plugins/authenticate.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default createPlugin(
4040
payload: {
4141
namespace: "onboarding",
4242
origin: "manual_trigger",
43-
position: 2,
43+
step_order: 2,
4444
started_at: startedAt,
4545
ended_at: new Date().toISOString(),
4646
status: "CANCELLED",
@@ -65,7 +65,7 @@ export default createPlugin(
6565
payload: {
6666
namespace: "onboarding",
6767
origin: "manual_trigger",
68-
position: 2,
68+
step_order: 2,
6969
auth_token: authToken,
7070
started_at: startedAt,
7171
ended_at: new Date().toISOString(),
@@ -87,7 +87,7 @@ export default createPlugin(
8787
payload: {
8888
namespace: "onboarding",
8989
origin: "manual_trigger",
90-
position: 2,
90+
step_order: 2,
9191
started_at: startedAt,
9292
ended_at: new Date().toISOString(),
9393
status: "FAILED",
@@ -106,7 +106,7 @@ export default createPlugin(
106106
payload: {
107107
namespace: "onboarding",
108108
origin: "manual_trigger",
109-
position: 2,
109+
step_order: 2,
110110
started_at: startedAt,
111111
ended_at: new Date().toISOString(),
112112
status: "FAILED",
@@ -123,7 +123,7 @@ export default createPlugin(
123123
payload: {
124124
namespace: "onboarding",
125125
origin: "manual_trigger",
126-
position: 2,
126+
step_order: 2,
127127
auth_token: token,
128128
started_at: startedAt,
129129
ended_at: new Date().toISOString(),
@@ -136,7 +136,7 @@ export default createPlugin(
136136
payload: {
137137
namespace: "onboarding",
138138
origin: "manual_trigger",
139-
position: 2,
139+
step_order: 2,
140140
started_at: startedAt,
141141
ended_at: new Date().toISOString(),
142142
status: "CANCELLED",

src/plugins/setup.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
checkIsAuthenticated,
66
requestAuthentication,
77
saveAuthToken,
8+
readAuthToken,
89
} from "../utils/authenticate.ts";
910
import { configureAwsProfiles } from "../utils/configure-aws.ts";
1011
import { runInstallProcess } from "../utils/install.ts";
@@ -31,26 +32,6 @@ export default createPlugin(
3132
payload: {
3233
namespace: "onboarding",
3334
origin: origin_trigger,
34-
expected_steps: [
35-
{
36-
name: "emulator_installed",
37-
is_first_step: true,
38-
is_last_step: false,
39-
position: 1,
40-
},
41-
{
42-
name: "auth_token_configured",
43-
is_first_step: false,
44-
is_last_step: false,
45-
position: 2,
46-
},
47-
{
48-
name: "aws_profile_configured",
49-
is_first_step: false,
50-
is_last_step: true,
51-
position: 3,
52-
},
53-
],
5435
},
5536
});
5637

@@ -77,7 +58,7 @@ export default createPlugin(
7758
payload: {
7859
namespace: "onboarding",
7960
origin: origin_trigger,
80-
position: 1,
61+
step_order: 1,
8162
started_at: installationStartedAt,
8263
ended_at: new Date().toISOString(),
8364
status: "CANCELLED",
@@ -100,6 +81,7 @@ export default createPlugin(
10081
namespace: "onboarding",
10182
steps: [1, 2, 3],
10283
status: "CANCELLED",
84+
auth_token: await readAuthToken(),
10385
},
10486
});
10587
return;
@@ -113,7 +95,7 @@ export default createPlugin(
11395
payload: {
11496
namespace: "onboarding",
11597
origin: origin_trigger,
116-
position: 2,
98+
step_order: 2,
11799
started_at: authStartedAuthAt,
118100
ended_at: new Date().toISOString(),
119101
status: "SKIPPED",
@@ -135,7 +117,7 @@ export default createPlugin(
135117
payload: {
136118
namespace: "onboarding",
137119
origin: origin_trigger,
138-
position: 2,
120+
step_order: 2,
139121
auth_token: authToken,
140122
started_at: authStartedAuthAt,
141123
ended_at: new Date().toISOString(),
@@ -156,7 +138,7 @@ export default createPlugin(
156138
payload: {
157139
namespace: "onboarding",
158140
origin: origin_trigger,
159-
position: 2,
141+
step_order: 2,
160142
auth_token: authToken,
161143
started_at: authStartedAuthAt,
162144
ended_at: new Date().toISOString(),
@@ -236,6 +218,7 @@ export default createPlugin(
236218
namespace: "onboarding",
237219
steps: [1, 2, 3],
238220
status: "COMPLETED",
221+
auth_token: await readAuthToken(),
239222
},
240223
});
241224
},

src/utils/authenticate.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export async function checkIsAuthenticated() {
131131
return false;
132132
}
133133
return true;
134-
} catch (error) {
134+
} catch {
135135
return false;
136136
}
137137
}
@@ -143,3 +143,21 @@ function isAuthTokenPresent(authObject: unknown) {
143143
AUTH_TOKEN_KEY in authObject
144144
);
145145
}
146+
147+
// Reads the auth token from the auth.json file for logging in the user
148+
export async function readAuthToken(): Promise<string> {
149+
try {
150+
const authJson = await fs.readFile(LOCALSTACK_AUTH_FILENAME, "utf-8");
151+
const authObject = JSON.parse(authJson) as unknown;
152+
if (!isAuthTokenPresent(authObject)) {
153+
return "";
154+
}
155+
const authToken = authObject[AUTH_TOKEN_KEY];
156+
if (typeof authToken !== "string") {
157+
return "";
158+
}
159+
return authToken;
160+
} catch {
161+
return "";
162+
}
163+
}

src/utils/configure-aws.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as path from "node:path";
55

66
import { window } from "vscode";
77

8+
import { readAuthToken } from "./authenticate.ts";
89
import { parseIni, serializeIni, updateIniSection } from "./ini-parser.ts";
910
import type { IniFile, IniSection } from "./ini-parser.ts";
1011
import type { Telemetry } from "./telemetry.ts";
@@ -296,6 +297,8 @@ export async function configureAwsProfiles(options: {
296297
const credentialsNeedsOverride =
297298
checkIfCredentialsNeedsOverride(credentialsSection);
298299

300+
const authToken = await readAuthToken();
301+
299302
// means sections exist, but we need to check what's inside
300303
if (credentialsSection && configSection) {
301304
if (!configNeedsOverride && !credentialsNeedsOverride) {
@@ -310,10 +313,11 @@ export async function configureAwsProfiles(options: {
310313
payload: {
311314
namespace: "onboarding",
312315
origin: trigger,
313-
position: 3,
316+
step_order: 3,
314317
started_at: startedAt,
315318
ended_at: new Date().toISOString(),
316319
status: "COMPLETED",
320+
auth_token: authToken,
317321
},
318322
});
319323
return;
@@ -343,10 +347,11 @@ export async function configureAwsProfiles(options: {
343347
payload: {
344348
namespace: "onboarding",
345349
origin: trigger,
346-
position: 3,
350+
step_order: 3,
347351
started_at: startedAt,
348352
ended_at: new Date().toISOString(),
349353
status: "SKIPPED",
354+
auth_token: authToken,
350355
},
351356
});
352357
return;
@@ -376,10 +381,11 @@ export async function configureAwsProfiles(options: {
376381
payload: {
377382
namespace: "onboarding",
378383
origin: trigger,
379-
position: 3,
384+
step_order: 3,
380385
started_at: startedAt,
381386
ended_at: new Date().toISOString(),
382387
status: "COMPLETED",
388+
auth_token: authToken,
383389
},
384390
});
385391
} else if (configNeedsOverride) {
@@ -398,10 +404,11 @@ export async function configureAwsProfiles(options: {
398404
payload: {
399405
namespace: "onboarding",
400406
origin: trigger,
401-
position: 3,
407+
step_order: 3,
402408
started_at: startedAt,
403409
ended_at: new Date().toISOString(),
404410
status: "COMPLETED",
411+
auth_token: authToken,
405412
},
406413
});
407414
} else if (credentialsNeedsOverride) {
@@ -420,10 +427,11 @@ export async function configureAwsProfiles(options: {
420427
payload: {
421428
namespace: "onboarding",
422429
origin: trigger,
423-
position: 3,
430+
step_order: 3,
424431
started_at: startedAt,
425432
ended_at: new Date().toISOString(),
426433
status: "COMPLETED",
434+
auth_token: authToken,
427435
},
428436
});
429437
}

src/utils/install.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export async function runInstallProcess(
6464
payload: {
6565
namespace: "onboarding",
6666
origin: origin_trigger,
67-
position: 1,
67+
step_order: 1,
6868
started_at: startedAt,
6969
ended_at: new Date().toISOString(),
7070
status: "SKIPPED",
@@ -152,7 +152,7 @@ export async function runInstallProcess(
152152
payload: {
153153
namespace: "onboarding",
154154
origin: origin_trigger,
155-
position: 1,
155+
step_order: 1,
156156
started_at: startedAt,
157157
ended_at: new Date().toISOString(),
158158
status: "FAILED",
@@ -181,7 +181,7 @@ export async function runInstallProcess(
181181
payload: {
182182
namespace: "onboarding",
183183
origin: origin_trigger,
184-
position: 1,
184+
step_order: 1,
185185
started_at: startedAt,
186186
ended_at: new Date().toISOString(),
187187
status: "FAILED",
@@ -198,7 +198,7 @@ export async function runInstallProcess(
198198
payload: {
199199
namespace: "onboarding",
200200
origin: origin_trigger,
201-
position: 1,
201+
step_order: 1,
202202
started_at: startedAt,
203203
ended_at: new Date().toISOString(),
204204
status: "COMPLETED",

0 commit comments

Comments
 (0)