From 8c69b3b9c48c5a7c4ccfd8a26e7b5fa806584e5c Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 29 Feb 2024 16:56:43 +0300 Subject: [PATCH] apps/web: add extra data for sentry --- apps/web/apollo/client.js | 2 +- apps/web/{config/apollo.js => apollo/link.js} | 20 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) rename apps/web/{config/apollo.js => apollo/link.js} (68%) diff --git a/apps/web/apollo/client.js b/apps/web/apollo/client.js index bde795e..b6cc104 100644 --- a/apps/web/apollo/client.js +++ b/apps/web/apollo/client.js @@ -1,4 +1,4 @@ -import { link } from '@/config/apollo'; +import { link } from './link'; import { ApolloClient, InMemoryCache } from '@apollo/client'; import { isServer } from 'tools/common'; diff --git a/apps/web/config/apollo.js b/apps/web/apollo/link.js similarity index 68% rename from apps/web/config/apollo.js rename to apps/web/apollo/link.js index 97d45b3..f7eea1b 100644 --- a/apps/web/config/apollo.js +++ b/apps/web/apollo/link.js @@ -1,5 +1,7 @@ -import getUrls from './urls'; -import { ApolloLink, HttpLink } from '@apollo/client'; +import getUrls from '@/config/urls'; +import { ApolloLink, from, HttpLink } from '@apollo/client'; +import { onError } from '@apollo/client/link/error'; +import { getCurrentScope } from '@sentry/nextjs'; const { URL_CRM_GRAPHQL } = getUrls(); @@ -42,4 +44,16 @@ const httpLink = new HttpLink({ uri: URL_CRM_GRAPHQL, }); -export const link = modifyDataLink.concat(httpLink); +const errorLink = onError(({ graphQLErrors, networkError, operation, response }) => { + const scope = getCurrentScope(); + scope.setTag('operationName', operation.operationName); + + scope.setExtras({ + graphQLErrors, + networkError, + operation, + response, + }); +}); + +export const link = from([errorLink, modifyDataLink, httpLink]);