From 1a7b68b647a8942e7183168a2406f87a835d03e5 Mon Sep 17 00:00:00 2001 From: Sophie Stadler Date: Thu, 15 Feb 2024 12:27:48 -0500 Subject: [PATCH] Add tag and fingerprint to graphql errors --- src/components/ErrorHandling/Sentry.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/components/ErrorHandling/Sentry.tsx b/src/components/ErrorHandling/Sentry.tsx index 09defe0d5a..896d5a078c 100644 --- a/src/components/ErrorHandling/Sentry.tsx +++ b/src/components/ErrorHandling/Sentry.tsx @@ -4,6 +4,7 @@ import { getCurrentHub, init, Replay, + setTag, withScope, } from "@sentry/react"; import type { Scope, SeverityLevel } from "@sentry/react"; @@ -46,6 +47,21 @@ const sendError = ( withScope((scope) => { setScope(scope, { level: severity, context: metadata }); + const { gqlErr, operationName } = metadata; + + // Add additional sorting for GraphQL errors + if (operationName) { + // A custom fingerprint allows for more intelligent grouping + const fingerprint = [operationName]; + if (gqlErr?.path && Array.isArray(gqlErr.path)) { + fingerprint.push(...gqlErr.path); + } + scope.setFingerprint(fingerprint); + + // Apply tag, which is a searchable/filterable property + setTag("operationName", metadata.operationName); + } + captureException(err); }); };