Skip to content

Commit 0cc2de3

Browse files
authored
add telemetry schema (#2589)
1 parent d937151 commit 0cc2de3

File tree

4 files changed

+333
-0
lines changed

4 files changed

+333
-0
lines changed

.changeset/pretty-bees-repair.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/platform-core': minor
3+
---
4+
5+
add telemetry schema

packages/platform-core/API.md

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ export class ConfigurationControllerFactory {
125125
getInstance: (configFileName: LocalConfigurationFileName) => ConfigurationController;
126126
}
127127

128+
// @public (undocumented)
129+
export type ErrorDetails = {
130+
name: string;
131+
message: string;
132+
stack: string;
133+
cause?: ErrorDetails;
134+
};
135+
128136
// @public
129137
export class FilePathExtractor {
130138
constructor(stackTraceLine: string);
@@ -220,6 +228,242 @@ export enum TagName {
220228
FRIENDLY_NAME = "amplify:friendly-name"
221229
}
222230

231+
// @public (undocumented)
232+
export type TelemetryPayload = z.infer<typeof telemetryPayloadSchema>;
233+
234+
// @public (undocumented)
235+
export const telemetryPayloadSchema: z.ZodObject<{
236+
identifiers: z.ZodObject<{
237+
payloadVersion: z.ZodString;
238+
sessionUuid: z.ZodString;
239+
eventId: z.ZodString;
240+
timestamp: z.ZodString;
241+
localProjectId: z.ZodString;
242+
accountId: z.ZodOptional<z.ZodString>;
243+
awsRegion: z.ZodOptional<z.ZodString>;
244+
}, "strip", z.ZodTypeAny, {
245+
payloadVersion: string;
246+
sessionUuid: string;
247+
timestamp: string;
248+
eventId: string;
249+
localProjectId: string;
250+
accountId?: string | undefined;
251+
awsRegion?: string | undefined;
252+
}, {
253+
payloadVersion: string;
254+
sessionUuid: string;
255+
timestamp: string;
256+
eventId: string;
257+
localProjectId: string;
258+
accountId?: string | undefined;
259+
awsRegion?: string | undefined;
260+
}>;
261+
event: z.ZodObject<{
262+
state: z.ZodEnum<["ABORTED", "FAILED", "SUCCEEDED"]>;
263+
command: z.ZodObject<{
264+
path: z.ZodArray<z.ZodString, "many">;
265+
parameters: z.ZodArray<z.ZodString, "many">;
266+
}, "strip", z.ZodTypeAny, {
267+
path: string[];
268+
parameters: string[];
269+
}, {
270+
path: string[];
271+
parameters: string[];
272+
}>;
273+
}, "strip", z.ZodTypeAny, {
274+
state: "FAILED" | "SUCCEEDED" | "ABORTED";
275+
command: {
276+
path: string[];
277+
parameters: string[];
278+
};
279+
}, {
280+
state: "FAILED" | "SUCCEEDED" | "ABORTED";
281+
command: {
282+
path: string[];
283+
parameters: string[];
284+
};
285+
}>;
286+
environment: z.ZodObject<{
287+
os: z.ZodObject<{
288+
platform: z.ZodString;
289+
release: z.ZodString;
290+
}, "strip", z.ZodTypeAny, {
291+
platform: string;
292+
release: string;
293+
}, {
294+
platform: string;
295+
release: string;
296+
}>;
297+
shell: z.ZodString;
298+
npmUserAgent: z.ZodString;
299+
ci: z.ZodBoolean;
300+
memory: z.ZodObject<{
301+
total: z.ZodNumber;
302+
free: z.ZodNumber;
303+
}, "strip", z.ZodTypeAny, {
304+
total: number;
305+
free: number;
306+
}, {
307+
total: number;
308+
free: number;
309+
}>;
310+
}, "strip", z.ZodTypeAny, {
311+
os: {
312+
platform: string;
313+
release: string;
314+
};
315+
shell: string;
316+
npmUserAgent: string;
317+
ci: boolean;
318+
memory: {
319+
total: number;
320+
free: number;
321+
};
322+
}, {
323+
os: {
324+
platform: string;
325+
release: string;
326+
};
327+
shell: string;
328+
npmUserAgent: string;
329+
ci: boolean;
330+
memory: {
331+
total: number;
332+
free: number;
333+
};
334+
}>;
335+
project: z.ZodObject<{
336+
dependencies: z.ZodOptional<z.ZodArray<z.ZodObject<{
337+
name: z.ZodString;
338+
version: z.ZodString;
339+
}, "strip", z.ZodTypeAny, {
340+
name: string;
341+
version: string;
342+
}, {
343+
name: string;
344+
version: string;
345+
}>, "many">>;
346+
}, "strip", z.ZodTypeAny, {
347+
dependencies?: {
348+
name: string;
349+
version: string;
350+
}[] | undefined;
351+
}, {
352+
dependencies?: {
353+
name: string;
354+
version: string;
355+
}[] | undefined;
356+
}>;
357+
latency: z.ZodObject<{
358+
total: z.ZodNumber;
359+
init: z.ZodOptional<z.ZodNumber>;
360+
synthesis: z.ZodOptional<z.ZodNumber>;
361+
deployment: z.ZodOptional<z.ZodNumber>;
362+
hotSwap: z.ZodOptional<z.ZodNumber>;
363+
}, "strip", z.ZodTypeAny, {
364+
total: number;
365+
init?: number | undefined;
366+
synthesis?: number | undefined;
367+
deployment?: number | undefined;
368+
hotSwap?: number | undefined;
369+
}, {
370+
total: number;
371+
init?: number | undefined;
372+
synthesis?: number | undefined;
373+
deployment?: number | undefined;
374+
hotSwap?: number | undefined;
375+
}>;
376+
error: z.ZodOptional<z.ZodType<ErrorDetails, z.ZodTypeDef, ErrorDetails>>;
377+
}, "strip", z.ZodTypeAny, {
378+
identifiers: {
379+
payloadVersion: string;
380+
sessionUuid: string;
381+
timestamp: string;
382+
eventId: string;
383+
localProjectId: string;
384+
accountId?: string | undefined;
385+
awsRegion?: string | undefined;
386+
};
387+
event: {
388+
state: "FAILED" | "SUCCEEDED" | "ABORTED";
389+
command: {
390+
path: string[];
391+
parameters: string[];
392+
};
393+
};
394+
environment: {
395+
os: {
396+
platform: string;
397+
release: string;
398+
};
399+
shell: string;
400+
npmUserAgent: string;
401+
ci: boolean;
402+
memory: {
403+
total: number;
404+
free: number;
405+
};
406+
};
407+
project: {
408+
dependencies?: {
409+
name: string;
410+
version: string;
411+
}[] | undefined;
412+
};
413+
latency: {
414+
total: number;
415+
init?: number | undefined;
416+
synthesis?: number | undefined;
417+
deployment?: number | undefined;
418+
hotSwap?: number | undefined;
419+
};
420+
error?: ErrorDetails | undefined;
421+
}, {
422+
identifiers: {
423+
payloadVersion: string;
424+
sessionUuid: string;
425+
timestamp: string;
426+
eventId: string;
427+
localProjectId: string;
428+
accountId?: string | undefined;
429+
awsRegion?: string | undefined;
430+
};
431+
event: {
432+
state: "FAILED" | "SUCCEEDED" | "ABORTED";
433+
command: {
434+
path: string[];
435+
parameters: string[];
436+
};
437+
};
438+
environment: {
439+
os: {
440+
platform: string;
441+
release: string;
442+
};
443+
shell: string;
444+
npmUserAgent: string;
445+
ci: boolean;
446+
memory: {
447+
total: number;
448+
free: number;
449+
};
450+
};
451+
project: {
452+
dependencies?: {
453+
name: string;
454+
version: string;
455+
}[] | undefined;
456+
};
457+
latency: {
458+
total: number;
459+
init?: number | undefined;
460+
synthesis?: number | undefined;
461+
deployment?: number | undefined;
462+
hotSwap?: number | undefined;
463+
};
464+
error?: ErrorDetails | undefined;
465+
}>;
466+
223467
// @public
224468
export const USAGE_DATA_TRACKING_ENABLED = "telemetry.enabled";
225469

packages/platform-core/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ export * from './parameter_path_conversions.js';
1212
export * from './object_accumulator.js';
1313
export { TagName } from './tag_name.js';
1414
export * from './naming_convention_conversions.js';
15+
export {
16+
ErrorDetails,
17+
TelemetryPayload,
18+
telemetryPayloadSchema,
19+
} from './telemetry-data/telemetry_data.js';
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import z from 'zod';
2+
3+
const identifiersSchema = z.object({
4+
payloadVersion: z.string(),
5+
sessionUuid: z.string(),
6+
eventId: z.string(),
7+
timestamp: z.string(),
8+
localProjectId: z.string(),
9+
accountId: z.string().optional(),
10+
awsRegion: z.string().optional(),
11+
});
12+
13+
const eventSchema = z.object({
14+
state: z.enum(['ABORTED', 'FAILED', 'SUCCEEDED']),
15+
command: z.object({
16+
path: z.array(z.string()),
17+
parameters: z.array(z.string()),
18+
}),
19+
});
20+
21+
const environmentSchema = z.object({
22+
os: z.object({
23+
platform: z.string(),
24+
release: z.string(),
25+
}),
26+
shell: z.string(),
27+
npmUserAgent: z.string(),
28+
ci: z.boolean(),
29+
memory: z.object({
30+
total: z.number(),
31+
free: z.number(),
32+
}),
33+
});
34+
35+
const projectSchema = z.object({
36+
dependencies: z
37+
.array(
38+
z.object({
39+
name: z.string(),
40+
version: z.string(),
41+
}),
42+
)
43+
.optional(),
44+
});
45+
46+
const latencySchema = z.object({
47+
total: z.number(),
48+
init: z.number().optional(),
49+
synthesis: z.number().optional(),
50+
deployment: z.number().optional(),
51+
hotSwap: z.number().optional(),
52+
});
53+
54+
export type ErrorDetails = {
55+
name: string;
56+
message: string;
57+
stack: string;
58+
cause?: ErrorDetails;
59+
};
60+
61+
const errorSchema: z.ZodType<ErrorDetails> = z.lazy(() =>
62+
z.object({
63+
name: z.string(),
64+
message: z.string(),
65+
stack: z.string(),
66+
cause: z.optional(errorSchema), // Recursive reference
67+
}),
68+
);
69+
70+
export const telemetryPayloadSchema = z.object({
71+
identifiers: identifiersSchema,
72+
event: eventSchema,
73+
environment: environmentSchema,
74+
project: projectSchema,
75+
latency: latencySchema,
76+
error: z.optional(errorSchema),
77+
});
78+
79+
export type TelemetryPayload = z.infer<typeof telemetryPayloadSchema>;

0 commit comments

Comments
 (0)