Skip to content

Commit

Permalink
feat: Add tagging to Sentry (#885)
Browse files Browse the repository at this point in the history
* Tags some errors for better tracking in Sentry
  • Loading branch information
8bittitan authored Oct 1, 2024
1 parent 93a7f5c commit fe31488
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/helpers/errorReporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import * as Sentry from '@sentry/node';

import { log } from './logger';

export const RENDERSCRIPT_TASK_URL_TAG = 'renderscript:task:url';
export const RENDERSCRIPT_TASK_TYPE_TAG = 'renderscript:task:type';

type SentryTag = {
key: string;
value: string;
};

Sentry.init({
dsn: process.env.SENTRY_DSN,
release: process.env.npm_package_version,
Expand All @@ -11,14 +19,22 @@ Sentry.init({
maxBreadcrumbs: 10,
});

export function report(err: Error, extra: any = {}): void {
export function report(
err: Error,
extra: any = {},
tags: SentryTag[] = []
): void {
if (!process.env.SENTRY_DSN) {
console.error({ err, extra });
return;
}

log.error(err.message, extra);
Sentry.withScope((scope) => {
tags.forEach((tag) => {
Sentry.setTag(tag.key, tag.value);
});

scope.setExtras(extra);
Sentry.captureException(err);
});
Expand Down
17 changes: 15 additions & 2 deletions src/lib/TasksManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { report } from '../helpers/errorReporting';
import {
RENDERSCRIPT_TASK_TYPE_TAG,
RENDERSCRIPT_TASK_URL_TAG,
report,
} from '../helpers/errorReporting';
import { log as mainLog } from '../helpers/logger';
import { stats } from '../helpers/stats';

Expand Down Expand Up @@ -184,7 +188,16 @@ export class TasksManager {
if (!(err instanceof ErrorIsHandledError)) {
task.results.error = task.results.error || cleanErrorMessage(err);
task.results.rawError = err;
report(err, { url });
report(err, { url }, [
{
key: RENDERSCRIPT_TASK_URL_TAG,
value: url,
},
{
key: RENDERSCRIPT_TASK_TYPE_TAG,
value: type,
},
]);
}
/* eslint-enable no-param-reassign */
}
Expand Down

0 comments on commit fe31488

Please sign in to comment.