From 4b91dffd6050f405fcf7e0b8731c1f104d70b1b7 Mon Sep 17 00:00:00 2001 From: AykutSarac Date: Mon, 22 May 2023 11:49:38 +0300 Subject: [PATCH] feat: implement sentry cli --- .github/workflows/nextjs.yml | 15 +++++++++++++++ .gitignore | 4 +++- next.config.js | 21 ++++++++++++++------- sentry.client.config.ts | 30 ++++++++++++++++++++++++++++++ sentry.edge.config.ts | 3 +++ sentry.server.config.ts | 3 +++ src/pages/_app.tsx | 9 --------- 7 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 sentry.client.config.ts create mode 100644 sentry.edge.config.ts create mode 100644 sentry.server.config.ts diff --git a/.github/workflows/nextjs.yml b/.github/workflows/nextjs.yml index f8b8b96..d4ad569 100644 --- a/.github/workflows/nextjs.yml +++ b/.github/workflows/nextjs.yml @@ -100,3 +100,18 @@ jobs: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v1 + + # Sentry job + sentry: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Sentry Release + uses: getsentry/action-release@v1.0.0 + env: + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + SENTRY_ORG: ${{ secrets.SENTRY_ORG }} + SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} + with: + environment: production + sourcemaps: ./out \ No newline at end of file diff --git a/.gitignore b/.gitignore index e1ae6ba..8aa75a4 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,6 @@ yarn-error.log* # PWA workers **/public/workbox-*.js **/public/sw.js -**/public/fallback-*.js \ No newline at end of file +**/public/fallback-*.js +# Sentry Auth Token +.sentryclirc diff --git a/next.config.js b/next.config.js index cb945ff..4ddc1de 100644 --- a/next.config.js +++ b/next.config.js @@ -1,9 +1,4 @@ -const withBundleAnalyzer = - process.env.ANALYZE === "true" - ? require("@next/bundle-analyzer")({ - enabled: process.env.ANALYZE === "true", - })() - : x => x; +const { withSentryConfig } = require("@sentry/nextjs"); /** * @type {import('next').NextConfig} @@ -16,4 +11,16 @@ const config = { }, }; -module.exports = withBundleAnalyzer(config); +module.exports = withSentryConfig( + config, + { + silent: true, + org: "aykut-sarac", + project: "json-crack", + }, + { + widenClientFileUpload: true, + hideSourceMaps: true, + disableLogger: true, + } +); diff --git a/sentry.client.config.ts b/sentry.client.config.ts new file mode 100644 index 0000000..af49fc8 --- /dev/null +++ b/sentry.client.config.ts @@ -0,0 +1,30 @@ +// This file configures the initialization of Sentry on the client. +// The config you add here will be used whenever a users loads a page in their browser. +// https://docs.sentry.io/platforms/javascript/guides/nextjs/ +import * as Sentry from "@sentry/nextjs"; + +Sentry.init({ + enabled: process.env.NODE_ENV === "development", + dsn: "https://d3345591295d4dd1b8c579b62003d939@o1284435.ingest.sentry.io/6495191", + + // Adjust this value in production, or use tracesSampler for greater control + tracesSampleRate: 0.2, + + // Setting this option to true will print useful information to the console while you're setting up Sentry. + debug: false, + + replaysOnErrorSampleRate: 1.0, + + // This sets the sample rate to be 10%. You may want this to be 100% while + // in development and sample at a lower rate in production + replaysSessionSampleRate: 0.1, + + // You can remove this option if you're not planning to use the Sentry Session Replay feature: + integrations: [ + new Sentry.Replay({ + // Additional Replay configuration goes in here, for example: + maskAllText: true, + blockAllMedia: true, + }), + ], +}); diff --git a/sentry.edge.config.ts b/sentry.edge.config.ts new file mode 100644 index 0000000..872c641 --- /dev/null +++ b/sentry.edge.config.ts @@ -0,0 +1,3 @@ +{ + /* empty */ +} diff --git a/sentry.server.config.ts b/sentry.server.config.ts new file mode 100644 index 0000000..872c641 --- /dev/null +++ b/sentry.server.config.ts @@ -0,0 +1,3 @@ +{ + /* empty */ +} diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 4d1473a..d8c32ac 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -3,7 +3,6 @@ import type { AppProps } from "next/app"; import localFont from "next/font/local"; import { ThemeProvider } from "styled-components"; import { MantineProvider } from "@mantine/core"; -import { init } from "@sentry/nextjs"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { Toaster } from "react-hot-toast"; import { GoogleAnalytics } from "src/components/GoogleAnalytics"; @@ -13,14 +12,6 @@ import { ExternalMode } from "src/layout/DevMode"; import { ModalController } from "src/layout/ModalController"; import useStored from "src/store/useStored"; -if (process.env.NODE_ENV !== "development") { - init({ - dsn: "https://d3345591295d4dd1b8c579b62003d939@o1284435.ingest.sentry.io/6495191", - tracesSampleRate: 0.25, - release: "production", - }); -} - const queryClient = new QueryClient({ defaultOptions: { queries: {