Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1561 from iFixit/turn-on-sentry-auto-instrument
Browse files Browse the repository at this point in the history
Sentry: Turn on auto instrument server funcs
  • Loading branch information
deltuh-vee authored Apr 11, 2023
2 parents 75295ae + 75152ef commit 76203fa
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 85 deletions.
3 changes: 1 addition & 2 deletions frontend/lib/shopify-storefront-sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ export function getServerShopifyStorefrontSdk(shop: ShopCredentials) {
scope.setExtra('query', doc);
scope.setExtra('variables', variables);
scope.setExtra('errors', result.errors);
Sentry.captureException(new Error(errorMessage));
throw new Error(errorMessage);
});
throw new Error(errorMessage);
}
return result.data;
};
Expand Down
4 changes: 1 addition & 3 deletions frontend/lib/strapi-sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ const requester: Requester = async <R, V>(
scope.setExtra('query', doc);
scope.setExtra('variables', variables);
scope.setExtra('errors', result.errors);
Sentry.captureException(
new Error('Strapi SDK GraphQL query failed with errors')
);
throw new Error('Strapi SDK GraphQL query failed with errors');
});
}
throw new Error(`GraphQL query failed to execute: ${response.statusText}`);
Expand Down
1 change: 0 additions & 1 deletion frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ const moduleExports = {
return config;
},
sentry: {
autoInstrumentServerFunctions: false,
// Upload artifacts in dist/framework as well; this includes sourcemaps
// for react and other next.js code
widenClientFileUpload: true,
Expand Down
65 changes: 0 additions & 65 deletions frontend/pages/_error.js

This file was deleted.

38 changes: 38 additions & 0 deletions frontend/pages/_error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* NOTE: This requires `@sentry/nextjs` version 7.3.0 or higher.
*
* This page is loaded by Nextjs:
* - on the server, when data-fetching methods throw or reject
* - on the client, when `getInitialProps` throws or rejects
* - on the client, when a React lifecycle method throws or rejects, and it's
* caught by the built-in Nextjs error boundary
*
* See:
* - https://nextjs.org/docs/basic-features/data-fetching/overview
* - https://nextjs.org/docs/api-reference/data-fetching/get-initial-props
* - https://reactjs.org/docs/error-boundaries.html
*/

import * as Sentry from '@sentry/nextjs';
import type { NextPage } from 'next';
import type { ErrorProps } from 'next/error';
import NextErrorComponent from 'next/error';

const CustomErrorComponent: NextPage<ErrorProps> = (props) => {
// If you're using a Nextjs version prior to 12.2.1, uncomment this to
// compensate for https://github.com/vercel/next.js/issues/8592
// Sentry.captureUnderscoreErrorException(props);

return <NextErrorComponent statusCode={props.statusCode} />;
};

CustomErrorComponent.getInitialProps = async (contextData) => {
// In case this is running in a serverless function, await this in order to give Sentry
// time to send the error before the lambda exits
await Sentry.captureUnderscoreErrorException(contextData);

// This will contain the status code of the response
return NextErrorComponent.getInitialProps(contextData);
};

export default CustomErrorComponent;
7 changes: 0 additions & 7 deletions packages/sentry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ export const applySentryFetchMiddleware = () => {
}
};

export const reportException: CaptureWithContextFn = (e, context) => {
Sentry.captureException(e, (scope) => {
scope.setContext('request', context);
return scope;
});
};

const withSentry: FetchMiddleware =
(fetcher, shouldSkipRequest) => async (input, init) => {
if (shouldSkipRequest?.(input, init)) {
Expand Down
1 change: 0 additions & 1 deletion packages/shopify-storefront-client/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { reportException } from '@ifixit/sentry';
import * as React from 'react';

interface ShopifyStorefrontClientOptions {
Expand Down
3 changes: 0 additions & 3 deletions packages/shopify-storefront-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"main": "./index.tsx",
"types": "./index.tsx",
"license": "MIT",
"dependencies": {
"@ifixit/sentry": "workspace:*"
},
"devDependencies": {
"@types/react": "18.0.24",
"@types/react-dom": "18.0.8",
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 comments on commit 76203fa

@vercel
Copy link

@vercel vercel bot commented on 76203fa Apr 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-commerce-prod – ./frontend

react-commerce-prod.vercel.app
react-commerce-prod-ifixit.vercel.app
react-commerce-prod-git-main-ifixit.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 76203fa Apr 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-commerce – ./frontend

react-commerce.vercel.app
react-commerce-git-main-ifixit.vercel.app
react-commerce-ifixit.vercel.app

Please sign in to comment.