Skip to content

Commit

Permalink
Use Sentry error and release tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
vcarl committed Jul 7, 2022
1 parent 0d7d722 commit 5d7dd19
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,10 @@ jobs:
--from-literal=DISCORD_SECRET=${{ secrets.DISCORD_SECRET }} \
--from-literal=DISCORD_HASH=${{ secrets.DISCORD_HASH }}
kubectl apply -k .
- name: Set Sentry release
run: |
curl ${{secrets.SENTRY_RELEASES}} \
-X POST \
-H 'Content-Type: application/json' \
-d '{"version": "${{github.sha}}}"'
3 changes: 3 additions & 0 deletions app/discord/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Sentry from "~/helpers/sentry.server";

import onboardCommand, { handler as onboardHandler } from "~/commands/setup";
import reportCommand, { handler as reportHandler } from "~/commands/report";

Expand Down Expand Up @@ -44,6 +46,7 @@ export default function init() {
});

const errorHandler = (error: unknown) => {
Sentry.captureException(error);
if (error instanceof Error) {
console.log("ERROR", error.message);
} else if (typeof error === "string") {
Expand Down
24 changes: 24 additions & 0 deletions app/helpers/sentry.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as Sentry from "@sentry/node";
// import * as Tracing from "@sentry/tracing";

console.log(process.env.SENTRY_INGEST);

Sentry.init({
dsn: process.env.SENTRY_INGEST,
environment: process.env.NODE_ENV,
integrations: [
// enable HTTP calls tracing
// new Sentry.Integrations.Http({ tracing: true }),
new Sentry.Integrations.OnUncaughtException(),
new Sentry.Integrations.OnUnhandledRejection(),
// enable Express.js middleware tracing
// new Tracing.Integrations.Express({ app }),
],

// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 0.2,
});

export default Sentry;
14 changes: 13 additions & 1 deletion app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import express from "express";
import { createRequestHandler } from "@remix-run/express";
import path from "path";
import * as build from "@remix-run/dev/server-build";

import Sentry from "~/helpers/sentry.server";
import discordBot from "~/discord/gateway";

const app = express();

app.use(express.static(path.join(__dirname, "..", "public")));
// RequestHandler creates a separate execution context using domains, so that
// every transaction/span/breadcrumb is attached to its own Hub instance
app.use(Sentry.Handlers.requestHandler());
// TracingHandler creates a trace for every incoming request
// app.use(Sentry.Handlers.tracingHandler());

/**
Route handlers and static hosting
Expand All @@ -31,6 +37,12 @@ app.all(
}),
);

/** ERROR TRACKING
Must go after route handlers
*/
app.use(Sentry.Handlers.errorHandler());

/** Init app */
app.listen(process.env.PORT || "3000");

discordBot();
Expand Down
252 changes: 252 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5d7dd19

Please sign in to comment.