Do not capture GraphQLError exceptions (#653)

This commit is contained in:
Kamil Kisiela 2022-11-15 10:21:30 +01:00 committed by GitHub
parent 9ac112db1e
commit 935cc59f6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -1,5 +1,6 @@
import * as Sentry from '@sentry/node';
import type { Span } from '@sentry/types';
import { GraphQLError } from 'graphql';
export type SentryContext = Parameters<Span['startChild']>[0] & {
captureException?: boolean;
@ -45,7 +46,9 @@ export function sentry(name: string, addToContext?: (...args: any[]) => SentryCo
return Promise.resolve(result);
},
error => {
Sentry.captureException(error);
if (!(error instanceof GraphQLError)) {
Sentry.captureException(error);
}
span.setStatus('internal_error');
span.finish();
return Promise.reject(error);

View file

@ -6,7 +6,7 @@ import { fastifyTRPCPlugin } from '@trpc/server/adapters/fastify/dist/trpc-serve
import { createRegistry, LogFn, Logger } from '@hive/api';
import { createStorage as createPostgreSQLStorage, createConnectionString } from '@hive/storage';
import got from 'got';
import { stripIgnoredCharacters } from 'graphql';
import { GraphQLError, stripIgnoredCharacters } from 'graphql';
import * as Sentry from '@sentry/node';
import { Dedupe, ExtraErrorData } from '@sentry/integrations';
import { internalApiRouter, createContext } from './api';
@ -30,7 +30,7 @@ export async function main() {
if (env.sentry) {
Sentry.init({
serverName: 'api',
enabled: !!env.sentry,
enabled: true,
environment: env.environment,
dsn: env.sentry.dsn,
tracesSampleRate: 1,
@ -71,6 +71,10 @@ export async function main() {
const errorObj = error instanceof Error ? error : errorLike instanceof Error ? errorLike : null;
if (errorObj instanceof GraphQLError) {
return;
}
if (errorObj instanceof Error) {
Sentry.captureException(errorObj, {
level,