From c6b3d9f39965d5f74b363fec45338af101f02111 Mon Sep 17 00:00:00 2001 From: Mitan Omar Date: Wed, 31 Jan 2024 14:00:40 +0100 Subject: [PATCH] feat: sentry integration --- app/app.js | 48 +++++++++++++++ config/environment.js | 28 ++++++++- package.json | 8 ++- pnpm-lock.yaml | 135 ++++++++++++++++++++++++++++++++++++------ 4 files changed, 198 insertions(+), 21 deletions(-) diff --git a/app/app.js b/app/app.js index 8cb0e0fd2..7f0a786d0 100644 --- a/app/app.js +++ b/app/app.js @@ -1,6 +1,8 @@ import Application from "@ember/application"; +import * as Sentry from "@sentry/ember"; import loadInitializers from "ember-load-initializers"; import Resolver from "ember-resolver"; +import fastRedact from "fast-redact"; import ResizeObserver from "resize-observer-polyfill"; import config from "timed/config/environment"; // simplebar setup @@ -8,6 +10,52 @@ import config from "timed/config/environment"; import "simplebar"; import "simplebar/dist/simplebar.css"; +const redact = fastRedact({ + paths: [ + "user.email", + "user.family_name", + "user.given_name", + "user.address", + "user.postalCode", + "user.city", + ], + serialize: false, +}); + +if (config["@sentry/ember"]) { + const sentryConfig = config["@sentry/ember"].sentry; + Sentry.init({ + ...sentryConfig, + transport: Sentry.makeBrowserOfflineTransport(Sentry.makeFetchTransport), + beforeSend(_event, hint) { + const event = redact(_event); + // ignore this differentiation in dev environment + if (event.environment === "production") { + if (window.location.hostname === "test.timed.adfinis.com") { + event.environment = "staging"; + } + } + + const exception = hint.originalException; + if ( + exception && + Array.isArray(exception.errors) && + exception.errors.every((e) => e.status === 401) + ) { + event.level = "info"; + } + + if ( + config.SENTRY_IGNORE && + config.SENTRY_IGNORE.includes(hint.originalException.name) + ) { + return null; + } + return event; + }, + }); +} + if (!window.ResizeObserver) { window.ResizeObserver = ResizeObserver; } diff --git a/config/environment.js b/config/environment.js index 770040050..dcdb0f31c 100644 --- a/config/environment.js +++ b/config/environment.js @@ -1,5 +1,4 @@ /* jshint node: true */ - module.exports = function (environment) { const ENV = { modulePrefix: "timed", @@ -62,6 +61,33 @@ module.exports = function (environment) { }, }; + if (process.env.SENTRY_DSN) { + ENV["@sentry/ember"] = { + // Will silence Ember.onError warning without the need of using Ember debugging tools. + ignoreEmberOnErrorWarning: false, + + // All runloop queue durations will be added as spans. + minimumRunloopQueueDuration: 0, + + // Will disable automatic instrumentation for components. + // disableInstrumentComponents: true, + + // All (non-glimmer) component render durations will be added as spans. + minimumComponentRenderDuration: 0, + + // All component definitions will be added as spans. + enableComponentDefinition: true, + sentry: { + environment, + dsn: process.env.SENTRY_DSN, + debug: environment !== "production", + tracesSampleRate: 0.01, + maxBreadcrumbs: 20, + }, + }; + ENV.SENTRY_IGNORE = ["TransitionAborted"]; + } + if (environment === "development") { ENV["ember-simple-auth-oidc"].host = "http://timed.local/auth/realms/timed/protocol/openid-connect"; diff --git a/package.json b/package.json index 8b2d5732f..226f746fe 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "@html-next/vertical-collection": "4.0.2", "@semantic-release/changelog": "^6.0.3", "@semantic-release/git": "^10.0.1", + "@sentry/ember": "^7.98.0", "broccoli-asset-rev": "3.0.0", "broccoli-funnel": "^3.0.8", "downloadjs": "1.4.7", @@ -88,7 +89,7 @@ "ember-cli-update": "1.0.1", "ember-component-css": "0.8.1", "ember-composable-helpers": "5.0.0", - "ember-concurrency": "2.3.4", + "ember-concurrency": "^2.3.7", "ember-data": "4.4.0", "ember-decorators": "6.1.1", "ember-event-helpers": "^0.1.1", @@ -139,7 +140,7 @@ "resize-observer-polyfill": "^1.5.1", "sass": "1.58.3", "semantic-release": "21.0.7", - "shepherd.js": "^11.1.1", + "shepherd.js": "^11.2.0", "simplebar": "^6.2.5", "tracked-built-ins": "3.1.1", "tracked-toolbox": "2.0.0", @@ -165,5 +166,8 @@ "marked" ] } + }, + "dependencies": { + "fast-redact": "^3.3.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1fb5a0ade..58e4e15e3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,11 @@ settings: overrides: ember-concurrency: ^2.1.1 +dependencies: + fast-redact: + specifier: ^3.3.0 + version: 3.3.0 + devDependencies: '@adfinis/eslint-config': specifier: 2.0.0 @@ -77,6 +82,9 @@ devDependencies: '@semantic-release/git': specifier: ^10.0.1 version: 10.0.1(semantic-release@21.0.7) + '@sentry/ember': + specifier: ^7.98.0 + version: 7.98.0(webpack@5.76.2) broccoli-asset-rev: specifier: 3.0.0 version: 3.0.0 @@ -312,7 +320,7 @@ devDependencies: specifier: 21.0.7 version: 21.0.7 shepherd.js: - specifier: ^11.1.1 + specifier: ^11.2.0 version: 11.2.0 simplebar: specifier: ^6.2.5 @@ -3678,6 +3686,96 @@ packages: - supports-color dev: true + /@sentry-internal/feedback@7.98.0: + resolution: {integrity: sha512-t/mATvwkLcQLKRlx8SO5vlUjaadF6sT3lfR0PdWYyBy8qglbMTHDW4KP6JKh1gdzTVQGnwMByy+/4h9gy4AVzw==} + engines: {node: '>=12'} + dependencies: + '@sentry/core': 7.98.0 + '@sentry/types': 7.98.0 + '@sentry/utils': 7.98.0 + dev: true + + /@sentry-internal/replay-canvas@7.98.0: + resolution: {integrity: sha512-vAR6KIycyazaY9HwxG5UONrPTe8jeKtZr6k04svPC8OvcoI0xF+l1jMEYcarffuzKpZlPfssYb5ChHtKuXCB+Q==} + engines: {node: '>=12'} + dependencies: + '@sentry/core': 7.98.0 + '@sentry/replay': 7.98.0 + '@sentry/types': 7.98.0 + '@sentry/utils': 7.98.0 + dev: true + + /@sentry-internal/tracing@7.98.0: + resolution: {integrity: sha512-FnhD2uMLIAJvv4XsYPv3qsTTtxrImyLxiZacudJyaWFhxoeVQ8bKKbWJ/Ar68FAwqTtjXMeY5evnEBbRMcQlaA==} + engines: {node: '>=8'} + dependencies: + '@sentry/core': 7.98.0 + '@sentry/types': 7.98.0 + '@sentry/utils': 7.98.0 + dev: true + + /@sentry/browser@7.98.0: + resolution: {integrity: sha512-/MzTS31N2iM6Qwyh4PSpHihgmkVD5xdfE5qi1mTlwQZz5Yz8t7MdMriX8bEDPlLB8sNxl7+D6/+KUJO8akX0nQ==} + engines: {node: '>=8'} + dependencies: + '@sentry-internal/feedback': 7.98.0 + '@sentry-internal/replay-canvas': 7.98.0 + '@sentry-internal/tracing': 7.98.0 + '@sentry/core': 7.98.0 + '@sentry/replay': 7.98.0 + '@sentry/types': 7.98.0 + '@sentry/utils': 7.98.0 + dev: true + + /@sentry/core@7.98.0: + resolution: {integrity: sha512-baRUcpCNGyk7cApQHMfqEZJkXdvAKK+z/dVWiMqWc5T5uhzMnPE8/gjP1JZsMtJSQ8g5nHimBdI5TwOyZtxPaA==} + engines: {node: '>=8'} + dependencies: + '@sentry/types': 7.98.0 + '@sentry/utils': 7.98.0 + dev: true + + /@sentry/ember@7.98.0(webpack@5.76.2): + resolution: {integrity: sha512-iQzvh32VHxgLjOrXRehcgB6JtUeOxptggg/92dCbdHc0TtiU3lGyj7c0JBkH5c1FkB6S2JOTc7RcIgeAI6iQ4w==} + engines: {node: 14.* || 16.* || >= 18} + dependencies: + '@embroider/macros': 1.13.1 + '@sentry/browser': 7.98.0 + '@sentry/core': 7.98.0 + '@sentry/types': 7.98.0 + '@sentry/utils': 7.98.0 + ember-auto-import: 2.6.3(webpack@5.76.2) + ember-cli-babel: 7.26.11 + ember-cli-htmlbars: 6.2.0 + ember-cli-typescript: 5.2.1 + transitivePeerDependencies: + - '@glint/template' + - supports-color + - webpack + dev: true + + /@sentry/replay@7.98.0: + resolution: {integrity: sha512-CQabv/3KnpMkpc2TzIquPu5krpjeMRAaDIO0OpTj5SQeH2RqSq3fVWNZkHa8tLsADxcfLFINxqOg2jd1NxvwxA==} + engines: {node: '>=12'} + dependencies: + '@sentry-internal/tracing': 7.98.0 + '@sentry/core': 7.98.0 + '@sentry/types': 7.98.0 + '@sentry/utils': 7.98.0 + dev: true + + /@sentry/types@7.98.0: + resolution: {integrity: sha512-pc034ziM0VTETue4bfBcBqTWGy4w0okidtoZJjGVrYAfE95ObZnUGVj/XYIQ3FeCYWIa7NFN2MvdsCS0buwivQ==} + engines: {node: '>=8'} + dev: true + + /@sentry/utils@7.98.0: + resolution: {integrity: sha512-0/LY+kpHxItVRY0xPDXPXVsKRb95cXsGSQf8sVMtfSjz++0bLL1U4k7PFz1c5s2/Vk0B8hS6duRrgMv6dMIZDw==} + engines: {node: '>=8'} + dependencies: + '@sentry/types': 7.98.0 + dev: true + /@simple-dom/interface@1.4.0: resolution: {integrity: sha512-l5qumKFWU0S+4ZzMaLXFU8tQZsicHEMEyAxI5kDFGhJsRqDwe0a7/iPA/GdxlGyDKseQQAgIz5kzU7eXTrlSpA==} dev: true @@ -6588,7 +6686,7 @@ packages: resolution: {integrity: sha512-WHVocJYavUwVgVViC0ORikPHQquXwVh939TaelZ4WDqpWgTX/FsGhl/+P4qBUAGcRvtOgDgC+xftNWWp2RUTAQ==} hasBin: true dependencies: - caniuse-lite: 1.0.30001466 + caniuse-lite: 1.0.30001581 electron-to-chromium: 1.4.332 dev: true @@ -6597,7 +6695,7 @@ packages: engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true dependencies: - caniuse-lite: 1.0.30001518 + caniuse-lite: 1.0.30001581 electron-to-chromium: 1.4.480 node-releases: 2.0.13 update-browserslist-db: 1.0.11(browserslist@4.21.10) @@ -6608,7 +6706,7 @@ packages: engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true dependencies: - caniuse-lite: 1.0.30001466 + caniuse-lite: 1.0.30001581 electron-to-chromium: 1.4.332 node-releases: 2.0.10 update-browserslist-db: 1.0.10(browserslist@4.21.5) @@ -6810,17 +6908,13 @@ packages: resolution: {integrity: sha512-bsTwuIg/BZZK/vreVTYYbSWoe2F+71P7K5QGEX+pT250DZbfU1MQ5prOKpPR+LL6uWKK3KMwMCAS74QB3Um1uw==} dependencies: browserslist: 4.21.5 - caniuse-lite: 1.0.30001466 + caniuse-lite: 1.0.30001581 lodash.memoize: 4.1.2 lodash.uniq: 4.5.0 dev: true - /caniuse-lite@1.0.30001466: - resolution: {integrity: sha512-ewtFBSfWjEmxUgNBSZItFSmVtvk9zkwkl1OfRZlKA8slltRN+/C/tuGVrF9styXkN36Yu3+SeJ1qkXxDEyNZ5w==} - dev: true - - /caniuse-lite@1.0.30001518: - resolution: {integrity: sha512-rup09/e3I0BKjncL+FesTayKtPrdwKhUufQFd3riFw1hHg8JmIFoInYfB102cFcY/pPgGmdyl/iy+jgiDi2vdA==} + /caniuse-lite@1.0.30001581: + resolution: {integrity: sha512-whlTkwhqV2tUmP3oYhtNfaWGYHDdS3JYFQBKXxcUR9qqPWsRhFHhoISO2Xnl/g0xyKzht9mI1LZpiNWfMzHixQ==} dev: true /capture-exit@2.0.0: @@ -6949,7 +7043,7 @@ packages: normalize-path: 3.0.0 readdirp: 3.6.0 optionalDependencies: - fsevents: 2.3.2 + fsevents: 2.3.3 dev: true /chownr@1.1.3: @@ -10823,6 +10917,11 @@ packages: blank-object: 1.0.2 dev: true + /fast-redact@3.3.0: + resolution: {integrity: sha512-6T5V1QK1u4oF+ATxs1lWUmlEk6P2T9HqJG3e2DnHOdVgZy2rFJBoEnrIedcTXlkAHU/zKC+7KETJ+KGGKwxgMQ==} + engines: {node: '>=6'} + dev: false + /fast-sourcemap-concat@2.1.0: resolution: {integrity: sha512-L9uADEnnHOeF4U5Kc3gzEs3oFpNCFkiTJXvT+nKmR0zcFqHZJJbszWT7dv4t9558FJRGpCj8UxUpTgz2zwiIZA==} engines: {node: 10.* || >= 12.*} @@ -11318,12 +11417,12 @@ packages: requiresBuild: true dependencies: bindings: 1.5.0 - nan: 2.17.0 + nan: 2.18.0 dev: true optional: true - /fsevents@2.3.2: - resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==} + /fsevents@2.3.3: + resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} os: [darwin] requiresBuild: true @@ -14087,8 +14186,8 @@ packages: resolution: {integrity: sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==} dev: true - /nan@2.17.0: - resolution: {integrity: sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==} + /nan@2.18.0: + resolution: {integrity: sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==} requiresBuild: true dev: true optional: true @@ -16240,7 +16339,7 @@ packages: engines: {node: '>=10.0.0'} hasBin: true optionalDependencies: - fsevents: 2.3.2 + fsevents: 2.3.3 dev: true /route-recognizer@0.3.3: