Skip to content

Commit

Permalink
Add sentry source map tracking and release (#4731)
Browse files Browse the repository at this point in the history
* Add sentry source map tracking and release

* Throw error

* Remove old scripts

* Remove throw button

* Add changeset

* Fix sentry in storybook
  • Loading branch information
poulch authored Mar 18, 2024
1 parent 31e4575 commit 9cdb1f6
Show file tree
Hide file tree
Showing 9 changed files with 437 additions and 202 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-plants-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Enable sourcemaps export to Senty
9 changes: 8 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ const config: StorybookConfig = {
},

async viteFinal(config) {
config.plugins = await withoutVitePlugins(config.plugins, ["vite:html"]);
config.plugins = await withoutVitePlugins(config.plugins, [
"vite:html",
"sentry-telemetry-plugin",
"sentry-vite-release-injection-plugin",
"sentry-debug-id-upload-plugin",
"sentry-vite-debug-id-injection-plugin",
"sentry-vite-debug-id-upload-plugin",
]);

return mergeConfig(config, {
build: {
Expand Down
567 changes: 402 additions & 165 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@saleor/macaw-ui-next": "npm:@saleor/[email protected]",
"@saleor/sdk": "0.6.0",
"@sentry/react": "^7.83.0",
"@sentry/vite-plugin": "^2.15.0",
"@types/faker": "^5.1.6",
"@uiw/react-color-hue": "0.0.34",
"@uiw/react-color-material": "^0.1.0",
Expand Down Expand Up @@ -317,9 +318,6 @@
"dev": "vite --host",
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 vite build",
"preview": "vite preview",
"sentry:inject": "sentry-cli sourcemaps inject build/dashboard",
"sentry:upload": "sentry-cli sourcemaps upload build/dashboard",
"sentry:clean": "node scripts/removeSourcemaps.js",
"build-storybook": "cross-env NODE_OPTIONS=--max-old-space-size=6144 storybook build -o build/storybook",
"build-types": "node scripts/build-types.js",
"build-flags": "node scripts/build-flags.js",
Expand Down Expand Up @@ -348,7 +346,6 @@
"lint": "eslint \"src/**/*.@(tsx|ts|jsx|js)\" --fix",
"lint:check-progress": "eslint-nibble \"src/**/*.@(tsx|ts|jsx|js)\"",
"prebuild": "npm run build-types",
"postbuild": "./scripts/sentry-upload.sh",
"predev": "npm run build-types",
"release": "echo $npm_package_version | xargs git tag && git push --follow-tags",
"prepare": "is-ci || husky install",
Expand Down
16 changes: 0 additions & 16 deletions scripts/removeSourcemaps.js

This file was deleted.

10 changes: 0 additions & 10 deletions scripts/sentry-upload.sh

This file was deleted.

2 changes: 2 additions & 0 deletions src/services/errorTracking/adapters/Sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TrackerMethods } from "../types";
interface Config {
dsn: string;
environment?: string;
release?: string;
}

export const SentryAdapter = (config: Config): TrackerMethods => {
Expand All @@ -13,6 +14,7 @@ export const SentryAdapter = (config: Config): TrackerMethods => {
Sentry.init({
dsn: config.dsn,
environment: config.environment,
release: config.release,
ignoreErrors: [
"Editor's content can not be saved in read-only mode",
"ResizeObserver loop completed with undelivered notifications",
Expand Down
1 change: 1 addition & 0 deletions src/services/errorTracking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const errorTracker = ErrorTrackerFactory(
SentryAdapter({
dsn: process.env.SENTRY_DSN,
environment: process.env.ENVIRONMENT,
release: process.env.RELEASE_NAME,
}),
);

Expand Down
24 changes: 18 additions & 6 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* eslint-disable no-console */
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
import { sentryVitePlugin } from "@sentry/vite-plugin";
import react from "@vitejs/plugin-react-swc";
import { CodeInspectorPlugin } from "code-inspector-plugin";
import { copyFileSync, mkdirSync } from "fs";
import path from "path";
import nodePolyfills from "rollup-plugin-polyfill-node";
import { defineConfig, loadEnv, searchForWorkspaceRoot } from "vite";
import { createHtmlPlugin } from "vite-plugin-html";
import { VitePWA } from "vite-plugin-pwa";
import { CodeInspectorPlugin } from 'code-inspector-plugin';

const copyOgImage = () => ({
name: "copy-og-image",
Expand Down Expand Up @@ -45,20 +46,25 @@ export default defineConfig(({ command, mode }) => {
FLAGS_SERVICE_ENABLED,
LOCALE_CODE,
POSTHOG_KEY,
POSTHOG_HOST
POSTHOG_HOST,
SENTRY_AUTH_TOKEN,
SENTRY_ORG,
SENTRY_PROJECT,
// eslint-disable-next-line camelcase
npm_package_version,
} = env;

const base = STATIC_URL ?? "/";
const featureFlagsEnvs = Object.fromEntries(
Object.entries(env).filter(([flagKey]) => flagKey.startsWith("FF_")),
);

const sourcemap = SKIP_SOURCEMAPS ? false : true;
const sourcemap = !SKIP_SOURCEMAPS;

const plugins = [
react(),
CodeInspectorPlugin({
bundler: 'vite',
bundler: "vite",
}),
createHtmlPlugin({
entry: path.resolve(__dirname, "src", "index.tsx"),
Expand Down Expand Up @@ -94,7 +100,6 @@ export default defineConfig(({ command, mode }) => {
copyOgImage(),
];


if (!isDev) {
console.log("Enabling service worker...");

Expand All @@ -113,6 +118,11 @@ export default defineConfig(({ command, mode }) => {
srcDir: path.resolve(__dirname),
filename: "sw.js",
}),
sentryVitePlugin({
authToken: SENTRY_AUTH_TOKEN,
org: SENTRY_ORG,
project: SENTRY_PROJECT,
}),
);
}

Expand Down Expand Up @@ -157,7 +167,9 @@ export default defineConfig(({ command, mode }) => {
SENTRY_RELEASE,
STATIC_URL,
POSTHOG_KEY,
POSTHOG_HOST
POSTHOG_HOST,
// eslint-disable-next-line camelcase
RELEASE_NAME: npm_package_version,
},
},
build: {
Expand Down

0 comments on commit 9cdb1f6

Please sign in to comment.