diff --git a/jest.config.js b/jest.config.js index 9c2d926862..53daef8995 100644 --- a/jest.config.js +++ b/jest.config.js @@ -19,7 +19,8 @@ module.exports = { url: 'http://cozy.localhost:8080/' }, transform: { - '^.+\\.(ts|tsx|js|jsx)?$': 'babel-jest' + '^.+\\.(ts|tsx|js|jsx)?$': 'babel-jest', + '^.+\\.webapp$': '/test/jestLib/json-transformer.js' }, transformIgnorePatterns: [ 'node_modules/(?!cozy-ui|cozy-harvest-lib|cozy-keys-lib|cozy-sharing|react-swipeable-views-core|copy-text-to-clipboard)' diff --git a/package.json b/package.json index 6af3960714..6f2a88193a 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ }, "homepage": "https://github.com/cozy/cozy-home#readme", "dependencies": { + "@sentry/react": "7.118.0", "cozy-client": "^48.8.0", "cozy-device-helper": "2.7.0", "cozy-doctypes": "1.83.8", diff --git a/src/containers/App.jsx b/src/containers/App.jsx index 5ffb53e001..0f9abf8a6a 100644 --- a/src/containers/App.jsx +++ b/src/containers/App.jsx @@ -1,6 +1,6 @@ /* global __SIMULATE_FLAGSHIP__ */ import React, { useEffect, useState } from 'react' -import { Navigate, Route, Routes } from 'react-router-dom' +import { Navigate, Route } from 'react-router-dom' import flag, { enable as enableFlags } from 'cozy-flags' import minilog from 'cozy-minilog' @@ -41,6 +41,7 @@ import { } from 'queries' import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' import SectionDialog from 'components/Sections/SectionDialog' +import { SentryRoutes } from 'lib/sentry' window.flag = window.flag || flag window.minilog = minilog @@ -152,7 +153,7 @@ const App = ({ accounts, konnectors, triggers }) => { )} {!isFetching && ( <> - + { } /> } /> - + )} diff --git a/src/lib/sentry.js b/src/lib/sentry.js new file mode 100644 index 0000000000..53ce50a278 --- /dev/null +++ b/src/lib/sentry.js @@ -0,0 +1,36 @@ +import * as Sentry from '@sentry/react' +import { useEffect } from 'react' +import { + Routes, + useLocation, + useNavigationType, + createRoutesFromChildren, + matchRoutes +} from 'react-router-dom' + +// eslint-disable-next-line import-alias/import-alias +import manifest from '../../manifest.webapp' + +Sentry.init({ + dsn: 'https://5d6007cd544cf04ebfb4ea19c4d539e9@errors.cozycloud.cc/82', + environment: process.env.NODE_ENV, + release: manifest.version, + integrations: [ + // We also want to capture the `console.error` to, among other things, + // report the logs present in the `try/catch + Sentry.captureConsoleIntegration({ levels: ['error'] }), + Sentry.reactRouterV6BrowserTracingIntegration({ + useEffect, + useLocation, + useNavigationType, + createRoutesFromChildren, + matchRoutes + }) + ], + tracesSampleRate: 0.1, + // React log these warnings(bad Proptypes), in a console.error, + // it is not relevant to report this type of information to Sentry + ignoreErrors: [/^Warning: /] +}) + +export const SentryRoutes = Sentry.withSentryReactRouterV6Routing(Routes) diff --git a/test/jestLib/json-transformer.js b/test/jestLib/json-transformer.js new file mode 100644 index 0000000000..25a7fd8463 --- /dev/null +++ b/test/jestLib/json-transformer.js @@ -0,0 +1,5 @@ +module.exports = { + process: src => ({ + code: `module.exports = ${src};` + }) +} diff --git a/yarn.lock b/yarn.lock index 218407907b..2fd2ace9b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3406,6 +3406,48 @@ dependencies: any-observable "^0.3.0" +"@sentry-internal/feedback@7.118.0": + version "7.118.0" + resolved "https://registry.yarnpkg.com/@sentry-internal/feedback/-/feedback-7.118.0.tgz#5b4b13ba514452d07a22ec8c66c2e4bc2091d8e6" + integrity sha512-IYOGRcqIqKJJpMwBBv+0JTu0FPpXnakJYvOx/XEa/SNyF5+l7b9gGEjUVWh1ok50kTLW/XPnpnXNAGQcoKHg+w== + dependencies: + "@sentry/core" "7.118.0" + "@sentry/types" "7.118.0" + "@sentry/utils" "7.118.0" + +"@sentry-internal/replay-canvas@7.118.0": + version "7.118.0" + resolved "https://registry.yarnpkg.com/@sentry-internal/replay-canvas/-/replay-canvas-7.118.0.tgz#d9741962439a85525e660973042c801c569ea9e4" + integrity sha512-XxHlCClvrxmVKpiZetFYyiBaPQNiojoBGFFVgbbWBIAPc+fWeLJ2BMoQEBjn/0NA/8u8T6lErK5YQo/eIx9+XQ== + dependencies: + "@sentry/core" "7.118.0" + "@sentry/replay" "7.118.0" + "@sentry/types" "7.118.0" + "@sentry/utils" "7.118.0" + +"@sentry-internal/tracing@7.118.0": + version "7.118.0" + resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.118.0.tgz#1a96ea745db818e20c2f8273d317f284a416a90a" + integrity sha512-dERAshKlQLrBscHSarhHyUeGsu652bDTUN1FK0m4e3X48M3I5/s+0N880Qjpe5MprNLcINlaIgdQ9jkisvxjfw== + dependencies: + "@sentry/core" "7.118.0" + "@sentry/types" "7.118.0" + "@sentry/utils" "7.118.0" + +"@sentry/browser@7.118.0": + version "7.118.0" + resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-7.118.0.tgz#2395b47d693f7e49057552997d5125fc1a3d3448" + integrity sha512-8onDOFV1VLEoBuqA5yaJeR3FF1JNuxr5C7p1oN3OwY724iTVqQnOLmZKZaSnHV3RkY67wKDGQkQIie14sc+42g== + dependencies: + "@sentry-internal/feedback" "7.118.0" + "@sentry-internal/replay-canvas" "7.118.0" + "@sentry-internal/tracing" "7.118.0" + "@sentry/core" "7.118.0" + "@sentry/integrations" "7.118.0" + "@sentry/replay" "7.118.0" + "@sentry/types" "7.118.0" + "@sentry/utils" "7.118.0" + "@sentry/browser@^6.0.1": version "6.13.2" resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-6.13.2.tgz#8b731ecf8c3cdd92a4b6893a26f975fd5844056d" @@ -3427,6 +3469,14 @@ "@sentry/utils" "6.13.2" tslib "^1.9.3" +"@sentry/core@7.118.0": + version "7.118.0" + resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.118.0.tgz#1549b49621bc05a8df16c3546793a299b0638559" + integrity sha512-ol0xBdp3/K11IMAYSQE0FMxBOOH9hMsb/rjxXWe0hfM5c72CqYWL3ol7voPci0GELJ5CZG+9ImEU1V9r6gK64g== + dependencies: + "@sentry/types" "7.118.0" + "@sentry/utils" "7.118.0" + "@sentry/hub@6.13.2": version "6.13.2" resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.13.2.tgz#ebc66fd55c96c7686a53ffd3521b6a63f883bb79" @@ -3436,6 +3486,16 @@ "@sentry/utils" "6.13.2" tslib "^1.9.3" +"@sentry/integrations@7.118.0": + version "7.118.0" + resolved "https://registry.yarnpkg.com/@sentry/integrations/-/integrations-7.118.0.tgz#f090db621979785c6dc44406da1f72653fa0617c" + integrity sha512-C2rR4NvIMjokF8jP5qzSf1o2zxDx7IeYnr8u15Kb2+HdZtX559owALR0hfgwnfeElqMhGlJBaKUWZ48lXJMzCQ== + dependencies: + "@sentry/core" "7.118.0" + "@sentry/types" "7.118.0" + "@sentry/utils" "7.118.0" + localforage "^1.8.1" + "@sentry/minimal@6.13.2": version "6.13.2" resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.13.2.tgz#de3ecc62b9463bf56ccdbcf4c75f7ea1aeeebc11" @@ -3445,11 +3505,37 @@ "@sentry/types" "6.13.2" tslib "^1.9.3" +"@sentry/react@7.118.0": + version "7.118.0" + resolved "https://registry.yarnpkg.com/@sentry/react/-/react-7.118.0.tgz#88ae04e1abec1fd9a242ad6d852a1fe5e6851ad4" + integrity sha512-oEYe5TGk8S7YzPsFqDf4xDHjfzs35/QFE+dou3S2d24OYpso8Tq4C5f1VzYmnOOyy85T7JNicYLSo0n0NSJvQg== + dependencies: + "@sentry/browser" "7.118.0" + "@sentry/core" "7.118.0" + "@sentry/types" "7.118.0" + "@sentry/utils" "7.118.0" + hoist-non-react-statics "^3.3.2" + +"@sentry/replay@7.118.0": + version "7.118.0" + resolved "https://registry.yarnpkg.com/@sentry/replay/-/replay-7.118.0.tgz#ae55b7e14b85f22256dcc5a96bf3e63b252c1acf" + integrity sha512-boQfCL+1L/tSZ9Huwi00+VtU+Ih1Lcg8HtxBuAsBCJR9pQgUL5jp7ECYdTeeHyCh/RJO7JqV1CEoGTgohe10mA== + dependencies: + "@sentry-internal/tracing" "7.118.0" + "@sentry/core" "7.118.0" + "@sentry/types" "7.118.0" + "@sentry/utils" "7.118.0" + "@sentry/types@6.13.2": version "6.13.2" resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.13.2.tgz#8388d5b92ea8608936e7aae842801dc90e0184e6" integrity sha512-6WjGj/VjjN8LZDtqJH5ikeB1o39rO1gYS6anBxiS3d0sXNBb3Ux0pNNDFoBxQpOhmdDHXYS57MEptX9EV82gmg== +"@sentry/types@7.118.0": + version "7.118.0" + resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.118.0.tgz#ca3ab06912f60bc2a7ccf2d2e5ccf43985851aef" + integrity sha512-2drqrD2+6kgeg+W/ycmiti3G4lJrV3hGjY9PpJ3bJeXrh6T2+LxKPzlgSEnKFaeQWkXdZ4eaUbtTXVebMjb5JA== + "@sentry/utils@6.13.2": version "6.13.2" resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.13.2.tgz#fb8010e7b67cc8c084d8067d64ef25289269cda5" @@ -3458,6 +3544,13 @@ "@sentry/types" "6.13.2" tslib "^1.9.3" +"@sentry/utils@7.118.0": + version "7.118.0" + resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.118.0.tgz#bfc60826fe3d5d2ae7338ec6ac1f06c20beb179e" + integrity sha512-43qItc/ydxZV1Zb3Kn2M54RwL9XXFa3IAYBO8S82Qvq5YUYmU2AmJ1jgg7DabXlVSWgMA1HntwqnOV3JLaEnTQ== + dependencies: + "@sentry/types" "7.118.0" + "@sinclair/typebox@^0.24.1": version "0.24.28" resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.28.tgz#15aa0b416f82c268b1573ab653e4413c965fe794" @@ -11626,7 +11719,7 @@ loader-utils@^2.0.0: emojis-list "^3.0.0" json5 "^2.1.2" -localforage@^1.10.0: +localforage@^1.10.0, localforage@^1.8.1: version "1.10.0" resolved "https://registry.yarnpkg.com/localforage/-/localforage-1.10.0.tgz#5c465dc5f62b2807c3a84c0c6a1b1b3212781dd4" integrity sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==