From b36eb6ef1b3b57ddf1f0ac0f7254f89fea71c2b8 Mon Sep 17 00:00:00 2001 From: cballevre Date: Wed, 7 Aug 2024 17:41:43 +0200 Subject: [PATCH] feat: Add Sentry with his new sdk --- package.json | 1 + src/lib/sentry.js | 39 +++++++ src/photos/components/AppRouter.jsx | 6 +- src/photos/targets/public/index.jsx | 7 +- yarn.lock | 165 ++++++++++++++++++++++------ 5 files changed, 177 insertions(+), 41 deletions(-) create mode 100644 src/lib/sentry.js diff --git a/package.json b/package.json index 6a965efc3..f12385520 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ }, "dependencies": { "@cozy/minilog": "1.0.0", + "@sentry/react": "7.118.0", "classnames": "2.3.1", "cozy-authentication": "2.10.10", "cozy-bar": "^12.2.4", diff --git a/src/lib/sentry.js b/src/lib/sentry.js new file mode 100644 index 000000000..ac3ca4afe --- /dev/null +++ b/src/lib/sentry.js @@ -0,0 +1,39 @@ +import * as Sentry from '@sentry/react' +import { useEffect } from 'react' +import { + Routes, + useLocation, + useNavigationType, + createRoutesFromChildren, + createHashRouter, + matchRoutes +} from 'react-router-dom' + +import appMetadata from 'photos/appMetadata' + +Sentry.init({ + dsn: 'https://3dbc84e226e3810df5ec86dde0e868f1@errors.cozycloud.cc/81', + environment: process.env.NODE_ENV, + release: appMetadata.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 sentryCreateBrowserRouter = + Sentry.wrapCreateBrowserRouter(createHashRouter) + +export const SentryRoutes = Sentry.withSentryReactRouterV6Routing(Routes) diff --git a/src/photos/components/AppRouter.jsx b/src/photos/components/AppRouter.jsx index 10f9f0cb1..796bd81f6 100644 --- a/src/photos/components/AppRouter.jsx +++ b/src/photos/components/AppRouter.jsx @@ -1,5 +1,5 @@ import React from 'react' -import { createHashRouter, Navigate, RouterProvider } from 'react-router-dom' +import { Navigate, RouterProvider } from 'react-router-dom' import { isFlagshipApp } from 'cozy-device-helper' import flag from 'cozy-flags' @@ -11,6 +11,8 @@ import Backup from '../ducks/backup' import { AlbumsView, AlbumPhotos, PhotosPicker } from '../ducks/albums' import { TimelinePhotosViewer, AlbumPhotosViewer } from './PhotosViewer' +import { sentryCreateBrowserRouter } from 'lib/sentry' + function ErrorBoundary() { // If there is error uncaugth we redirect to homepage return @@ -20,7 +22,7 @@ const getRouter = () => { const DEFAULT_ROUTE = flag('flagship.backup.enabled') && isFlagshipApp() ? 'backup' : 'photos' - return createHashRouter([ + return sentryCreateBrowserRouter([ { element: , children: [ diff --git a/src/photos/targets/public/index.jsx b/src/photos/targets/public/index.jsx index 17199c07f..1bcc0f875 100644 --- a/src/photos/targets/public/index.jsx +++ b/src/photos/targets/public/index.jsx @@ -10,11 +10,12 @@ import { Provider } from 'react-redux' import { createStore, applyMiddleware, combineReducers } from 'redux' import thunkMiddleware from 'redux-thunk' import { createLogger } from 'redux-logger' -import { HashRouter, Routes, Route, Navigate } from 'react-router-dom' +import { HashRouter, Route, Navigate } from 'react-router-dom' import CozyClient, { CozyProvider, RealTimeQueries } from 'cozy-client' import { RealtimePlugin } from 'cozy-realtime' import flag from 'cozy-flags' import AlertProvider from 'cozy-ui/transpiled/react/providers/Alert' +import { SentryRoutes } from 'lib/sentry' import { BarProvider } from 'cozy-bar' import { BreakpointsProvider } from 'cozy-ui/transpiled/react/providers/Breakpoints' @@ -75,7 +76,7 @@ async function init() { - + }> } /> - + diff --git a/yarn.lock b/yarn.lock index 87f82b537..e4e29ce4d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3225,58 +3225,151 @@ resolved "https://registry.yarnpkg.com/@remix-run/router/-/router-1.7.2.tgz#cba1cf0a04bc04cb66027c51fa600e9cbc388bc8" integrity sha512-7Lcn7IqGMV+vizMPoEl5F0XDshcdDYtMI6uJLQdQz5CfZAwy3vvGKYSUk789qndt5dEC4HfSjviSYlSoHGL2+A== +"@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.0.2" - resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-6.0.2.tgz#6e886ccd2067291d242adae7d4ba2560a8fa0e08" - integrity sha512-Vkww+P7qYhhYp4+elYQ2UjbDNFzOLC0tWaegjA6ohXHewiCWio5byySLxPAwj2gfLIXwIuf5Ud21njZHg7FSIQ== + version "6.19.7" + resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-6.19.7.tgz#a40b6b72d911b5f1ed70ed3b4e7d4d4e625c0b5f" + integrity sha512-oDbklp4O3MtAM4mtuwyZLrgO1qDVYIujzNJQzXmi9YzymJCuzMLSRDvhY83NNDCRxf0pds4DShgYeZdbSyKraA== dependencies: - "@sentry/core" "6.0.2" - "@sentry/types" "6.0.2" - "@sentry/utils" "6.0.2" + "@sentry/core" "6.19.7" + "@sentry/types" "6.19.7" + "@sentry/utils" "6.19.7" tslib "^1.9.3" -"@sentry/core@6.0.2": - version "6.0.2" - resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.0.2.tgz#8cb2aa69130b809c438593da433254da1a20543f" - integrity sha512-7v9tiHRYxDT1WxVNQJc+K4s9T2m++0I+ERrTx4fx5vRzTZrtS9nDjpbiLGonGZaV6Lv2houZUp4uLVNU3vtOQw== +"@sentry/core@6.19.7": + version "6.19.7" + resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.19.7.tgz#156aaa56dd7fad8c89c145be6ad7a4f7209f9785" + integrity sha512-tOfZ/umqB2AcHPGbIrsFLcvApdTm9ggpi/kQZFkej7kMphjT+SGBiQfYtjyg9jcRW+ilAR4JXC9BGKsdEQ+8Vw== dependencies: - "@sentry/hub" "6.0.2" - "@sentry/minimal" "6.0.2" - "@sentry/types" "6.0.2" - "@sentry/utils" "6.0.2" + "@sentry/hub" "6.19.7" + "@sentry/minimal" "6.19.7" + "@sentry/types" "6.19.7" + "@sentry/utils" "6.19.7" tslib "^1.9.3" -"@sentry/hub@6.0.2": - version "6.0.2" - resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.0.2.tgz#6bb33b072bef6bf9ad50599f19f9674438717cb8" - integrity sha512-/rByl+ak5Ni6xTSfzIcJqKaaErJbDw0kXgNlHGPRQ4bM5hjDDuKbdykMk4J6BfPWt2dfwe13P25bIjz9M3a7kw== +"@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.19.7": + version "6.19.7" + resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.19.7.tgz#58ad7776bbd31e9596a8ec46365b45cd8b9cfd11" + integrity sha512-y3OtbYFAqKHCWezF0EGGr5lcyI2KbaXW2Ik7Xp8Mu9TxbSTuwTe4rTntwg8ngPjUQU3SUHzgjqVB8qjiGqFXCA== dependencies: - "@sentry/types" "6.0.2" - "@sentry/utils" "6.0.2" + "@sentry/types" "6.19.7" + "@sentry/utils" "6.19.7" tslib "^1.9.3" -"@sentry/minimal@6.0.2": - version "6.0.2" - resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.0.2.tgz#09b3e9f67329090da713860e40560f77ad4afc48" - integrity sha512-wrSTTIvDsRCXbNcfha/fjkP7Mj1xzNHzGeBRMRlNg3T+nYZSrs5SihVTXT/gcABhO5PpWu8EXbMpv0bAahaEGw== +"@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/hub" "6.0.2" - "@sentry/types" "6.0.2" + "@sentry/core" "7.118.0" + "@sentry/types" "7.118.0" + "@sentry/utils" "7.118.0" + localforage "^1.8.1" + +"@sentry/minimal@6.19.7": + version "6.19.7" + resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.19.7.tgz#b3ee46d6abef9ef3dd4837ebcb6bdfd01b9aa7b4" + integrity sha512-wcYmSJOdvk6VAPx8IcmZgN08XTXRwRtB1aOLZm+MVHjIZIhHoBGZJYTVQS/BWjldsamj2cX3YGbGXNunaCfYJQ== + dependencies: + "@sentry/hub" "6.19.7" + "@sentry/types" "6.19.7" tslib "^1.9.3" -"@sentry/types@6.0.2": - version "6.0.2" - resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.0.2.tgz#8c1f6b5bc41708b5d6133847988752d9d184b237" - integrity sha512-aDUJuOe0MsqjDzx6dUTS6xXe+gNjYuZTHUuUB7EpihzoHGre7gUN3/WCCghiR4OJ703fxyl24cex6vDboZJLvg== +"@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/utils@6.0.2": - version "6.0.2" - resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.0.2.tgz#ffa53e7f6873683a5aa8a50f5fcb391ca37ffab4" - integrity sha512-X2hAFMkfht4GzdtqrjuVJfK07af5r6h2BfYJGSS/XYa8KBVlDGAtvffP9uYuNWUoLxr+Vrc+ePrPoi4xCREcDQ== +"@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/types" "6.0.2" + "@sentry-internal/tracing" "7.118.0" + "@sentry/core" "7.118.0" + "@sentry/types" "7.118.0" + "@sentry/utils" "7.118.0" + +"@sentry/types@6.19.7": + version "6.19.7" + resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.19.7.tgz#c6b337912e588083fc2896eb012526cf7cfec7c7" + integrity sha512-jH84pDYE+hHIbVnab3Hr+ZXr1v8QABfhx39KknxqKWr2l0oEItzepV0URvbEhB446lk/S/59230dlUUIBGsXbg== + +"@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.19.7": + version "6.19.7" + resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.19.7.tgz#6edd739f8185fd71afe49cbe351c1bbf5e7b7c79" + integrity sha512-z95ECmE3i9pbWoXQrD/7PgkBAzJYR+iXtPuTkpBjDKs86O3mT+PXOT3BAn79w2wkn7/i3vOGD2xVr1uiMl26dA== + dependencies: + "@sentry/types" "6.19.7" 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.27.8": version "0.27.8" resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e" @@ -12220,7 +12313,7 @@ loader-utils@^2.0.3: 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==