Skip to content

Commit 34dc06f

Browse files
authored
fix: remove freeform error message text from telemetry (#3050)
Even accounting for our best attempts to sanitize the freeform text, the chance something undesirable slips through is too high. Don't collect the text at all. _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license._
1 parent 899a46d commit 34dc06f

File tree

6 files changed

+18
-24
lines changed

6 files changed

+18
-24
lines changed

.changeset/thick-papers-wish.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': patch
3+
---
4+
5+
Remove freeform error message text from telemetry

packages/platform-core/API.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ export class ConfigurationControllerFactory {
131131
// @public (undocumented)
132132
export type ErrorDetails = {
133133
name: string;
134-
message: string;
135-
stack: string;
136134
caused?: ErrorDetails;
137135
};
138136

packages/platform-core/src/telemetry/telemetry_payload.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,20 @@ const latencySchema = z.object({
5353

5454
export type ErrorDetails = {
5555
name: string;
56-
message: string;
57-
stack: string;
56+
// Purposely omitting message and stack. Removing them from the Zod schema
57+
// removes them from the payload sent to the server.
58+
// message: string;
59+
// stack: string;
5860
caused?: ErrorDetails;
5961
};
6062

6163
const errorSchema: z.ZodType<ErrorDetails> = z.lazy(() =>
6264
z.object({
6365
name: z.string(),
64-
message: z.string(),
65-
stack: z.string(),
66+
// Purposely omitting message and stack. Removing them from the Zod schema
67+
// removes them from the payload sent to the server.
68+
// message: z.string(),
69+
// stack: z.string(),
6670
caused: z.optional(errorSchema), // Recursive reference
6771
}),
6872
);

packages/platform-core/src/telemetry/telemetry_payload_exporter.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,12 @@ void describe('DefaultTelemetryPayloadExporter', () => {
250250
assert.strictEqual(telemetryPayloadSent.latency.deployment, 740);
251251
assert.strictEqual(telemetryPayloadSent.error?.name, 'test error');
252252
assert.strictEqual(
253-
telemetryPayloadSent.error.message,
254-
'test error message',
253+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
254+
(telemetryPayloadSent.error as any).message,
255+
undefined,
255256
);
256-
assert.strictEqual(telemetryPayloadSent.error.stack, 'test error stack');
257+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
258+
assert.strictEqual((telemetryPayloadSent.error as any).stack, undefined);
257259
assert.deepStrictEqual(mockResultCallback.mock.calls[0].arguments[0], {
258260
code: ExportResultCode.SUCCESS,
259261
});
@@ -329,11 +331,6 @@ void describe('DefaultTelemetryPayloadExporter', () => {
329331
telemetryPayloadSent.error?.name,
330332
'TelemetrySpanAttributeCountLimitFault',
331333
);
332-
assert.strictEqual(
333-
telemetryPayloadSent.error.message,
334-
`Telemetry span attribute count has hit the limit of ${telemetrySpanAttributeCountLimit}`,
335-
);
336-
assert.ok(telemetryPayloadSent.error.stack);
337334
assert.deepStrictEqual(mockResultCallback.mock.calls[0].arguments[0], {
338335
code: ExportResultCode.SUCCESS,
339336
});

packages/platform-core/src/telemetry/translate_error_to_telemetry_error_details.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ void describe('translateErrorToTelemetryErrorDetails', () => {
99
error.stack = 'test stack';
1010
const expectedError: TelemetryPayload['error'] = {
1111
name: 'Error',
12-
message: 'test error message',
13-
stack: 'test stack',
1412
};
1513
const actual = translateErrorToTelemetryErrorDetails(error);
1614
assert.deepStrictEqual(actual, expectedError);
@@ -30,16 +28,10 @@ void describe('translateErrorToTelemetryErrorDetails', () => {
3028

3129
const expectedError: TelemetryPayload['error'] = {
3230
name: 'DeeplyNestedError',
33-
message: 'deeply nested error',
34-
stack: 'stack for deeply nested error',
3531
caused: {
3632
name: 'NestedError',
37-
message: 'nested error',
38-
stack: 'stack for nested error',
3933
caused: {
4034
name: 'Error',
41-
message: 'top level error',
42-
stack: 'stack for error',
4335
},
4436
},
4537
};

packages/platform-core/src/telemetry/translate_error_to_telemetry_error_details.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ export const translateErrorToTelemetryErrorDetails = (
1818
const serializedError = new SerializableError(currentError);
1919
const errorDetail: TelemetryPayload['error'] = {
2020
name: serializedError.name,
21-
message: serializedError.message,
22-
stack: serializedError.stack ?? '',
2321
};
2422

2523
if (errorDetails) {

0 commit comments

Comments
 (0)