Skip to content

Commit

Permalink
chore: improve apollo error report in Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Sep 5, 2024
1 parent f2b775f commit c5ac434
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions apps/backend/src/graphql/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,34 @@ const apolloSentryPlugin: ApolloServerPlugin = {
continue;
}

if (error.path && error.name === "GraphQLError") {
Sentry.withScope((scope) => {
scope.setTag("graphql", "exec_error");
scope.setExtras({
source: error.source && error.source.body,
positions: error.positions,
path: error.path,
});
Sentry.captureException(error);
Sentry.withScope((scope) => {
// Annotate the scope with the query and variables
scope.setExtras({
operationName: ctx.operationName,
variables: ctx.request.variables,
});
} else {
Sentry.withScope((scope) => {
scope.setTag("graphql", "wrong_query");
scope.setExtras({
source: error.source && error.source.body,
positions: error.positions,

if (error.path && error.name === "GraphQLError") {
Sentry.withScope((scope) => {
scope.setTag("graphql", "exec_error");
scope.setExtras({
source: error.source && error.source.body,
positions: error.positions,
path: error.path,
});
Sentry.captureException(error);
});
Sentry.captureMessage(`GraphQLWrongQuery: ${error.message}`);
});
}
} else {
Sentry.withScope((scope) => {
scope.setTag("graphql", "wrong_query");
scope.setExtras({
source: error.source && error.source.body,
positions: error.positions,
});
Sentry.captureMessage(`GraphQLWrongQuery: ${error.message}`);
});
}
});
}
},
};
Expand Down

0 comments on commit c5ac434

Please sign in to comment.