Skip to content

Commit 71e6afe

Browse files
committed
feat: Adds the raw stack trace in the synthetic monitors response
1 parent 0c05e4f commit 71e6afe

File tree

6 files changed

+53
-9
lines changed

6 files changed

+53
-9
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/synthetics-sdk-api/proto/synthetic_response.proto

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ message TestResult {
5353

5454
// A list of StackFrame messages that indicate a single trace of code.
5555
repeated StackFrame stack_frames = 3;
56+
57+
// The raw stack trace associated with the error.
58+
string stack_trace = 4;
5659
}
5760

5861
// The error that was the result of a test failure.
@@ -86,12 +89,14 @@ message GenericResultV1 {
8689
// lookup".
8790
string error_message = 2;
8891

89-
// The name of the function where the error occurred
92+
// The name of the function where the error occurred.
9093
string function_name = 3;
9194
// The name of the file that reported the error.
9295
string file_path = 4;
9396
// Line number that reported the error.
9497
optional int64 line = 5;
98+
// The raw stack trace that is associated with this error.
99+
string stack_trace = 6;
95100
}
96101

97102
// Error that was associated with this result, causing it to fail.
@@ -113,4 +118,4 @@ message SyntheticResult {
113118
string start_time = 5;
114119
// The end time of the synthetic in iso format.
115120
string end_time = 6;
116-
}
121+
}

packages/synthetics-sdk-api/src/generated/proto/synthetic_response.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export interface TestResult_TestError {
5353
error_message: string;
5454
/** A list of StackFrame messages that indicate a single trace of code. */
5555
stack_frames: TestResult_TestError_StackFrame[];
56+
/** The raw stack trace associated with the error. */
57+
stack_trace: string;
5658
}
5759

5860
/** An individual stack frame that represents a line of code within a file. */
@@ -114,12 +116,16 @@ export interface GenericResultV1_GenericError {
114116
* lookup".
115117
*/
116118
error_message: string;
117-
/** The name of the function where the error occurred */
119+
/** The name of the function where the error occurred. */
118120
function_name: string;
119121
/** The name of the file that reported the error. */
120122
file_path: string;
121123
/** Line number that reported the error. */
122-
line?: number | undefined;
124+
line?:
125+
| number
126+
| undefined;
127+
/** The raw stack trace that is associated with this error. */
128+
stack_trace: string;
123129
}
124130

125131
export interface SyntheticResult {
@@ -282,7 +288,7 @@ export const TestResult = {
282288
};
283289

284290
function createBaseTestResult_TestError(): TestResult_TestError {
285-
return { error_type: "", error_message: "", stack_frames: [] };
291+
return { error_type: "", error_message: "", stack_frames: [], stack_trace: "" };
286292
}
287293

288294
export const TestResult_TestError = {
@@ -296,6 +302,9 @@ export const TestResult_TestError = {
296302
for (const v of message.stack_frames) {
297303
TestResult_TestError_StackFrame.encode(v!, writer.uint32(26).fork()).ldelim();
298304
}
305+
if (message.stack_trace !== "") {
306+
writer.uint32(34).string(message.stack_trace);
307+
}
299308
return writer;
300309
},
301310

@@ -327,6 +336,13 @@ export const TestResult_TestError = {
327336

328337
message.stack_frames.push(TestResult_TestError_StackFrame.decode(reader, reader.uint32()));
329338
continue;
339+
case 4:
340+
if (tag !== 34) {
341+
break;
342+
}
343+
344+
message.stack_trace = reader.string();
345+
continue;
330346
}
331347
if ((tag & 7) === 4 || tag === 0) {
332348
break;
@@ -343,6 +359,7 @@ export const TestResult_TestError = {
343359
stack_frames: Array.isArray(object?.stack_frames)
344360
? object.stack_frames.map((e: any) => TestResult_TestError_StackFrame.fromJSON(e))
345361
: [],
362+
stack_trace: isSet(object.stack_trace) ? String(object.stack_trace) : "",
346363
};
347364
},
348365

@@ -355,6 +372,7 @@ export const TestResult_TestError = {
355372
} else {
356373
obj.stack_frames = [];
357374
}
375+
message.stack_trace !== undefined && (obj.stack_trace = message.stack_trace);
358376
return obj;
359377
},
360378

@@ -367,6 +385,7 @@ export const TestResult_TestError = {
367385
message.error_type = object.error_type ?? "";
368386
message.error_message = object.error_message ?? "";
369387
message.stack_frames = object.stack_frames?.map((e) => TestResult_TestError_StackFrame.fromPartial(e)) || [];
388+
message.stack_trace = object.stack_trace ?? "";
370389
return message;
371390
},
372391
};
@@ -684,7 +703,7 @@ export const GenericResultV1 = {
684703
};
685704

