Skip to content

Commit

Permalink
Configure sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
ljowen committed Aug 29, 2024
1 parent e5d7982 commit 078215c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ yarn-error.log

package-lock.json
.nvmrc

# Sentry Config File
.env.sentry-build-plugin
9 changes: 8 additions & 1 deletion buildprocess/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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: [
{
Expand Down Expand Up @@ -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: {},
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions lib/Core/SentryErrorProvider.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions wwwroot/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down

0 comments on commit 078215c

Please sign in to comment.