Skip to content

Commit

Permalink
update sentry and add profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtsam committed Jun 29, 2024
1 parent 9c37c55 commit c497e18
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 223 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ COPY --from=build /app/public /app/public
COPY --from=build /app/package.json /app/package.json
COPY --from=build /app/server.js /app/server.js
COPY --from=build /app/server-utils.js /app/server-utils.js
COPY --from=build /app/server-monitoring.js /app/server-monitoring.js
COPY ./mdx ./mdx

CMD [ "pnpm","start" ]
6 changes: 1 addition & 5 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createReadableStreamFromReadable } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import { isbot } from "isbot";
import { renderToPipeableStream } from "react-dom/server";
import { env, forceEnvValidation } from "#app/utils/env.server.ts";
import { forceEnvValidation } from "#app/utils/env.server.ts";
import { NonceProvider } from "./utils/nonce-provider.tsx";
import chalk from "chalk";
import { captureException, captureRemixServerException } from "@sentry/remix";
Expand All @@ -17,10 +17,6 @@ forceEnvValidation();

const ABORT_DELAY = 5_000;

if (env.NODE_ENV === "production" && env.SENTRY_DSN) {
import("./utils/monitoring.server.ts").then(({ init }) => init());
}

type DocRequestArgs = Parameters<HandleDocumentRequestFunction>;
export default function handleRequest(
...[
Expand Down
3 changes: 3 additions & 0 deletions app/utils/monitoring.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
init as sentryInit,
browserTracingIntegration,
replayIntegration,
browserProfilingIntegration,
} from "@sentry/remix";
import { useLocation, useMatches } from "@remix-run/react";
import { useEffect } from "react";
Expand All @@ -10,6 +11,7 @@ export function init() {
sentryInit({
dsn: window.ENV.SENTRY_DSN,
tracesSampleRate: 1,
profilesSampleRate: 1,
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1,

Expand All @@ -20,6 +22,7 @@ export function init() {
useMatches,
}),
replayIntegration(),
browserProfilingIntegration(),
],
});
}
9 changes: 0 additions & 9 deletions app/utils/monitoring.server.ts

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"@remix-run/node": "2.9.1",
"@remix-run/react": "2.9.1",
"@remix-run/serve": "2.9.1",
"@sentry/remix": "8.9.2",
"@sentry/profiling-node": "8.13.0",
"@sentry/remix": "8.13.0",
"@sentry/vite-plugin": "2.18.0",
"address": "2.0.2",
"cache-control-parser": "2.0.6",
Expand Down
437 changes: 234 additions & 203 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions server-monitoring.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { init as sentryInit } from "@sentry/remix";
import { nodeProfilingIntegration } from "@sentry/profiling-node";

export function init() {
sentryInit({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1,
profilesSampleRate: 1,
autoInstrumentRemix: true,
integrations: [nodeProfilingIntegration()],
});
}
10 changes: 5 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { wrapExpressCreateRequestHandler } from "@sentry/remix";
import "dotenv/config";
import crypto from "crypto";
import { createRequestHandler } from "@remix-run/express";
Expand All @@ -11,14 +10,15 @@ import getPort, { portNumbers } from "get-port";
import chalk from "chalk";
import { printUrls } from "./server-utils.js";

const sentryCreateRequestHandler =
wrapExpressCreateRequestHandler(createRequestHandler);

const MODE = process.env.NODE_ENV ?? "development";
const DISALLOW_INDEXING = process.env.DISALLOW_INDEXING === "true";

sourceMapSupport.install();

if (MODE === "production" && process.env.SENTRY_DSN) {
import("./utils/server-monitoring.js").then(({ init }) => init());
}

const viteDevServer =
MODE === "production"
? undefined
Expand Down Expand Up @@ -108,7 +108,7 @@ function getBuild() {
// handle SSR requests
app.all(
"*",
sentryCreateRequestHandler({
createRequestHandler({
getLoadContext: (_, res) => ({
cspNonce: res.locals.cspNonce,
serverBuild: getBuild(),
Expand Down

0 comments on commit c497e18

Please sign in to comment.