about summary refs log tree commit diff
path: root/src/lib/sentry.ts
diff options
context:
space:
mode:
authorAnsh <anshnanda10@gmail.com>2023-05-01 12:42:31 -0700
committerGitHub <noreply@github.com>2023-05-01 14:42:31 -0500
commitc75c888de2407d3314cad07989174201313facaa (patch)
treee7b293ebc6730a47c1a89207fd0248393db5185e /src/lib/sentry.ts
parentdbb3c5c15524c517291356a4918d043348906aad (diff)
downloadvoidsky-c75c888de2407d3314cad07989174201313facaa.tar.zst
[APP-527] setup sentry (#532)
* setup sentry

* add sentry to transformIgnorePatterns to fix jest issues

* update README with sourcemap instructions

* only enable integrations on native

* fix sentry web

* remove testing code

* fix sentry authToken

* Switch over to paul's auth tokens temporarily (lol)

---------

Co-authored-by: Paul Frazee <pfrazee@gmail.com>
Diffstat (limited to 'src/lib/sentry.ts')
-rw-r--r--src/lib/sentry.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/lib/sentry.ts b/src/lib/sentry.ts
new file mode 100644
index 000000000..c5d1d3eb6
--- /dev/null
+++ b/src/lib/sentry.ts
@@ -0,0 +1,46 @@
+import {isNative, isWeb} from 'platform/detection'
+import {FC} from 'react'
+import * as Sentry from 'sentry-expo'
+
+// Sentry Initialization
+
+export const getRoutingInstrumentation = () => {
+  return new Sentry.Native.ReactNavigationInstrumentation() // initialize this in `onReady` prop of NavigationContainer
+}
+
+Sentry.init({
+  dsn: 'https://05bc3789bf994b81bd7ce20c86ccd3ae@o4505071687041024.ingest.sentry.io/4505071690514432',
+  enableInExpoDevelopment: false, // if true, Sentry will try to send events/errors in development mode.
+  debug: false, // If `true`, Sentry will try to print out useful debugging information if something goes wrong with sending the event. Set it to `false` in production
+  environment: __DEV__ ? 'development' : 'production', // Set the environment
+  enableAutoPerformanceTracking: true, // Enable auto performance tracking
+  tracesSampleRate: 0.5, // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring. // TODO: this might be too much in production
+  integrations: isNative
+    ? [
+        new Sentry.Native.ReactNativeTracing({
+          shouldCreateSpanForRequest: url => {
+            // Do not create spans for outgoing requests to a `/logs` endpoint as it is too noisy due to expo
+            return !url.match(/\/logs$/)
+          },
+          routingInstrumentation: getRoutingInstrumentation(),
+        }),
+      ]
+    : [], // no integrations for web, yet
+})
+
+// if web, use Browser client, otherwise use Native client
+export function getSentryClient() {
+  if (isWeb) {
+    return Sentry.Browser
+  }
+  return Sentry.Native
+}
+
+// wrap root App component with Sentry for automatic touch event tracking and performance monitoring
+export function withSentry(Component: FC) {
+  if (isWeb) {
+    return Component // .wrap is not required or available for web
+  }
+  const sentryClient = getSentryClient()
+  return sentryClient.wrap(Component)
+}