Skip to content

Commit 3092d39

Browse files
authored
feat(sentry): include message into title (#541)
* feat(sentry): include message into title * fix(sentry): message is included in title if exception is missing
1 parent 152362b commit 3092d39

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

workers/sentry/src/utils/converter.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ function flattenObject(obj: unknown, prefix = ''): string[] {
5454
* @param eventPayload - Sentry event payload
5555
*/
5656
export function composeTitle(eventPayload: SentryEvent): string {
57-
return `${eventPayload.exception?.values?.[0]?.type || 'Unknown'}: ${eventPayload.exception?.values?.[0]?.value || ''}`;
57+
const exception = eventPayload.exception?.values?.[0];
58+
59+
if (exception) {
60+
return `${exception.type || 'Unknown'}: ${exception.value || ''}`;
61+
}
62+
63+
return eventPayload.message || 'Unknown: ';
5864
}
5965

6066
/**

workers/sentry/tests/converter.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@ describe('converter utils', () => {
2121

2222
expect(composeTitle(event)).toBe('Unknown: ');
2323
});
24+
25+
it('should compose title from message if exception is missing', () => {
26+
const event: SentryEvent = {
27+
message: 'message'
28+
};
29+
30+
expect(composeTitle(event)).toBe('message');
31+
});
32+
33+
it('should compose title from exception type and value even if message is present', () => {
34+
const event: SentryEvent = {
35+
exception: {
36+
values: [ {
37+
type: 'Error',
38+
value: 'Something went wrong',
39+
} ],
40+
},
41+
message: 'message'
42+
};
43+
44+
expect(composeTitle(event)).toBe('Error: Something went wrong');
45+
});
2446
});
2547

2648
describe('composeBacktrace()', () => {

workers/sentry/tests/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ describe('SentryEventWorker', () => {
304304
},
305305
},
306306
catcherVersion: '1.0.1',
307-
title: 'Unknown: ',
307+
title: 'Test timestamp',
308308
type: 'error',
309309
},
310310
}));

0 commit comments

Comments
 (0)