686705
function createBaseGenericResultV1_GenericError(): GenericResultV1_GenericError {
687-
return { error_type: "", error_message: "", function_name: "", file_path: "", line: undefined };
706+
return { error_type: "", error_message: "", function_name: "", file_path: "", line: undefined, stack_trace: "" };
688707
}
689708

690709
export const GenericResultV1_GenericError = {
@@ -704,6 +723,9 @@ export const GenericResultV1_GenericError = {
704723
if (message.line !== undefined) {
705724
writer.uint32(40).int64(message.line);
706725
}
726+
if (message.stack_trace !== "") {
727+
writer.uint32(50).string(message.stack_trace);
728+
}
707729
return writer;
708730
},
709731

@@ -749,6 +771,13 @@ export const GenericResultV1_GenericError = {
749771

750772
message.line = longToNumber(reader.int64() as Long);
751773
continue;
774+
case 6:
775+
if (tag !== 50) {
776+
break;
777+
}
778+
779+
message.stack_trace = reader.string();
780+
continue;
752781
}
753782
if ((tag & 7) === 4 || tag === 0) {
754783
break;
@@ -765,6 +794,7 @@ export const GenericResultV1_GenericError = {
765794
function_name: isSet(object.function_name) ? String(object.function_name) : "",
766795
file_path: isSet(object.file_path) ? String(object.file_path) : "",
767796
line: isSet(object.line) ? Number(object.line) : undefined,
797+
stack_trace: isSet(object.stack_trace) ? String(object.stack_trace) : "",
768798
};
769799
},
770800

@@ -775,6 +805,7 @@ export const GenericResultV1_GenericError = {
775805
message.function_name !== undefined && (obj.function_name = message.function_name);
776806
message.file_path !== undefined && (obj.file_path = message.file_path);
777807
message.line !== undefined && (obj.line = Math.round(message.line));
808+
message.stack_trace !== undefined && (obj.stack_trace = message.stack_trace);
778809
return obj;
779810
},
780811

@@ -789,6 +820,7 @@ export const GenericResultV1_GenericError = {
789820
message.function_name = object.function_name ?? "";
790821
message.file_path = object.file_path ?? "";
791822
message.line = object.line ?? undefined;
823+
message.stack_trace = object.stack_trace ?? "";
792824
return message;
793825
},
794826
};
@@ -1066,4 +1098,4 @@ function isObject(value: any): boolean {
10661098

10671099
function isSet(value: any): boolean {
10681100
return value !== null && value !== undefined;
1069-
}
1101+
}

packages/synthetics-sdk-api/src/handlers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ const runSynthetic = async (syntheticCode: () => any) => {
5252
line: firstFrame?.lineNumber,
5353
function_name: firstFrame?.functionName,
5454
});
55+
56+
synthetic_generic_result.generic_error.stack_trace = err.stack ?? '';
5557
}
5658
}
5759

packages/synthetics-sdk-api/test/integration/integration.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ describe('CloudFunctionV2 Running Synthetics', async () => {
6868
expect(generic_result?.generic_error?.file_path).to.equal('/user/code/location.js');
6969
expect(generic_result?.generic_error?.function_name).to.equal('async fn');
7070
expect(generic_result?.generic_error?.line).to.equal(8);
71+
expect(generic_result?.generic_error?.stack_trace).to.equal(
72+
`AssertionError: Did not assert\n\ at internalFn (node:internal)\n\ at async fn (/user/code/location.js:8:3)`);
7173

7274
expect(runtime_metadata).to.not.be.undefined;
7375
});

packages/synthetics-sdk-api/test/unit/handlers.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ describe('GCM Synthetics Handler', async () => {
7777
it('Assigns first stack frame with user code to the error', async () => {
7878
const now = new Date();
7979

80+
let e: Error | undefined;
8081
const handlerFunction = () => {
81-
const e = new AssertionError('Did not assert');
82+
e = new AssertionError('Did not assert');
8283
const splitStack = e.stack?.split('\n', 2) ?? '';
8384
e.stack = [
8485
splitStack?.[0],
@@ -113,6 +114,8 @@ describe('GCM Synthetics Handler', async () => {
113114
expect(syntheticResult?.synthetic_generic_result_v1?.generic_error?.file_path).to.equal('/user/code/location.js');
114115
expect(syntheticResult?.synthetic_generic_result_v1?.generic_error?.line).to.equal(8);
115116
expect(syntheticResult?.runtime_metadata).to.not.be.undefined;
117+
118+
expect(syntheticResult?.synthetic_generic_result_v1?.generic_error?.stack_trace).to.equal((e as Error).stack);
116119
});
117120

118121
describe('firstUserErrorStackFrame', () => {

0 commit comments

Comments
 (0)