diff --git a/package.json b/package.json index a036325..2d89fa5 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "@babylonjs/core": "^4.1.0", "@babylonjs/loaders": "^4.1.0", "@msgpack/msgpack": "^1.12.1", + "@sentry/react": "^5.27.1", "@stripe/stripe-js": "^1.3.2", "@tensorflow/tfjs": "^2.6.0", "@testing-library/jest-dom": "^4.2.4", diff --git a/src/helpers/logging.js b/src/helpers/logging.js new file mode 100644 index 0000000..a80ff82 --- /dev/null +++ b/src/helpers/logging.js @@ -0,0 +1,8 @@ +import { captureException } from "@sentry/react"; + +export function logError(error) { + console.error(error); + if (process.env.NODE_ENV === "production") { + captureException(error); + } +} diff --git a/src/helpers/map.js b/src/helpers/map.js index b59601b..3ded592 100644 --- a/src/helpers/map.js +++ b/src/helpers/map.js @@ -1,5 +1,7 @@ import GridSizeModel from "../ml/gridSize/GridSizeModel"; +import { logError } from "./logging"; + export function getMapDefaultInset(width, height, gridX, gridY) { // Max the width const gridScale = width / gridX; @@ -140,7 +142,7 @@ export async function getGridSize(image) { try { prediction = await gridSizeML(image, candidates); } catch (error) { - console.error(error); + logError(error); } if (!prediction) { diff --git a/src/index.js b/src/index.js index 44247da..a2c2acd 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,6 @@ import React from "react"; import ReactDOM from "react-dom"; +import * as Sentry from "@sentry/react"; import App from "./App"; import Modal from "react-modal"; @@ -10,6 +11,14 @@ import * as serviceWorker from "./serviceWorker"; import "./index.css"; +if (process.env.NODE_ENV === "production") { + Sentry.init({ + dsn: + "https://bc1e2edfe7ca453f8e7357a48693979e@o467475.ingest.sentry.io/5493956", + release: "owlbear-rodeo@" + process.env.REACT_APP_VERSION, + }); +} + Modal.setAppElement("#root"); ReactDOM.render(, document.getElementById("root")); diff --git a/src/network/Connection.js b/src/network/Connection.js index 40c490d..88eade3 100644 --- a/src/network/Connection.js +++ b/src/network/Connection.js @@ -3,6 +3,7 @@ import { encode, decode } from "@msgpack/msgpack"; import shortid from "shortid"; import blobToBuffer from "../helpers/blobToBuffer"; +import { logError } from "../helpers/logging"; // Limit buffer size to 16kb to avoid issues with chrome packet size // http://viblast.com/blog/2015/2/5/webrtc-data-channel-message-size/ @@ -78,7 +79,7 @@ class Connection extends SimplePeer { } } } catch (error) { - console.error(error); + logError(error); } } diff --git a/src/network/Session.js b/src/network/Session.js index f410afd..0978a4f 100644 --- a/src/network/Session.js +++ b/src/network/Session.js @@ -4,6 +4,7 @@ import { EventEmitter } from "events"; import Connection from "./Connection"; import { omit } from "../helpers/shared"; +import { logError } from "../helpers/logging"; /** * @typedef {object} SessionPeer @@ -112,8 +113,8 @@ class Session extends EventEmitter { const data = await response.json(); this._iceServers = data.iceServers; this.socket.emit("join party", partyId, password); - } catch (e) { - console.error("Unable to join party:", e.message); + } catch (error) { + logError(error); this.emit("disconnected"); } } @@ -190,6 +191,7 @@ class Session extends EventEmitter { this.peers[id] = peer; } catch (error) { + logError(error); this.emit("error", { error }); } } diff --git a/src/routes/Donate.js b/src/routes/Donate.js index 2a8f8d9..35f2441 100644 --- a/src/routes/Donate.js +++ b/src/routes/Donate.js @@ -15,6 +15,8 @@ import Footer from "../components/Footer"; import Banner from "../components/Banner"; import LoadingOverlay from "../components/LoadingOverlay"; +import { logError } from "../helpers/logging"; + const prices = [ { price: "$5.00", name: "Small", value: 5 }, { price: "$15.00", name: "Medium", value: 15 }, @@ -36,8 +38,9 @@ function Donate() { setStripe(stripe); setLoading(false); }) - .catch((err) => { - setError(err.message); + .catch((error) => { + logError(error); + setError(error.message); setLoading(false); }); }); diff --git a/src/routes/Game.js b/src/routes/Game.js index f82b7b8..83953a6 100644 --- a/src/routes/Game.js +++ b/src/routes/Game.js @@ -49,7 +49,6 @@ function Game() { const [peerError, setPeerError] = useState(null); useEffect(() => { function handlePeerError({ error }) { - console.error(error.code); if (error.code === "ERR_WEBRTC_SUPPORT") { setPeerError("WebRTC not supported."); } else if (error.code === "ERR_CREATE_OFFER") { diff --git a/yarn.lock b/yarn.lock index 489ead7..e72fada 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1537,6 +1537,70 @@ resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b" integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw== +"@sentry/browser@5.27.1": + version "5.27.1" + resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-5.27.1.tgz#67da0cb9680ed54ecdb56a66abd8183b5a8ee174" + integrity sha512-OPBtKKJDgpJOJILaXntGp0z5KT2I1fmtePnHDdgPd7uNqXfTw0E6bvSjY9bR0pSJSooSwqZAAnsAZg8t4772ow== + dependencies: + "@sentry/core" "5.27.1" + "@sentry/types" "5.27.1" + "@sentry/utils" "5.27.1" + tslib "^1.9.3" + +"@sentry/core@5.27.1": + version "5.27.1" + resolved "https://registry.yarnpkg.com/@sentry/core/-/core-5.27.1.tgz#489604054d821e1de155f80fe650085b37cad235" + integrity sha512-n5CxzMbOAT6HZK4U4cOUAAikkRnnHhMNhInrjfZh7BoiuX1k63Hru2H5xk5WDuEaTTr5RaBA/fqPl7wxHySlwQ== + dependencies: + "@sentry/hub" "5.27.1" + "@sentry/minimal" "5.27.1" + "@sentry/types" "5.27.1" + "@sentry/utils" "5.27.1" + tslib "^1.9.3" + +"@sentry/hub@5.27.1": + version "5.27.1" + resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-5.27.1.tgz#c95faaf18257c365acc09246fafd27276bfd6a2f" + integrity sha512-RBHo3T92s6s4Ian1pZcPlmNtFqB+HAP6xitU+ZNA48bYUK+R1vvqEcI8Xs83FyNaRGCgclp9erDFQYyAuxY4vw== + dependencies: + "@sentry/types" "5.27.1" + "@sentry/utils" "5.27.1" + tslib "^1.9.3" + +"@sentry/minimal@5.27.1": + version "5.27.1" + resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-5.27.1.tgz#d6ce881ba3c262db29520177a4c1f0e0f5388697" + integrity sha512-MHXCeJdA1NAvaJuippcM8nrWScul8iTN0Q5nnFkGctGIGmmiZHTXAYkObqJk7H3AK+CP7r1jqN2aQj5Nd9CtyA== + dependencies: + "@sentry/hub" "5.27.1" + "@sentry/types" "5.27.1" + tslib "^1.9.3" + +"@sentry/react@^5.27.1": + version "5.27.1" + resolved "https://registry.yarnpkg.com/@sentry/react/-/react-5.27.1.tgz#1accad75dd7302d6486b8d4657673d56ebfb7fa7" + integrity sha512-iKJgF3ZfIbKC9pCTip+xnu7JYAYryDgobknj/NmT7nbfeSE2oJHFZYsMk+BzxxKaEFcYfMeJvtm3Ijq1Nm1Khw== + dependencies: + "@sentry/browser" "5.27.1" + "@sentry/minimal" "5.27.1" + "@sentry/types" "5.27.1" + "@sentry/utils" "5.27.1" + hoist-non-react-statics "^3.3.2" + tslib "^1.9.3" + +"@sentry/types@5.27.1": + version "5.27.1" + resolved "https://registry.yarnpkg.com/@sentry/types/-/types-5.27.1.tgz#031480a4cf8f0b6e6337fb03ee884deedcef6f40" + integrity sha512-g1aX0V0fz5BTo0mjgSVY9XmPLGZ6p+8OEzq3ubKzDUf59VHl+Vt8viZ8VXw/vsNtfAjBHn7BzSuzJo7cXJJBtA== + +"@sentry/utils@5.27.1": + version "5.27.1" + resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-5.27.1.tgz#0ed9d9685aae6f4ef9eb6b9ebb81e361fd1c5452" + integrity sha512-VIzK8utuvFO9EogZcKJPgmLnlJtYbaPQ0jCw7od9HRw1ckrSBc84sA0uuuY6pB6KSM+7k6EjJ5IdIBaCz5ep/A== + dependencies: + "@sentry/types" "5.27.1" + tslib "^1.9.3" + "@sheerun/mutationobserver-shim@^0.3.2": version "0.3.3" resolved "https://registry.yarnpkg.com/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.3.tgz#5405ee8e444ed212db44e79351f0c70a582aae25" @@ -5846,7 +5910,7 @@ hmac-drbg@^1.0.0: minimalistic-assert "^1.0.0" minimalistic-crypto-utils "^1.0.1" -hoist-non-react-statics@^3.1.0: +hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.3.2: version "3.3.2" resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45" integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw== @@ -11522,6 +11586,11 @@ tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.13.0.tgz#c881e13cc7015894ed914862d276436fa9a47043" integrity sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q== +tslib@^1.9.3: + version "1.14.1" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" + integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== + tsutils@^3.17.1: version "3.17.1" resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759"