Skip to content

Commit

Permalink
Sentry integration and migration to Expo SDK 50 (#177)
Browse files Browse the repository at this point in the history
* chore(deps): upgraded to Expo 50

* feat(expo): added Sentry integration

* chore(config): added sentry URL

* feat(backend): added Sentry

* chore(backend): added environment related configuration

* chore: removed debug route
  • Loading branch information
MAXOUXAX authored May 10, 2024
1 parent 26adc5d commit 1416de4
Show file tree
Hide file tree
Showing 12 changed files with 6,974 additions and 4,529 deletions.
3 changes: 3 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Sentry Config File
.sentryclirc
3,009 changes: 2,033 additions & 976 deletions backend/package-lock.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
"main": "index.js",
"scripts": {
"dev": "cross-env NODE_ENV=development nodemon --watch src src/server.ts",
"build": "tsc -p tsconfig.json",
"postinstall": "npm link ../commons"
"build": "tsc -p tsconfig.json && npm run sentry:sourcemaps",
"postinstall": "npm link ../commons",
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org datsmysong --project backend ./build && sentry-cli sourcemaps upload --org datsmysong --project backend ./build"
},
"author": "",
"license": "ISC",
"dependencies": {
"@fastify/cookie": "^9.3.1",
"@fastify/cors": "^9.0.1",
"@fastify/rate-limit": "^9.1.0",
"@sentry/cli": "^2.31.2",
"@sentry/node": "^8.0.0-rc.2",
"@spotify/web-api-ts-sdk": "^1.2.0",
"@supabase/auth-helpers-nextjs": "^0.10.0",
"@supabase/ssr": "^0.3.0",
Expand Down Expand Up @@ -41,4 +44,4 @@
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
}
}
18 changes: 17 additions & 1 deletion backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ServerToClientEvents,
} from "commons/socket.io-types";
import { config } from "dotenv";
import fastify from "fastify";
import fastifySocketIO from "fastify-socket.io";
import { Server } from "socket.io";
import authRoutes from "./authRoutes";
Expand All @@ -25,6 +24,7 @@ import StreamingServicesGET from "./route/StreamingServicesGET";
import UnbindServicePOST from "./route/UnbindServicePOST";
import RecentMusicsGET from "./route/RecentMusicsGET";
import onRoomWSConnection from "./socketio/RoomIO";
import * as Sentry from "@sentry/node";

config({ path: ".env.local" });

Expand All @@ -44,6 +44,20 @@ const corsOrigin: (devValue?: string | boolean) => (string | boolean)[] = (
return ["https://datsmysong.app", "https://api.datsmysong.app/"];
};

// Ensure to call this before requiring any other modules!
Sentry.init({
dsn: "https://349dd8dd31222fcee73479d237a589dd@o4507124937064448.ingest.de.sentry.io/4507226372636752",

// Add Performance Monitoring by setting tracesSampleRate
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
environment: process.env.NODE_ENV,
debug: process.env.NODE_ENV === "development",
});

// (!) This import should be done after the Sentry.init call
import fastify from "fastify";

export const server = fastify({
ignoreTrailingSlash: true,
ignoreDuplicateSlashes: true,
Expand All @@ -54,6 +68,8 @@ export const server = fastify({
},
});

Sentry.setupFastifyErrorHandler(server);

if (!process.env.SUPABASE_URL || !process.env.SERVICE_ROLE) {
throw new Error(
"Missing SUPABASE_URL or SUPABASE_SERVICE_ROLE environment variable"
Expand Down
238 changes: 125 additions & 113 deletions backend/tsconfig.json

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions expo/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": [
"**/*"
],
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "app.datsmysong"
Expand All @@ -24,9 +22,7 @@
"foregroundImage": "./assets/images/adaptive-icon.png",
"backgroundColor": "#ffffff"
},
"permissions": [
"android.permission.INTERNET"
],
"permissions": ["android.permission.INTERNET"],
"package": "app.datsmysong"
},
"web": {
Expand All @@ -35,7 +31,15 @@
"favicon": "./assets/images/favicon.png"
},
"plugins": [
"expo-router"
"expo-router",
[
"@sentry/react-native/expo",
{
"url": "https://sentry.io/",
"organization": "datsmysong",
"project": "app"
}
]
],
"experiments": {
"typedRoutes": true
Expand Down
1 change: 0 additions & 1 deletion expo/app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import MusicNote from "phosphor-react-native/src/icons/MusicNote";
import React, { useEffect, useState } from "react";
import { FlatList, View as NativeView, ScrollView } from "react-native";

import Alert from "../../components/Alert";
import Button from "../../components/Button";
import { TrackCard } from "../../components/Music";
import { View } from "../../components/Themed";
Expand Down
43 changes: 41 additions & 2 deletions expo/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import FontAwesome from "@expo/vector-icons/FontAwesome";
import * as Sentry from "@sentry/react-native";
import { useFonts } from "expo-font";
import { SplashScreen, Stack, router } from "expo-router";
import {
SplashScreen,
Stack,
router,
useNavigationContainerRef,
} from "expo-router";
import { IconContext } from "phosphor-react-native/src/lib";
import { useEffect } from "react";
import { MenuProvider } from "react-native-popup-menu";
Expand All @@ -16,9 +22,40 @@ export const unstable_settings = {
initialRouteName: "(tabs)",
};

// Construct a new instrumentation instance. This is needed to communicate between the integration and React
const routingInstrumentation = new Sentry.ReactNavigationInstrumentation();

Sentry.init({
dsn: "https://7085409d423f186cbaf15178a350408f@o4507124937064448.ingest.de.sentry.io/4507124939620432",
debug: process.env.NODE_ENV === "development",
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
tracesSampleRate: 1.0,
_experiments: {
// profilesSampleRate is relative to tracesSampleRate.
// Here, we'll capture profiles for 100% of transactions.
profilesSampleRate: 1.0,
},
integrations: [
new Sentry.ReactNativeTracing({
routingInstrumentation,
}),
],
});

// Prevent the splash screen from auto-hiding before asset loading is complete.
SplashScreen.preventAutoHideAsync();
export default function RootLayout() {

function RootLayout() {
// Capture the NavigationContainer ref and register it with the instrumentation.
const ref = useNavigationContainerRef();

useEffect(() => {
if (ref) {
routingInstrumentation.registerNavigationContainer(ref);
}
}, [ref]);

const [loaded, error] = useFonts({
"Outfit-Thin": require("../assets/fonts/outfit/Outfit-Thin.ttf"),
"Outfit-ExtraLight": require("../assets/fonts/outfit/Outfit-ExtraLight.ttf"),
Expand Down Expand Up @@ -108,3 +145,5 @@ function RootLayoutNav() {
</View>
);
}

export default Sentry.wrap(RootLayout);
6 changes: 1 addition & 5 deletions expo/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
plugins: [
// Required for expo-router
'expo-router/babel',
],
presets: ["babel-preset-expo"],
};
};
4 changes: 2 additions & 2 deletions expo/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require("expo/metro-config");
const { getSentryExpoConfig } = require("@sentry/react-native/metro");

/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname, {
const config = getSentryExpoConfig(__dirname, {
// [Web-only]: Enables CSS support in Metro.
isCSSEnabled: true,
});
Expand Down
Loading

0 comments on commit 1416de4

Please sign in to comment.