From de1857bf26124246752bb370f54508cdab7a57c2 Mon Sep 17 00:00:00 2001 From: Alexey Ivanov Date: Mon, 10 Feb 2020 22:51:23 +0900 Subject: [PATCH 1/2] Revert "Revert "Add sentry"" This reverts commit c21785f2b9d42b9f018f70e9f343c13e8a523925. --- next.config.js | 14 +++++++++++ package.json | 2 ++ pages/_app.js | 41 ++++++++++++++++++++++++++++++++ pages/_document.js | 11 +++++++++ yarn.lock | 59 +++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 next.config.js create mode 100644 pages/_app.js diff --git a/next.config.js b/next.config.js new file mode 100644 index 0000000000..c1a8c1a98c --- /dev/null +++ b/next.config.js @@ -0,0 +1,14 @@ +/* eslint-env node */ + +const withSourceMaps = require('@zeit/next-source-maps') + +const settings = withSourceMaps({ + webpack(config) { + return config + }, + env: { + SENTRY_DSN: process.env.SENTRY_DSN + } +}) + +module.exports = settings diff --git a/package.json b/package.json index 0e11f3d286..5efbfb1946 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ }, "homepage": "https://github.com/iterative/dvc.org#readme", "dependencies": { + "@sentry/browser": "^5.12.1", "color": "^3.1.2", "dom-scroll-into-view": "^2.0.1", "github-markdown-css": "^3.0.1", @@ -59,6 +60,7 @@ }, "devDependencies": { "@babel/core": "^7.7.7", + "@zeit/next-source-maps": "^0.0.3", "babel-eslint": "^10.0.3", "babel-jest": "^24.9.0", "babel-plugin-transform-define": "^2.0.0", diff --git a/pages/_app.js b/pages/_app.js new file mode 100644 index 0000000000..39bcd60c70 --- /dev/null +++ b/pages/_app.js @@ -0,0 +1,41 @@ +/* global process */ + +import React from 'react' +import App from 'next/app' +import * as Sentry from '@sentry/browser' + +Sentry.init({ + dsn: process.env.SENTRY_DSN +}) + +class MyApp extends App { + static async getInitialProps({ Component, ctx }) { + let pageProps = {} + + if (Component.getInitialProps) { + pageProps = await Component.getInitialProps(ctx) + } + + return { pageProps } + } + + componentDidCatch(error, errorInfo) { + Sentry.withScope(scope => { + Object.keys(errorInfo).forEach(key => { + scope.setExtra(key, errorInfo[key]) + }) + + Sentry.captureException(error) + }) + + super.componentDidCatch(error, errorInfo) + } + + render() { + const { Component, pageProps } = this.props + + return + } +} + +export default MyApp diff --git a/pages/_document.js b/pages/_document.js index 5b5216aef3..c9e36105e5 100644 --- a/pages/_document.js +++ b/pages/_document.js @@ -1,6 +1,17 @@ +/* eslint-env node */ + import React from 'react' import Document, { Head, Main, NextScript } from 'next/document' import { ServerStyleSheet } from 'styled-components' +import * as Sentry from '@sentry/browser' + +process.on('unhandledRejection', err => { + Sentry.captureException(err) +}) + +process.on('uncaughtException', err => { + Sentry.captureException(err) +}) import { META_BASE_TITLE, diff --git a/yarn.lock b/yarn.lock index 407d7d3ac2..ddb3e900d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1094,6 +1094,58 @@ dependencies: any-observable "^0.3.0" +"@sentry/browser@^5.12.1": + version "5.12.1" + resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-5.12.1.tgz#dc1f268595269fb7277f55eb625c7e92d76dc01b" + integrity sha512-Zl7VdppUxctyaoqMSEhnDJp2rrupx8n8N2n3PSooH74yhB2Z91nt84mouczprBsw3JU1iggGyUw9seRFzDI1hw== + dependencies: + "@sentry/core" "5.12.0" + "@sentry/types" "5.12.0" + "@sentry/utils" "5.12.0" + tslib "^1.9.3" + +"@sentry/core@5.12.0": + version "5.12.0" + resolved "https://registry.yarnpkg.com/@sentry/core/-/core-5.12.0.tgz#d6380c4ef7beee5f418ac1d0e5be86a2de2af449" + integrity sha512-wY4rsoX71QsGpcs9tF+OxKgDPKzIFMRvFiSRcJoPMfhFsTilQ/CBMn/c3bDtWQd9Bnr/ReQIL6NbnIjUsPHA4Q== + dependencies: + "@sentry/hub" "5.12.0" + "@sentry/minimal" "5.12.0" + "@sentry/types" "5.12.0" + "@sentry/utils" "5.12.0" + tslib "^1.9.3" + +"@sentry/hub@5.12.0": + version "5.12.0" + resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-5.12.0.tgz#5e8c8f249f5bdbeb8cc4ec02c2ccc53a67f2cc02" + integrity sha512-3k7yE8BEVJsKx8mR4LcI4IN0O8pngmq44OcJ/fRUUBAPqsT38jsJdP2CaWhdlM1jiNUzUDB1ktBv6/lY+VgcoQ== + dependencies: + "@sentry/types" "5.12.0" + "@sentry/utils" "5.12.0" + tslib "^1.9.3" + +"@sentry/minimal@5.12.0": + version "5.12.0" + resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-5.12.0.tgz#2611e2aa520c1edb7999e6de51bd65ec66341757" + integrity sha512-fk73meyz4k4jCg9yzbma+WkggsfEIQWI2e2TWfYsRGcrV3RnlSrXyM4D91/A8Bjx10SNezHPUFHjasjlHXOkyA== + dependencies: + "@sentry/hub" "5.12.0" + "@sentry/types" "5.12.0" + tslib "^1.9.3" + +"@sentry/types@5.12.0": + version "5.12.0" + resolved "https://registry.yarnpkg.com/@sentry/types/-/types-5.12.0.tgz#5367e53c74261beea01502e3f7b6f3d822682a31" + integrity sha512-aZbBouBLrKB8wXlztriIagZNmsB+wegk1Jkl6eprqRW/w24Sl/47tiwH8c5S4jYTxdAiJk+SAR10AAuYmIN3zg== + +"@sentry/utils@5.12.0": + version "5.12.0" + resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-5.12.0.tgz#62967f934a3ee6d21472eac0219084e37225933e" + integrity sha512-fYUadGLbfTCbs4OG5hKCOtv2jrNE4/8LHNABy9DwNJ/t5DVtGqWAZBnxsC+FG6a3nVqCpxjFI9AHlYsJ2wsf7Q== + dependencies: + "@sentry/types" "5.12.0" + tslib "^1.9.3" + "@types/babel__core@^7.1.0": version "7.1.3" resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.3.tgz#e441ea7df63cd080dfcd02ab199e6d16a735fc30" @@ -1345,6 +1397,11 @@ resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d" integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ== +"@zeit/next-source-maps@^0.0.3": + version "0.0.3" + resolved "https://registry.yarnpkg.com/@zeit/next-source-maps/-/next-source-maps-0.0.3.tgz#d62e93b4f5ccdd542c8530d21f60dd2757d98e3c" + integrity sha512-gFDf7yQI8r/fdzTKJG9cp0rhKscRJWs/uebhScj8nZINT16kPTVm23JAi5EivO5pAJmHGzT1A8dwxAhTX0liNw== + abab@^2.0.0: version "2.0.3" resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.3.tgz#623e2075e02eb2d3f2475e49f99c91846467907a" @@ -8530,7 +8587,7 @@ ts-pnp@^1.1.2: resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.1.5.tgz#840e0739c89fce5f3abd9037bb091dbff16d9dec" integrity sha512-ti7OGMOUOzo66wLF3liskw6YQIaSsBgc4GOAlWRnIEj8htCxJUxskanMUoJOD6MDCRAXo36goXJZch+nOS0VMA== -tslib@^1.9.0: +tslib@^1.9.0, tslib@^1.9.3: version "1.10.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== From 98711eec0b2a6552b0faa905ccf4b562b4898dbd Mon Sep 17 00:00:00 2001 From: Alexey Ivanov Date: Mon, 10 Feb 2020 23:44:59 +0900 Subject: [PATCH 2/2] Move sourcemaps to dependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5efbfb1946..6b2cc58983 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "homepage": "https://github.com/iterative/dvc.org#readme", "dependencies": { "@sentry/browser": "^5.12.1", + "@zeit/next-source-maps": "^0.0.3", "color": "^3.1.2", "dom-scroll-into-view": "^2.0.1", "github-markdown-css": "^3.0.1", @@ -60,7 +61,6 @@ }, "devDependencies": { "@babel/core": "^7.7.7", - "@zeit/next-source-maps": "^0.0.3", "babel-eslint": "^10.0.3", "babel-jest": "^24.9.0", "babel-plugin-transform-define": "^2.0.0",