Skip to content

Commit b1919d6

Browse files
committed
Add Sentry breadcrumbs to Roarr logging methods
1 parent 452a3ad commit b1919d6

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/lib/shared/roarr/client.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
import { serializeError } from 'serialize-error';
1010
import { sentry } from '../sentry';
1111
import { getTraceId } from '../sentry/utils';
12+
import type { SeverityLevel } from '../sentry/types';
1213

1314
export const roarr = (function () {
1415
const createLogger = (methodName: LoggerLoggingMethodName) => {
@@ -26,6 +27,13 @@ export const roarr = (function () {
2627
: contextClone,
2728
message,
2829
);
30+
31+
sentry?.addBreadcrumb({
32+
type: 'default',
33+
category: 'console',
34+
message: JSON.stringify({ message, context: contextClone }),
35+
level: convertLogLevelNameRoarrToSentry(methodName),
36+
});
2937
};
3038
};
3139

@@ -119,3 +127,18 @@ function getFileName(): string {
119127

120128
return fileName.replace(config.folders.root, '');
121129
}
130+
131+
function convertLogLevelNameRoarrToSentry(
132+
methodName: LoggerLoggingMethodName,
133+
): SeverityLevel {
134+
const methodNameWithoutOnce = methodName.replace('Once', '');
135+
136+
switch (methodNameWithoutOnce) {
137+
case 'trace':
138+
return 'debug';
139+
case 'warn':
140+
return 'warning';
141+
default:
142+
return methodName as SeverityLevel;
143+
}
144+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type { SeverityLevel } from '@sentry/sveltekit';

0 commit comments

Comments
 (0)