Skip to content

Commit 61e401d

Browse files
feat: Add runtime tags to errors (#3327)
1 parent 3db3cce commit 61e401d

File tree

5 files changed

+17
-115
lines changed

5 files changed

+17
-115
lines changed
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import { withScope, captureException } from '@sentry/nextjs';
2-
3-
export default async function onErrorClient({ err, errorInfo, renderErrorProps, data, version }) {
4-
// TODO: Extract some useful metadata from the router and other arguments — Kamil
1+
import { withScope, captureException, captureMessage } from '@sentry/nextjs';
52

3+
export default async function onErrorClient({ err }) {
64
withScope(scope => {
7-
if (typeof errorInfo?.componentStack === 'string') {
8-
scope.setContext('react', {
9-
componentStack: errorInfo.componentStack.trim(),
10-
});
5+
if (err instanceof Error) {
6+
captureException(err);
7+
} else {
8+
captureMessage(err.message);
119
}
12-
captureException(err);
1310
});
1411
}

packages/nextjs/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
},
1818
"dependencies": {
1919
"@sentry/core": "6.2.1",
20-
"@sentry/minimal": "6.2.1",
20+
"@sentry/next-plugin-sentry": "6.2.1",
2121
"@sentry/node": "6.2.1",
2222
"@sentry/react": "6.2.1",
23-
"@sentry/next-plugin-sentry": "6.2.1",
24-
"@sentry/wizard": "^1.2.1",
25-
"@sentry/webpack-plugin": "^1.14.1"
23+
"@sentry/webpack-plugin": "^1.14.1",
24+
"@sentry/wizard": "^1.2.1"
2625
},
2726
"devDependencies": {
2827
"@sentry/types": "6.2.1",

packages/nextjs/src/node.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { init as nodeInit } from '@sentry/node';
1+
import { configureScope, init as nodeInit } from '@sentry/node';
22

33
import { InitDecider } from './utils/initDecider';
44
import { MetadataBuilder } from './utils/metadataBuilder';
@@ -17,6 +17,9 @@ export function init(options: NextjsOptions): any {
1717
const initDecider = new InitDecider(options);
1818
if (initDecider.shouldInitSentry()) {
1919
nodeInit(options);
20+
configureScope(scope => {
21+
scope.setTag('runtime', 'node');
22+
});
2023
} else {
2124
// eslint-disable-next-line no-console
2225
console.warn('[Sentry] Detected a non-production environment. Not initializing Sentry.');

packages/nextjs/src/react.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { init as reactInit } from '@sentry/react';
1+
import { configureScope, init as reactInit } from '@sentry/react';
22

33
import { InitDecider } from './utils/initDecider';
44
import { MetadataBuilder } from './utils/metadataBuilder';
@@ -13,6 +13,9 @@ export function init(options: NextjsOptions): any {
1313
const initDecider = new InitDecider(options);
1414
if (initDecider.shouldInitSentry()) {
1515
reactInit(options);
16+
configureScope(scope => {
17+
scope.setTag('runtime', 'browser');
18+
});
1619
} else {
1720
// eslint-disable-next-line no-console
1821
console.warn('[Sentry] Detected a non-production environment. Not initializing Sentry.');

yarn.lock

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,16 +3276,6 @@
32763276
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
32773277
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=
32783278

3279-
3280-
version "6.2.1"
3281-
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-6.2.1.tgz#f9f277e6f8cad0c7efd1a01726095d63a47a1c16"
3282-
integrity sha512-OAikFZ9EimD3noxMp8tA6Cf6qJcQ2U8k5QSgTPwdx+09nZOGJzbRFteK7WWmrS93ZJdzN61lpSQbg5v+bmmfbQ==
3283-
dependencies:
3284-
"@sentry/core" "6.2.1"
3285-
"@sentry/types" "6.2.1"
3286-
"@sentry/utils" "6.2.1"
3287-
tslib "^1.9.3"
3288-
32893279
"@sentry/cli@^1.52.4", "@sentry/cli@^1.58.0":
32903280
version "1.63.0"
32913281
resolved "https://registry.yarnpkg.com/@sentry/cli/-/cli-1.63.0.tgz#e69f05e2abab3c68a68958b55556618067e1dea9"
@@ -3297,96 +3287,6 @@
32973287
progress "^2.0.3"
32983288
proxy-from-env "^1.1.0"
32993289

3300-
3301-
version "6.2.1"
3302-
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.2.1.tgz#8b177e9bf591e2e7ddcb04f0b1403de3f5aa8755"
3303-
integrity sha512-jPqQEtafxxDtLONhCbTHh/Uq8mZRhsfbwJTSVYfPVEe/ELfFZLQK7tP6rOh7zEWKbTkE0mE6XcaoH3ZRAhgrqg==
3304-
dependencies:
3305-
"@sentry/hub" "6.2.1"
3306-
"@sentry/minimal" "6.2.1"
3307-
"@sentry/types" "6.2.1"
3308-
"@sentry/utils" "6.2.1"
3309-
tslib "^1.9.3"
3310-
3311-
3312-
version "6.2.1"
3313-
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.2.1.tgz#35bc6bf841a93f4354b3a17592c938b3dba20b73"
3314-
integrity sha512-pG7wCQeRpzeP6t0bT4T0X029R19dbDS3/qswF8BL6bg0AI3afjfjBAZm/fqn1Uwe/uBoMHVVdbxgJDZeQ5d4rQ==
3315-
dependencies:
3316-
"@sentry/types" "6.2.1"
3317-
"@sentry/utils" "6.2.1"
3318-
tslib "^1.9.3"
3319-
3320-
3321-
version "6.2.1"
3322-
resolved "https://registry.yarnpkg.com/@sentry/integrations/-/integrations-6.2.1.tgz#caa9b49de29523698668d45827633be86b2268ff"
3323-
integrity sha512-UBvuil/b9M5HGH6aBDzTiIVRsmpC/wqwDKy28IO05XLdalmKgJ9C1EQhoyN6xw+1lINpXXFtfq4NhfgZgWbc7Q==
3324-
dependencies:
3325-
"@sentry/types" "6.2.1"
3326-
"@sentry/utils" "6.2.1"
3327-
localforage "^1.8.1"
3328-
tslib "^1.9.3"
3329-
3330-
3331-
version "6.2.1"
3332-
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.2.1.tgz#8f01480e1b56bc7dd54adf925e5317f233e19384"
3333-
integrity sha512-wuSXB4Ayxv9rBEQ4pm7fnG4UU2ZPtPnnChoEfd4/mw1UthXSvmPFEn6O4pdo2G8fTkl8eqm6wT/Q7uIXMEmw+A==
3334-
dependencies:
3335-
"@sentry/hub" "6.2.1"
3336-
"@sentry/types" "6.2.1"
3337-
tslib "^1.9.3"
3338-
3339-
3340-
version "6.2.1"
3341-
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-6.2.1.tgz#111418d2cc2245512bc5e46786c373d7d5202525"
3342-
integrity sha512-JlixtJHS6xMzh2G4Pz7oMM8Nd40mGUALQYtuGMwW2QE3IduOaaGsn1+eVpN6PwZetMnvRIn6VVFOc2UmFIzWpA==
3343-
dependencies:
3344-
"@sentry/core" "6.2.1"
3345-
"@sentry/hub" "6.2.1"
3346-
"@sentry/tracing" "6.2.1"
3347-
"@sentry/types" "6.2.1"
3348-
"@sentry/utils" "6.2.1"
3349-
cookie "^0.4.1"
3350-
https-proxy-agent "^5.0.0"
3351-
lru_map "^0.3.3"
3352-
tslib "^1.9.3"
3353-
3354-
3355-
version "6.2.1"
3356-
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-6.2.1.tgz#26587f3f47e9699003b04ac558d8aa8a2b7416d7"
3357-
integrity sha512-emJnYVASM2hej2f8eSjqiDRMljwLsDJDSwa6kVc5HUOs9gnVrE4MR+vSywraACf5tKZbH1YI+NUXCmR++fIB0g==
3358-
dependencies:
3359-
"@sentry/browser" "6.2.1"
3360-
"@sentry/minimal" "6.2.1"
3361-
"@sentry/types" "6.2.1"
3362-
"@sentry/utils" "6.2.1"
3363-
hoist-non-react-statics "^3.3.2"
3364-
tslib "^1.9.3"
3365-
3366-
3367-
version "6.2.1"
3368-
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-6.2.1.tgz#61c18c43c5390c348b35dafe73947ab379252d8f"
3369-
integrity sha512-bvStY1SnL08wkSeVK3j9K5rivQQJdKFCPR2VYRFOCaUoleZ6ChPUnBvxQ/E2LXc0hk/y/wo1q4r5B0dfCCY+bQ==
3370-
dependencies:
3371-
"@sentry/hub" "6.2.1"
3372-
"@sentry/minimal" "6.2.1"
3373-
"@sentry/types" "6.2.1"
3374-
"@sentry/utils" "6.2.1"
3375-
tslib "^1.9.3"
3376-
3377-
3378-
version "6.2.1"
3379-
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.2.1.tgz#28c946230b2023f72307b65606d32052ad9e5353"
3380-
integrity sha512-h0OV1QT+fv5ojfK5/+iEXClu33HirmvbjcQC2jf05IHj9yXIOWy6EB10S8nBjuLiiFqQiAQYj3FN9Ip4eN8NJA==
3381-
3382-
3383-
version "6.2.1"
3384-
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.2.1.tgz#bfcb12c20d44bf2aeb0073b1264703c11c179ebd"
3385-
integrity sha512-6kQgM/yBPdXu+3qbJnI6HBcWztN9QfiMkH++ZiKk4ERhg9d2LYWlze478uTU5Fyo/JQYcp+McpjtjpR9QIrr0g==
3386-
dependencies:
3387-
"@sentry/types" "6.2.1"
3388-
tslib "^1.9.3"
3389-
33903290
"@sentry/webpack-plugin@^1.14.1":
33913291
version "1.14.1"
33923292
resolved "https://registry.yarnpkg.com/@sentry/webpack-plugin/-/webpack-plugin-1.14.1.tgz#f7aceac17820677f6064293d1f5d01ac72012d14"

0 commit comments

Comments
 (0)