Skip to content

Commit

Permalink
Added sentry reporting to the pg-queue
Browse files Browse the repository at this point in the history
  • Loading branch information
habdelra committed May 13, 2024
1 parent ff6fc92 commit de51074
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
6 changes: 5 additions & 1 deletion packages/realm-server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { readFileSync } from 'fs-extra';
import { shimExternals } from './lib/externals';
import { type RealmPermissions as RealmPermissionsInterface } from '@cardstack/runtime-common/realm';
import * as Sentry from '@sentry/node';
import { setErrorReporter } from '@cardstack/runtime-common/realm';
import {
reportSentryError,
setErrorReporter,
} from '@cardstack/runtime-common/error';
import PgAdapter from './pg-adapter';
import PgQueue from './pg-queue';

Expand Down Expand Up @@ -272,6 +275,7 @@ if (distURL) {
`Unexpected error encountered starting realm, stopping server`,
e,
);
reportSentryError(e);
process.exit(1);
});

Expand Down
4 changes: 3 additions & 1 deletion packages/realm-server/pg-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Deferred,
Job,
} from '@cardstack/runtime-common';
import { reportSentryError } from '@cardstack/runtime-common/error';
import PgAdapter from './pg-adapter';

const log = logger('queue');
Expand Down Expand Up @@ -338,7 +339,8 @@ export default class PgQueue implements Queue {
log.debug(`running %s`, coalescedIds);
result = await this.runJob(firstJob.category, firstJob.args);
newStatus = 'resolved';
} catch (err) {
} catch (err: any) {
reportSentryError(err);
result = serializableError(err);
newStatus = 'rejected';
}
Expand Down
16 changes: 16 additions & 0 deletions packages/runtime-common/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ export interface SerializedError {
stack?: string;
}

export type ErrorReporter = (error: Error) => void;

let globalWithErrorReporter = global as typeof globalThis & {
__boxelErrorReporter: ErrorReporter;
};

export function setErrorReporter(reporter: ErrorReporter) {
globalWithErrorReporter.__boxelErrorReporter = reporter;
}

export function reportSentryError(error: Error) {
if (globalWithErrorReporter.__boxelErrorReporter) {
globalWithErrorReporter.__boxelErrorReporter(error);
}
}

export class CardError extends Error implements SerializedError {
detail: string;
status: number;
Expand Down
16 changes: 0 additions & 16 deletions packages/runtime-common/realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1790,22 +1790,6 @@ function lastModifiedHeader(
) as {} | { 'last-modified': string };
}

export type ErrorReporter = (error: Error) => void;

let globalWithErrorReporter = global as typeof globalThis & {
__boxelErrorReporter: ErrorReporter;
};

export function setErrorReporter(reporter: ErrorReporter) {
globalWithErrorReporter.__boxelErrorReporter = reporter;
}

export function reportError(error: Error) {
if (globalWithErrorReporter.__boxelErrorReporter) {
globalWithErrorReporter.__boxelErrorReporter(error);
}
}

export interface CardDefinitionResource {
id: string;
type: 'card-definition';
Expand Down

0 comments on commit de51074

Please sign in to comment.