Skip to content

Commit

Permalink
feat: better sentry error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
acaldas committed Jul 22, 2024
1 parent 89ba91b commit a97591a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
7 changes: 4 additions & 3 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const createApp = (): { app: Express; router: express.Router } => {
],
tracesSampleRate: 1.0,
ignoreErrors: [
/Transmitter .+ not found/,
/Transmitter(?: .+)? not found/,
/^Failed to fetch strands$/,
/Drive with id .+ not found/,
/Document with id .+ not found/,
Expand Down Expand Up @@ -79,8 +79,9 @@ export const createApp = (): { app: Express; router: express.Router } => {
res.setHeader('Content-Type', 'text/html');
const basePath =
process.env.BASE_PATH === '/' ? '' : process.env.BASE_PATH || '';
const endpoint = `${basePath}${req.params.driveId !== undefined ? `/d/${req.params.driveId}` : '/drives'
}`;
const endpoint = `${basePath}${
req.params.driveId !== undefined ? `/d/${req.params.driveId}` : '/drives'
}`;
res.send(
renderPlaygroundPage({
endpoint: endpoint,
Expand Down
2 changes: 1 addition & 1 deletion api/src/graphql/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function loggerPlugin(): ApolloServerPlugin<Context> {
return {
async didEncounterErrors(c) {
c.errors?.forEach((e) => {
c.contextValue.apolloLogger.error({ error: e }, e.message);
c.contextValue.apolloLogger.error({ err: e }, e.message);
});
},
};
Expand Down
16 changes: 11 additions & 5 deletions api/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import path from 'path';
import pino from 'pino';
import pinoHttp from 'pino-http';
import * as Sentry from '@sentry/node';
import { loggerConfig } from '../logger.config';
import { isDevelopment } from './env';

const {
moduleFilter, prefixFilter, logLevel, httpLogLevel,
} = loggerConfig;
const { moduleFilter, prefixFilter, logLevel, httpLogLevel } = loggerConfig;

export const dirname = (() => {
if (typeof __dirname !== 'undefined') {
Expand Down Expand Up @@ -72,13 +71,20 @@ if (process.env.SENTRY_DSN) {
target: 'pino-sentry-transport',
options: {
sentry: {
integrations: [
Sentry.extraErrorDataIntegration({
depth: 15,
captureErrorCause: true,
}),
],
dsn: process.env.SENTRY_DSN,
environment: process.env.SENTRY_ENV ?? 'dev',
ignoreErrors: [
/Transmitter .+ not found/,
/Transmitter(?: .+)? not found/,
/^Failed to fetch strands$/,
/Drive with id .+ not found/,
/Document with id .+ not found/,
'Drive not found',
],
// additional options for sentry
},
Expand Down Expand Up @@ -106,7 +112,7 @@ const logger = pino({

export const getChildLogger = (
options?: pino.ChildLoggerOptions,
bindings?: pino.Bindings,
bindings?: pino.Bindings
) => {
// get caller module of this function
const caller = Error().stack?.split('at ').at(2)?.trim().split(':')[0] || '';
Expand Down

0 comments on commit a97591a

Please sign in to comment.