From 078215c2fa794abc5cec00a3cbad7d001bc9a6ad Mon Sep 17 00:00:00 2001 From: Lawrence Owen Date: Mon, 19 Aug 2024 16:57:29 +1000 Subject: [PATCH] Configure sentry --- .gitignore | 3 +++ buildprocess/webpack.config.js | 9 ++++++++- index.js | 3 +++ lib/Core/SentryErrorProvider.ts | 24 ++++++++++++++++++++++++ package.json | 2 ++ wwwroot/config.json | 19 +++++++++++++++++++ 6 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 lib/Core/SentryErrorProvider.ts diff --git a/.gitignore b/.gitignore index f124f4ef2..58b7612c8 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,6 @@ yarn-error.log package-lock.json .nvmrc + +# Sentry Config File +.env.sentry-build-plugin diff --git a/buildprocess/webpack.config.js b/buildprocess/webpack.config.js index 6b5566e8b..0ace45f58 100644 --- a/buildprocess/webpack.config.js +++ b/buildprocess/webpack.config.js @@ -5,6 +5,7 @@ var configureWebpackForTerriaJS = require("terriajs/buildprocess/configureWebpac var configureWebpackForPlugins = require("./configureWebpackForPlugins"); var MiniCssExtractPlugin = require("mini-css-extract-plugin"); var path = require("path"); +const { sentryWebpackPlugin } = require("@sentry/webpack-plugin"); module.exports = function (devMode, hot) { var config = { @@ -18,7 +19,7 @@ module.exports = function (devMode, hot) { sourcePrefix: "", // to avoid breaking multi-line string literals by inserting extra tabs. globalObject: "(self || window)" // to avoid breaking in web worker (https://github.com/webpack/webpack/issues/6642) }, - devtool: devMode ? "eval-cheap-module-source-map" : false, + devtool: "source-map", module: { rules: [ { @@ -148,6 +149,12 @@ module.exports = function (devMode, hot) { ignoreOrder: true, allChunks: true }) + // sentryWebpackPlugin({ + // authToken: process.env.SENTRY_AUTH_TOKEN, + // org: "lawrence-at", + // project: "terriamap-example", + // telemetry: false + // }) ], resolve: { alias: {}, diff --git a/index.js b/index.js index 6aabae7ed..baf9fa3e8 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,8 @@ import registerSearchProviders from "terriajs/lib/Models/SearchProviders/registe import defined from "terriajs-cesium/Source/Core/defined"; import loadPlugins from "./lib/Core/loadPlugins"; import plugins from "./plugins"; +import SentryErrorProvider from "./lib/Core/SentryErrorProvider"; +import SentryErrorServiceProvider from "./lib/Core/SentryErrorProvider"; // Register all types of catalog members in the core TerriaJS. If you only want to register a subset of them // (i.e. to reduce the size of your application if you don't actually use them all), feel free to copy a subset of @@ -68,6 +70,7 @@ module.exports = terria shareDataService: new ShareDataService({ terria: terria }), + errorService: new SentryErrorProvider(), beforeRestoreAppState: () => { // Load plugins before restoring app state because app state may // reference plugin components and catalog items. diff --git a/lib/Core/SentryErrorProvider.ts b/lib/Core/SentryErrorProvider.ts new file mode 100644 index 000000000..c2708ea8e --- /dev/null +++ b/lib/Core/SentryErrorProvider.ts @@ -0,0 +1,24 @@ +import TerriaError from "terriajs/lib/Core/TerriaError"; +import * as Sentry from "@sentry/react"; +import { ErrorServiceProvider } from "terriajs/lib/Models/ErrorServiceProviders/ErrorService"; +import { ConfigParameters } from "terriajs/lib/Models/Terria"; + +export default class SentryErrorServiceProvider + implements ErrorServiceProvider +{ + init(config: ConfigParameters) { + Sentry.init({ + ...config.errorService?.configuration + }); + console.log("sentry init"); + } + + error(_error: string | Error | TerriaError) { + console.log("sentry err"); + if (_error instanceof TerriaError) { + Sentry.captureException(_error.toError()); + } else { + Sentry.captureException(_error); + } + } +} diff --git a/package.json b/package.json index b2a915fb0..be90a9dc8 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,8 @@ "sass": "^1.66.1", "sass-loader": "^10", "semver": "^5.0.0", + "@sentry/react": "^8.22.0", + "@sentry/webpack-plugin": "^2.21.1", "style-loader": "^0.23.1", "svg-sprite-loader": "^6.0.11", "terriajs": "8.7.5", diff --git a/wwwroot/config.json b/wwwroot/config.json index c874fe106..f26347976 100644 --- a/wwwroot/config.json +++ b/wwwroot/config.json @@ -77,6 +77,25 @@ }, "fallbackLanguage": "en" }, + "errorService": { + "provider": "sentry", + "configuration": { + "dsn": "https://87c898683a4f6875b3209c9c81fb9cb7@o4507722649829376.ingest.us.sentry.io/4507722651205632", + // Performance Monitoring + "tracesSampleRate": 1.0, // Capture 100% of the transactions + // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled + "tracePropagationTargets": ["localhost"], + // Session Replay + "replaysSessionSampleRate": 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production. + "replaysOnErrorSampleRate": 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur. + // Set profilesSampleRate to 1.0 to profile every transaction. + // Since profilesSampleRate is relative to tracesSampleRate, + // the final profiling rate can be computed as tracesSampleRate * profilesSampleRate + // For example, a tracesSampleRate of 0.5 and profilesSampleRate of 0.5 would + // results in 25% of transactions being profiled (0.5*0.5=0.25) + "profilesSampleRate": 1.0 + } + }, "searchBarConfig": {}, "searchProviders": [ {