From 961dc8e461c23e22257d2c5b29671efbe463334f Mon Sep 17 00:00:00 2001 From: m5r Date: Sun, 26 Jun 2022 17:01:55 +0200 Subject: [PATCH] report errors to sentry --- .gitignore | 2 +- app/config/config.server.ts | 4 + app/entry.client.tsx | 16 ++ app/root.tsx | 35 ++++- app/routes/__app.tsx | 9 +- package-lock.json | 290 +++++++++++++++++++++++++---------- package.json | 9 +- scripts/build-server.js | 8 +- server.ts => server/index.ts | 55 ++----- server/queues.ts | 35 +++++ server/sentry-remix.ts | 109 +++++++++++++ 11 files changed, 446 insertions(+), 126 deletions(-) rename server.ts => server/index.ts (61%) create mode 100644 server/queues.ts create mode 100644 server/sentry-remix.ts diff --git a/.gitignore b/.gitignore index 08ee14b..595c16c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ node_modules /public/build /public/entry.worker.js /build -server.js +/server/index.js /app/styles/tailwind.css /.idea diff --git a/app/config/config.server.ts b/app/config/config.server.ts index f47526f..f0e8542 100644 --- a/app/config/config.server.ts +++ b/app/config/config.server.ts @@ -36,6 +36,7 @@ invariant( typeof process.env.WEB_PUSH_VAPID_PUBLIC_KEY === "string", `Please define the "WEB_PUSH_VAPID_PUBLIC_KEY" environment variable`, ); +invariant(typeof process.env.SENTRY_DSN === "string", `Please define the "SENTRY_DSN" environment variable`); export default { app: { @@ -54,6 +55,9 @@ export default { url: process.env.REDIS_URL, password: process.env.REDIS_PASSWORD, }, + sentry: { + dsn: process.env.SENTRY_DSN, + }, twilio: { authToken: process.env.TWILIO_AUTH_TOKEN, }, diff --git a/app/entry.client.tsx b/app/entry.client.tsx index 13fa3dc..4c7672c 100644 --- a/app/entry.client.tsx +++ b/app/entry.client.tsx @@ -1,5 +1,21 @@ import { hydrate } from "react-dom"; import { RemixBrowser } from "@remix-run/react"; +import * as Sentry from "@sentry/browser"; +import { Integrations } from "@sentry/tracing"; + +declare global { + interface Window { + shellphoneConfig: { + sentry: { dsn: string }; + }; + } +} + +Sentry.init({ + dsn: window.shellphoneConfig.sentry.dsn, + tracesSampleRate: 1.0, + integrations: [new Integrations.BrowserTracing()], +}); hydrate(, document); diff --git a/app/root.tsx b/app/root.tsx index c10cc97..e27b06a 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -1,17 +1,48 @@ import type { FunctionComponent, PropsWithChildren } from "react"; -import type { LinksFunction } from "@remix-run/node"; -import { Link, Links, LiveReload, Meta, Outlet, Scripts, ScrollRestoration, useCatch } from "@remix-run/react"; +import { type LinksFunction, type LoaderFunction, json } from "@remix-run/node"; +import { + 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 styles from "./styles/tailwind.css"; export const links: LinksFunction = () => [{ rel: "stylesheet", href: styles }]; +type LoaderData = { + shellphoneConfig: string; +}; +export const loader: LoaderFunction = () => { + return json({ + shellphoneConfig: JSON.stringify({ + sentry: { + dsn: config.sentry.dsn, + }, + }), + }); +}; + export default function App() { + const { shellphoneConfig } = useLoaderData(); return ( +