remove sentry

This commit is contained in:
m5r 2023-04-29 07:49:56 +02:00
parent 2ebdca5484
commit cb35455722
8 changed files with 4 additions and 374 deletions

View File

@ -88,9 +88,6 @@ export default {
url: process.env.REDIS_URL, url: process.env.REDIS_URL,
password: process.env.REDIS_PASSWORD, password: process.env.REDIS_PASSWORD,
}, },
sentry: {
dsn: process.env.SENTRY_DSN,
},
webPush: { webPush: {
privateKey: process.env.WEB_PUSH_VAPID_PRIVATE_KEY, privateKey: process.env.WEB_PUSH_VAPID_PRIVATE_KEY,
publicKey: process.env.WEB_PUSH_VAPID_PUBLIC_KEY, publicKey: process.env.WEB_PUSH_VAPID_PUBLIC_KEY,

View File

@ -1,15 +1,5 @@
import { hydrate } from "react-dom"; import { hydrate } from "react-dom";
import { RemixBrowser } from "@remix-run/react"; import { RemixBrowser } from "@remix-run/react";
import * as Sentry from "@sentry/browser";
import { Integrations } from "@sentry/tracing";
if (window.shellphoneConfig.sentry.dsn) {
Sentry.init({
dsn: window.shellphoneConfig.sentry.dsn,
tracesSampleRate: 1.0,
integrations: [new Integrations.BrowserTracing()],
});
}
hydrate(<RemixBrowser />, document); hydrate(<RemixBrowser />, document);

View File

@ -1,58 +1,17 @@
import type { FunctionComponent, PropsWithChildren } from "react"; import type { FunctionComponent, PropsWithChildren } from "react";
import { type LinksFunction, type LoaderFunction, json } from "@remix-run/node"; import type { LinksFunction } from "@remix-run/node";
import { import { Link, Links, LiveReload, Meta, Outlet, Scripts, ScrollRestoration, useCatch } from "@remix-run/react";
Link,
Links,
LiveReload,
Meta,
Outlet,
Scripts,
ScrollRestoration,
useCatch,
useLoaderData,
} from "@remix-run/react";
import config from "~/config/config.server";
import Logo from "~/features/core/components/logo"; import Logo from "~/features/core/components/logo";
import styles from "./styles/tailwind.css"; import styles from "./styles/tailwind.css";
export const links: LinksFunction = () => [{ rel: "stylesheet", href: styles }]; export const links: LinksFunction = () => [{ rel: "stylesheet", href: styles }];
declare global {
interface Window {
shellphoneConfig: LoaderData["shellphoneConfig"];
}
}
type LoaderData = {
shellphoneConfig: {
sentry: {
dsn?: string;
};
};
};
export const loader: LoaderFunction = () => {
return json<LoaderData>({
shellphoneConfig: {
sentry: {
dsn: config.sentry.dsn,
},
},
});
};
export default function App() { export default function App() {
const { shellphoneConfig } = useLoaderData<LoaderData>();
return ( return (
<Document> <Document>
<Outlet /> <Outlet />
<script
suppressHydrationWarning
dangerouslySetInnerHTML={{
__html: `window.shellphoneConfig=${JSON.stringify(shellphoneConfig)};`,
}}
/>
</Document> </Document>
); );
} }

View File

@ -1,10 +1,7 @@
import { useEffect } from "react";
import { type LinksFunction, type LoaderFunction, json } from "@remix-run/node"; import { type LinksFunction, type LoaderFunction, json } from "@remix-run/node";
import { Outlet, useCatch, useLoaderData, useMatches } from "@remix-run/react"; import { Outlet, useCatch, useMatches } from "@remix-run/react";
import * as Sentry from "@sentry/browser";
import serverConfig from "~/config/config.server"; import serverConfig from "~/config/config.server";
import { type SessionData, requireLoggedIn } from "~/utils/auth.server";
import Footer from "~/features/core/components/footer"; import Footer from "~/features/core/components/footer";
import ServiceWorkerUpdateNotifier from "~/features/core/components/service-worker-update-notifier"; import ServiceWorkerUpdateNotifier from "~/features/core/components/service-worker-update-notifier";
import Notification from "~/features/core/components/notification"; import Notification from "~/features/core/components/notification";
@ -19,15 +16,11 @@ export const links: LinksFunction = () => [
]; ];
export type AppLoaderData = { export type AppLoaderData = {
sessionData: SessionData;
config: { webPushPublicKey: string }; config: { webPushPublicKey: string };
}; };
export const loader: LoaderFunction = async ({ request }) => { export const loader: LoaderFunction = async ({ request }) => {
const sessionData = await requireLoggedIn(request);
return json<AppLoaderData>({ return json<AppLoaderData>({
sessionData,
config: { config: {
webPushPublicKey: serverConfig.webPush.publicKey, webPushPublicKey: serverConfig.webPush.publicKey,
}, },
@ -37,14 +30,9 @@ export const loader: LoaderFunction = async ({ request }) => {
export default function __App() { export default function __App() {
useDevice(); useDevice();
useServiceWorkerRevalidate(); useServiceWorkerRevalidate();
const { sessionData } = useLoaderData<AppLoaderData>();
const matches = useMatches(); const matches = useMatches();
const hideFooter = matches.some((match) => match.handle?.hideFooter === true); const hideFooter = matches.some((match) => match.handle?.hideFooter === true);
useEffect(() => {
Sentry.setUser(sessionData.user);
}, []);
return ( return (
<> <>
<div className="h-full w-full overflow-hidden fixed bg-gray-100"> <div className="h-full w-full overflow-hidden fixed bg-gray-100">

178
package-lock.json generated
View File

@ -15,9 +15,6 @@
"@remix-run/node": "1.14.3", "@remix-run/node": "1.14.3",
"@remix-run/react": "1.14.3", "@remix-run/react": "1.14.3",
"@remix-run/server-runtime": "1.14.3", "@remix-run/server-runtime": "1.14.3",
"@sentry/browser": "7.3.0",
"@sentry/node": "7.3.0",
"@sentry/tracing": "7.3.0",
"@tailwindcss/forms": "0.5.2", "@tailwindcss/forms": "0.5.2",
"@tailwindcss/line-clamp": "0.4.0", "@tailwindcss/line-clamp": "0.4.0",
"@tailwindcss/typography": "0.5.2", "@tailwindcss/typography": "0.5.2",
@ -4245,99 +4242,6 @@
"url": "https://github.com/fb55/domhandler?sponsor=1" "url": "https://github.com/fb55/domhandler?sponsor=1"
} }
}, },
"node_modules/@sentry/browser": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/browser/-/browser-7.3.0.tgz",
"integrity": "sha512-UJMTDbajKNRGrs4ZQNelrPDaATvSZ9uELpPOtPSG6JUvB1BCwGgsgzz55RS0Uqs7B8KhMnDQ0kIn3FMewM4FMg==",
"dependencies": {
"@sentry/core": "7.3.0",
"@sentry/types": "7.3.0",
"@sentry/utils": "7.3.0",
"tslib": "^1.9.3"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/core": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.3.0.tgz",
"integrity": "sha512-EvuWVlYm0F0+BtIEmQiCL31Fw0cfKSwUTmxc99wvouaabpHBr2zCJHRxaXOWzxS705bYBJEQiFDTIHfoOQZMzA==",
"dependencies": {
"@sentry/hub": "7.3.0",
"@sentry/types": "7.3.0",
"@sentry/utils": "7.3.0",
"tslib": "^1.9.3"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/hub": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/hub/-/hub-7.3.0.tgz",
"integrity": "sha512-0GtTaWf/hoAMoIFY7Ke6eozIbG3FdIPM364sER4SxUQVSklp6AORrV6p82IgWPROK6aj83cPk9Bszgi6RiF/BA==",
"dependencies": {
"@sentry/types": "7.3.0",
"@sentry/utils": "7.3.0",
"tslib": "^1.9.3"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/node": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.3.0.tgz",
"integrity": "sha512-hPqLQMdpL9MeirtKDCgy0ekptWh58CCUhvcoQ2bYstVBsyMMTNTbiQqF/ClzanrScQ5CEuGWnCbKxrFN/S6cQg==",
"dependencies": {
"@sentry/core": "7.3.0",
"@sentry/hub": "7.3.0",
"@sentry/types": "7.3.0",
"@sentry/utils": "7.3.0",
"cookie": "^0.4.1",
"https-proxy-agent": "^5.0.0",
"lru_map": "^0.3.3",
"tslib": "^1.9.3"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/tracing": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/tracing/-/tracing-7.3.0.tgz",
"integrity": "sha512-A+mLEH8jtLkhfyw81EZA1XgI96jh9TIwH9EST3hdfSPgdZQf0A5sV8oVVh/d9Hw7NVb65Va5KhAZDNhcx5QxUA==",
"dependencies": {
"@sentry/hub": "7.3.0",
"@sentry/types": "7.3.0",
"@sentry/utils": "7.3.0",
"tslib": "^1.9.3"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/types": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.3.0.tgz",
"integrity": "sha512-cGkHdh9+uvbFTj65TjWcXuhe6vQiMY+U+N2GE5xCfmZT9hwuouCASViNsbJMpZqvCg+Yi0fasQLZ71rujiRNOA==",
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/utils": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.3.0.tgz",
"integrity": "sha512-xUP8TBf2p/c6CN8eFQ7Y+xk0IFrJXsph5ScozqNl/2l/Xs8hd2EiYETqgUklphoYD4J2RxvPwMyqBL15QN6wNg==",
"dependencies": {
"@sentry/types": "7.3.0",
"tslib": "^1.9.3"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sideway/address": { "node_modules/@sideway/address": {
"version": "4.1.4", "version": "4.1.4",
"resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.4.tgz", "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.4.tgz",
@ -14135,11 +14039,6 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/lru_map": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/lru_map/-/lru_map-0.3.3.tgz",
"integrity": "sha512-Pn9cox5CsMYngeDbmChANltQl+5pi6XmTrraMSzhPmMBbmgcxmqWry0U3PGapCU1yB4/LqCcom7qhHZiF/jGfQ=="
},
"node_modules/lru-cache": { "node_modules/lru-cache": {
"version": "6.0.0", "version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
@ -25655,78 +25554,6 @@
} }
} }
}, },
"@sentry/browser": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/browser/-/browser-7.3.0.tgz",
"integrity": "sha512-UJMTDbajKNRGrs4ZQNelrPDaATvSZ9uELpPOtPSG6JUvB1BCwGgsgzz55RS0Uqs7B8KhMnDQ0kIn3FMewM4FMg==",
"requires": {
"@sentry/core": "7.3.0",
"@sentry/types": "7.3.0",
"@sentry/utils": "7.3.0",
"tslib": "^1.9.3"
}
},
"@sentry/core": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.3.0.tgz",
"integrity": "sha512-EvuWVlYm0F0+BtIEmQiCL31Fw0cfKSwUTmxc99wvouaabpHBr2zCJHRxaXOWzxS705bYBJEQiFDTIHfoOQZMzA==",
"requires": {
"@sentry/hub": "7.3.0",
"@sentry/types": "7.3.0",
"@sentry/utils": "7.3.0",
"tslib": "^1.9.3"
}
},
"@sentry/hub": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/hub/-/hub-7.3.0.tgz",
"integrity": "sha512-0GtTaWf/hoAMoIFY7Ke6eozIbG3FdIPM364sER4SxUQVSklp6AORrV6p82IgWPROK6aj83cPk9Bszgi6RiF/BA==",
"requires": {
"@sentry/types": "7.3.0",
"@sentry/utils": "7.3.0",
"tslib": "^1.9.3"
}
},
"@sentry/node": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.3.0.tgz",
"integrity": "sha512-hPqLQMdpL9MeirtKDCgy0ekptWh58CCUhvcoQ2bYstVBsyMMTNTbiQqF/ClzanrScQ5CEuGWnCbKxrFN/S6cQg==",
"requires": {
"@sentry/core": "7.3.0",
"@sentry/hub": "7.3.0",
"@sentry/types": "7.3.0",
"@sentry/utils": "7.3.0",
"cookie": "^0.4.1",
"https-proxy-agent": "^5.0.0",
"lru_map": "^0.3.3",
"tslib": "^1.9.3"
}
},
"@sentry/tracing": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/tracing/-/tracing-7.3.0.tgz",
"integrity": "sha512-A+mLEH8jtLkhfyw81EZA1XgI96jh9TIwH9EST3hdfSPgdZQf0A5sV8oVVh/d9Hw7NVb65Va5KhAZDNhcx5QxUA==",
"requires": {
"@sentry/hub": "7.3.0",
"@sentry/types": "7.3.0",
"@sentry/utils": "7.3.0",
"tslib": "^1.9.3"
}
},
"@sentry/types": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.3.0.tgz",
"integrity": "sha512-cGkHdh9+uvbFTj65TjWcXuhe6vQiMY+U+N2GE5xCfmZT9hwuouCASViNsbJMpZqvCg+Yi0fasQLZ71rujiRNOA=="
},
"@sentry/utils": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.3.0.tgz",
"integrity": "sha512-xUP8TBf2p/c6CN8eFQ7Y+xk0IFrJXsph5ScozqNl/2l/Xs8hd2EiYETqgUklphoYD4J2RxvPwMyqBL15QN6wNg==",
"requires": {
"@sentry/types": "7.3.0",
"tslib": "^1.9.3"
}
},
"@sideway/address": { "@sideway/address": {
"version": "4.1.4", "version": "4.1.4",
"resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.4.tgz", "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.4.tgz",
@ -32939,11 +32766,6 @@
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz",
"integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==" "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA=="
}, },
"lru_map": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/lru_map/-/lru_map-0.3.3.tgz",
"integrity": "sha512-Pn9cox5CsMYngeDbmChANltQl+5pi6XmTrraMSzhPmMBbmgcxmqWry0U3PGapCU1yB4/LqCcom7qhHZiF/jGfQ=="
},
"lru-cache": { "lru-cache": {
"version": "6.0.0", "version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",

View File

@ -36,9 +36,6 @@
"@remix-run/node": "1.14.3", "@remix-run/node": "1.14.3",
"@remix-run/react": "1.14.3", "@remix-run/react": "1.14.3",
"@remix-run/server-runtime": "1.14.3", "@remix-run/server-runtime": "1.14.3",
"@sentry/browser": "7.3.0",
"@sentry/node": "7.3.0",
"@sentry/tracing": "7.3.0",
"@tailwindcss/forms": "0.5.2", "@tailwindcss/forms": "0.5.2",
"@tailwindcss/line-clamp": "0.4.0", "@tailwindcss/line-clamp": "0.4.0",
"@tailwindcss/typography": "0.5.2", "@tailwindcss/typography": "0.5.2",

View File

@ -2,25 +2,12 @@ import express from "express";
import compression from "compression"; import compression from "compression";
import morgan from "morgan"; import morgan from "morgan";
import { createRequestHandler } from "@remix-run/express"; import { createRequestHandler } from "@remix-run/express";
import * as Sentry from "@sentry/node";
import config from "~/config/config.server";
import logger from "~/utils/logger.server"; import logger from "~/utils/logger.server";
import { adminMiddleware, setupBullBoard } from "./queues"; import { adminMiddleware, setupBullBoard } from "./queues";
import { registerSentry, sentryLoadContext } from "./sentry-remix";
import { purgeRequireCache } from "./purge-require-cache"; import { purgeRequireCache } from "./purge-require-cache";
const environment = process.env.NODE_ENV; const environment = process.env.NODE_ENV;
if (config.sentry.dsn) {
Sentry.init({
dsn: config.sentry.dsn,
integrations: [new Sentry.Integrations.Http({ tracing: true })],
tracesSampleRate: 1.0,
environment,
});
}
const app = express(); const app = express();
app.use((req, res, next) => { app.use((req, res, next) => {
res.set("X-Fly-Region", process.env.FLY_REGION ?? "unknown"); res.set("X-Fly-Region", process.env.FLY_REGION ?? "unknown");
@ -90,9 +77,8 @@ app.all("*", (req, res, next) => {
} }
return createRequestHandler({ return createRequestHandler({
build: registerSentry(require("../build")), build: require("../build"),
mode: environment, mode: environment,
getLoadContext: sentryLoadContext,
})(req, res, next); })(req, res, next);
}); });

View File

@ -1,109 +0,0 @@
import type { Request, Response } from "express";
import type { ActionFunction, DataFunctionArgs, LoaderFunction, ServerBuild } from "@remix-run/node";
import { isResponse } from "@remix-run/server-runtime/dist/responses";
import type { Transaction } from "@sentry/types";
import * as Sentry from "@sentry/node";
import { v4 as uuid } from "uuid";
import { __getSession } from "~/utils/session.server";
import type { SessionData } from "~/utils/auth.server";
function wrapDataFunc(func: ActionFunction | LoaderFunction, routeId: string, method: string) {
const ogFunc = func;
return async (args: DataFunctionArgs) => {
const session = await __getSession(args.request.headers.get("Cookie"));
const sessionData: SessionData | undefined = session.data.user;
if (sessionData) {
Sentry.setUser({
id: sessionData.user.id,
email: sessionData.user.email,
role: sessionData.user.role,
});
} else {
Sentry.configureScope((scope) => scope.setUser(null));
}
const parentTransaction: Transaction | undefined = args.context && (args.context.__sentry_transaction as any);
const transaction = parentTransaction?.startChild({
op: `${method}:${routeId}`,
description: `${method}: ${routeId}`,
});
if (transaction) {
transaction.setStatus("ok");
transaction.transaction = parentTransaction;
}
try {
return await ogFunc(args);
} catch (error) {
if (isResponse(error)) {
throw error;
}
Sentry.captureException(error, {
tags: {
global_id: parentTransaction && parentTransaction.tags["global_id"],
},
});
transaction?.setStatus("internal_error");
throw error;
} finally {
transaction?.finish();
}
};
}
// Register Sentry across your entire remix build.
export function registerSentry(build: ServerBuild) {
type Route = ServerBuild["routes"][string];
const routes: Record<string, Route> = {};
for (const [id, route] of Object.entries(build.routes)) {
const newRoute: Route = { ...route, module: { ...route.module } };
if (route.module.action) {
newRoute.module.action = wrapDataFunc(route.module.action, id, "action");
}
if (route.module.loader) {
newRoute.module.loader = wrapDataFunc(route.module.loader, id, "loader");
}
routes[id] = newRoute;
}
return {
...build,
routes,
};
}
export function sentryLoadContext(req: Request, res: Response) {
const transaction = Sentry.getCurrentHub().startTransaction({
op: "request",
name: `${req.method}: ${req.url}`,
description: `${req.method}: ${req.url}`,
metadata: {
requestPath: req.url,
},
tags: {
global_id: uuid(),
},
});
transaction && transaction.setStatus("internal_error");
res.once("finish", () => {
if (transaction) {
transaction.setHttpStatus(res.statusCode);
transaction.setTag("http.status_code", res.statusCode);
transaction.setTag("http.method", req.method);
transaction.finish();
}
});
return {
__sentry_transaction: transaction,
};
}