📝
Sentry
On this page
Ignore errors
ts
Sentry.init({dsn: "sentry_dsn",ignoreErrors: ['TypeError: Failed to fetch','TypeError: NetworkError when attempting to fetch resource.','TypeError: Cancelled','TypeError: Preflight response is not successful',// https://browserhow.com/how-to-fix-cannot-parse-response-in-safari-browser/'TypeError: cannot parse response'],});```## [Handling GraphQL Errors Using Sentry](https://blog.sentry.io/2020/07/22/handling-graphql-errors-using-sentry)### Reporting Errors to Sentry with Apollo Server```jsdidEncounterErrors(ctx) {// If we couldn't parse the operation, don't// do anything hereif (!ctx.operation) {return;}for (const err of ctx.errors) {// Only report internal server errors,// all errors extending ApolloError should be user-facingif (err instanceof ApolloError) {continue;}// Add scoped report details and send to SentrySentry.withScope(scope => {// Annotate whether failing operation was query/mutation/subscriptionscope.setTag("kind", ctx.operation.operation);// Log query and variables as extras// (make sure to strip out sensitive data!)scope.setExtra("query", ctx.request.query);scope.setExtra("variables", ctx.request.variables);if (err.path) {// We can also add the path as breadcrumbscope.addBreadcrumb({category: "query-path",message: err.path.join(" > "),level: Sentry.Severity.Debug});}Sentry.captureException(err);});}}
Tracing Errors, End-To-End
js
// Retrieve the transaction ID from our request headersconst transactionId = ctx.request.http.headers.get("x-transaction-id");if (transactionId) {scope.setTransaction(transactionId);}// ...Sentry.captureException(err);