Skip to content

Commit b3b7a02

Browse files
authored
Upgrade to sentry (thedevs-network#374)
1 parent 0a2f295 commit b3b7a02

File tree

8 files changed

+204
-59
lines changed

8 files changed

+204
-59
lines changed

client/helpers/analytics.ts

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import getConfig from "next/config";
22
import ReactGA from "react-ga";
3+
import * as Sentry from '@sentry/react';
4+
import { Integrations } from '@sentry/apm';
35

46
const { publicRuntimeConfig } = getConfig();
57

@@ -12,6 +14,19 @@ export const logPageView = () => {
1214
ReactGA.pageview(window.location.pathname);
1315
};
1416

17+
export const initSentry = () => {
18+
if (publicRuntimeConfig.SENTRY_PUBLIC_DSN) {
19+
Sentry.init({
20+
dsn: publicRuntimeConfig.SENTRY_PUBLIC_DSN,
21+
environment: process.env.NODE_ENV,
22+
integrations: [
23+
new Integrations.Tracing(),
24+
],
25+
tracesSampleRate: 1.0,
26+
});
27+
};
28+
};
29+
1530
export const logEvent = (category = "", action = "") => {
1631
if (category && action) {
1732
ReactGA.event({ category, action });

client/pages/_app.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ import cookie from "js-cookie";
77
import Head from "next/head";
88
import React from "react";
99

10-
import { initGA, logPageView } from "../helpers/analytics";
10+
import { initGA, logPageView , initSentry } from "../helpers/analytics";
1111
import { initializeStore } from "../store";
1212
import { TokenPayload } from "../types";
1313

1414
const isProd = process.env.NODE_ENV === "production";
1515
const { publicRuntimeConfig } = getConfig();
1616

17+
if (isProd) {
18+
initSentry();
19+
};
20+
1721
// TODO: types
1822
class MyApp extends App<any> {
1923
static async getInitialProps({ Component, ctx }: AppContext) {

next.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
GOOGLE_ANALYTICS: localEnv && localEnv.GOOGLE_ANALYTICS,
1010
REPORT_EMAIL: localEnv && localEnv.REPORT_EMAIL,
1111
DISALLOW_ANONYMOUS_LINKS: localEnv && localEnv.DISALLOW_ANONYMOUS_LINKS,
12-
DISALLOW_REGISTRATION: localEnv && localEnv.DISALLOW_REGISTRATION
12+
DISALLOW_REGISTRATION: localEnv && localEnv.DISALLOW_REGISTRATION,
13+
SENTRY_PUBLIC_DSN: localEnv && localEnv.SENTRY_PUBLIC_DSN,
1314
}
1415
};

package-lock.json

+160-45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
},
3636
"homepage": "https://github.com/TheDevs-Network/kutt#readme",
3737
"dependencies": {
38+
"@sentry/apm": "^5.21.1",
39+
"@sentry/node": "^5.21.1",
40+
"@sentry/react": "^5.21.1",
3841
"axios": "^0.19.1",
3942
"babel-plugin-inline-react-svg": "^1.1.0",
4043
"bcryptjs": "^2.4.3",
@@ -74,7 +77,6 @@
7477
"prop-types": "^15.7.2",
7578
"qrcode.react": "^0.8.0",
7679
"query-string": "^6.10.1",
77-
"raven": "^2.6.4",
7880
"react": "^16.12.0",
7981
"react-copy-to-clipboard": "^5.0.2",
8082
"react-dom": "^16.12.0",

server/env.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const env = cleanEnv(process.env, {
4040
MAIL_PASSWORD: str(),
4141
REPORT_EMAIL: str({ default: "" }),
4242
CONTACT_EMAIL: str({ default: "" }),
43-
RAVEN_DSN: str({ default: "" })
43+
SENTRY_PRIVATE_DSN: str({ default: "" }),
44+
SENTRY_PUBLIC_DSN: str({ default: "" })
4445
});
4546

4647
export default env;

server/handlers/helpers.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Handler, ErrorRequestHandler } from "express";
22
import { validationResult } from "express-validator";
3-
import Raven from "raven";
3+
import * as Sentry from "@sentry/node";
44
import signale from "signale";
55

66
import { CustomError } from "../utils";
@@ -21,10 +21,8 @@ export const error: ErrorRequestHandler = (error, req, res, next) => {
2121
return res.status(error.statusCode || 500).json({ error: error.message });
2222
}
2323

24-
if (env.RAVEN_DSN) {
25-
Raven.captureException(error, {
26-
user: { email: req.user && req.user.email }
27-
});
24+
if (env.SENTRY_PRIVATE_DSN) {
25+
Sentry.captureException(error);
2826
}
2927

3028
return res.status(500).json({ error: "An error occurred." });

0 commit comments

Comments
 (0)