Skip to content

Commit f870a02

Browse files
committed
setup sentry, monitoring errors
1 parent 37c93b6 commit f870a02

File tree

8 files changed

+98
-11
lines changed

8 files changed

+98
-11
lines changed

buzzy.config.demo.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module.exports = {
22
env: {
3-
HTML_TITLE: "Yumin's Notes",
3+
HTML_TITLE: "Awesome JavaScript",
44
API_PROD: "http://localhost:8080", // deploy next app and wp in the same vm instance
55
API_DEV: "http://localhost:8080",
66
GA_TRACKING_ID: "",
7+
SENTRY_DSN: "",
78
},
89
};

next.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ const withSass = require("@zeit/next-sass");
33
const withCss = require("@zeit/next-css");
44
const buzzy = require("./buzzy.config");
55

6+
const withSourceMaps = require("@zeit/next-source-maps")();
7+
68
const axios = require("axios");
79

810
const enhance = compose(
11+
withSourceMaps,
912
withCss,
1013
withSass
1114
);

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"private": false,
1515
"dependencies": {
1616
"@fortawesome/fontawesome-free": "^5.10.2",
17+
"@sentry/browser": "^5.9.1",
1718
"@zeit/next-sass": "^1.0.1",
19+
"@zeit/next-source-maps": "0.0.4-canary.1",
1820
"axios": "^0.19.0",
1921
"bulma": "^0.7.5",
2022
"express": "^4.17.1",

pages/_app.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import React from "react";
22
import App from "next/app";
3+
import * as Sentry from "@sentry/browser";
34
import Router from "next/router";
5+
import styles from "src/assets/styles/global.scss";
46
import { initGA, logPageView } from "src/utils/google";
57
import Head from "next/head";
68

9+
Sentry.init({ dsn: process.env.SENTRY_DSN });
10+
711
import Layout from "src/components/common/Layout";
812

913
import { PostContextProvider } from "src/contexts/PostContext";
@@ -19,12 +23,27 @@ export default class BuzzyBlogApp extends App {
1923
Router.router.events.on("routeChangeComplete", logPageView);
2024
}
2125

26+
componentDidCatch(error, errorInfo) {
27+
Sentry.withScope((scope) => {
28+
Object.keys(errorInfo).forEach((key) => {
29+
scope.setExtra(key, errorInfo[key]);
30+
});
31+
32+
Sentry.captureException(error);
33+
});
34+
35+
super.componentDidCatch(error, errorInfo);
36+
}
37+
2238
render() {
2339
const { Component, pageProps } = this.props;
2440
return (
2541
<PostContextProvider>
2642
<Head>
2743
<title>{process.env.HTML_TITLE}</title>
44+
<style jsx global>
45+
{styles}
46+
</style>
2847
</Head>
2948
<Layout>
3049
<Component {...pageProps} />

pages/_document.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import Document, { Html, Head, Main, NextScript } from "next/document";
2-
import styles from "src/assets/styles/global.scss";
2+
import * as Sentry from "@sentry/browser";
3+
4+
process.on("unhandledRejection", (err) => {
5+
Sentry.captureException(err);
6+
});
7+
8+
process.on("uncaughtException", (err) => {
9+
Sentry.captureException(err);
10+
});
311

412
class MyDocument extends Document {
513
// static async getInitialProps(ctx) {
@@ -12,9 +20,6 @@ class MyDocument extends Document {
1220
<Html>
1321
<Head>
1422
<link type="shortcut icon" type="image/x-icon" href="/favicon.ico" />
15-
<style jsx global>
16-
{styles}
17-
</style>
1823
</Head>
1924
<body>
2025
<Main />

src/assets/styles/global.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ body,
88
cursor: pointer;
99
}
1010

11+
.is-clickable:hover {
12+
text-decoration: underline;
13+
}
14+
1115
@media screen and (min-width: 769px) {
1216
.is-x-paddingless-desktop {
1317
padding-left: 0 !important;

src/components/posts/BaseContainer.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ const BaseContainer = (props) => {
2626
{sortedPosts.map((post) => {
2727
return (
2828
<div className="tile is-child" key={post.id}>
29-
<div
30-
style={{ marginBottom: "0.5rem" }}
31-
className="title is-clickable is-flex"
32-
onClick={() => handlePostOnClick(post)}
33-
>
29+
<div className="title is-clickable is-flex" onClick={() => handlePostOnClick(post)}>
3430
<h4 className="title is-4">{post.title.rendered}</h4>
3531
</div>
3632
<div className="tags has-addons is-marginless">

yarn.lock

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,58 @@
10071007
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free/-/fontawesome-free-5.10.2.tgz#27e02da1e34b50c9869179d364fb46627b521130"
10081008
integrity sha512-9pw+Nsnunl9unstGEHQ+u41wBEQue6XPBsILXtJF/4fNN1L3avJcMF/gGF86rIjeTAgfLjTY9ndm68/X4f4idQ==
10091009

1010+
"@sentry/browser@^5.9.1":
1011+
version "5.9.1"
1012+
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-5.9.1.tgz#b2ec27ead501a49f26807a9c0774f44f4292f236"
1013+
integrity sha512-7AOabwp9yAH9h6Xe6TfDwlLxHbUSWs+SPWHI7bPlht2yDSAqkXYGSzRr5X0XQJX9oBQdx2cEPMqHyJrbNaP/og==
1014+
dependencies:
1015+
"@sentry/core" "5.8.0"
1016+
"@sentry/types" "5.7.1"
1017+
"@sentry/utils" "5.8.0"
1018+
tslib "^1.9.3"
1019+
1020+
1021+
version "5.8.0"
1022+
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-5.8.0.tgz#bbfd2f4711491951a8e3a0e8fa8b172fdf7bff6f"
1023+
integrity sha512-aAh2KLidIXJVGrxmHSVq2eVKbu7tZiYn5ylW6yzJXFetS5z4MA+JYaSBaG2inVYDEEqqMIkb17TyWxxziUDieg==
1024+
dependencies:
1025+
"@sentry/hub" "5.8.0"
1026+
"@sentry/minimal" "5.8.0"
1027+
"@sentry/types" "5.7.1"
1028+
"@sentry/utils" "5.8.0"
1029+
tslib "^1.9.3"
1030+
1031+
1032+
version "5.8.0"
1033+
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-5.8.0.tgz#56aaeb7324cb66d90db838011cb0127f5558007f"
1034+
integrity sha512-VdApn1ZCNwH1wwQwoO6pu53PM/qgHG+DQege0hbByluImpLBhAj9w50nXnF/8KzV4UoMIVbzCb6jXzMRmqqp9A==
1035+
dependencies:
1036+
"@sentry/types" "5.7.1"
1037+
"@sentry/utils" "5.8.0"
1038+
tslib "^1.9.3"
1039+
1040+
1041+
version "5.8.0"
1042+
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-5.8.0.tgz#b7ad5113504ab67f1ef2b0f465b7ba608e6b8dc5"
1043+
integrity sha512-MIlFOgd+JvAUrBBmq7vr9ovRH1HvckhnwzHdoUPpKRBN+rQgTyZy1o6+kA2fASCbrRqFCP+Zk7EHMACKg8DpIw==
1044+
dependencies:
1045+
"@sentry/hub" "5.8.0"
1046+
"@sentry/types" "5.7.1"
1047+
tslib "^1.9.3"
1048+
1049+
1050+
version "5.7.1"
1051+
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-5.7.1.tgz#4c4c1d4d891b6b8c2c3c7b367d306a8b1350f090"
1052+
integrity sha512-tbUnTYlSliXvnou5D4C8Zr+7/wJrHLbpYX1YkLXuIJRU0NSi81bHMroAuHWILcQKWhVjaV/HZzr7Y/hhWtbXVQ==
1053+
1054+
1055+
version "5.8.0"
1056+
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-5.8.0.tgz#34683088159b9935f973b6e6cad1a1cc26bbddac"
1057+
integrity sha512-KDxUvBSYi0/dHMdunbxAxD3389pcQioLtcO6CI6zt/nJXeVFolix66cRraeQvqupdLhvOk/el649W4fCPayTHw==
1058+
dependencies:
1059+
"@sentry/types" "5.7.1"
1060+
tslib "^1.9.3"
1061+
10101062
"@types/anymatch@*":
10111063
version "1.3.1"
10121064
resolved "https://registry.yarnpkg.com/@types/anymatch/-/anymatch-1.3.1.tgz#336badc1beecb9dacc38bea2cf32adf627a8421a"
@@ -1255,6 +1307,11 @@
12551307
"@zeit/next-css" "1.0.1"
12561308
sass-loader "6.0.6"
12571309

1310+
1311+
version "0.0.4-canary.1"
1312+
resolved "https://registry.yarnpkg.com/@zeit/next-source-maps/-/next-source-maps-0.0.4-canary.1.tgz#5051ff8425e5f615da2d21dd08a99284fbb63d7d"
1313+
integrity sha512-SPQCLs7ToaqzQnqXqGSCoL7KTlnOAao+1F5hy7Hkuq85TjHsUC3eeLsmVrBIraIhXG/ARHmZ0JHOesPDtBfpzw==
1314+
12581315
abbrev@1:
12591316
version "1.1.1"
12601317
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
@@ -7830,7 +7887,7 @@ ts-pnp@^1.1.2:
78307887
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.1.4.tgz#ae27126960ebaefb874c6d7fa4729729ab200d90"
78317888
integrity sha512-1J/vefLC+BWSo+qe8OnJQfWTYRS6ingxjwqmHMqaMxXMj7kFtKLgAaYW3JeX3mktjgUL+etlU8/B4VUAUI9QGw==
78327889

7833-
tslib@^1.9.0:
7890+
tslib@^1.9.0, tslib@^1.9.3:
78347891
version "1.10.0"
78357892
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
78367893
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==

0 commit comments

Comments
 (0)