@naturalcycles/backend-lib 4.18.5 → 4.18.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,6 +15,7 @@ const sentrySeverityMap = {
|
|
|
15
15
|
};
|
|
16
16
|
const INSPECT_OPT = {
|
|
17
17
|
colors: false,
|
|
18
|
+
includeErrorData: true,
|
|
18
19
|
};
|
|
19
20
|
class SentrySharedService {
|
|
20
21
|
constructor(sentryServiceCfg) {
|
|
@@ -72,7 +73,7 @@ class SentrySharedService {
|
|
|
72
73
|
captureException(err_, logError = true) {
|
|
73
74
|
// normalize the error
|
|
74
75
|
const err = (0, js_lib_1._anyToError)(err_);
|
|
75
|
-
const data =
|
|
76
|
+
const data = (0, js_lib_1._isErrorObject)(err) ? err.data : undefined;
|
|
76
77
|
// Using request-aware logger here
|
|
77
78
|
if (logError) {
|
|
78
79
|
// Log both the error and attached ErrorData (if any)
|
|
@@ -82,20 +83,14 @@ class SentrySharedService {
|
|
|
82
83
|
// Skip reporting the error
|
|
83
84
|
return;
|
|
84
85
|
}
|
|
85
|
-
if (data?.reportRate
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (Math.random() > reportRate)
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
86
|
+
if (data?.reportRate && // E.g rate of 0.1 means 10% of errors are reported
|
|
87
|
+
Math.random() > data.reportRate)
|
|
88
|
+
return;
|
|
91
89
|
// This is to avoid Sentry cutting err.message to 253 characters
|
|
92
90
|
// It will log additional "breadcrumb object" before the error
|
|
93
91
|
// It's a Breadcrumb, not a console.log, because console.log are NOT automatically attached as Breadcrumbs in cron-job environments (outside of Express)
|
|
94
92
|
this.sentry().addBreadcrumb({
|
|
95
|
-
message:
|
|
96
|
-
.filter(js_lib_1._isNotEmpty)
|
|
97
|
-
.map(a => (0, nodejs_lib_1.inspectAny)(a, INSPECT_OPT))
|
|
98
|
-
.join('\n'),
|
|
93
|
+
message: (0, nodejs_lib_1.inspectAny)(err, INSPECT_OPT),
|
|
99
94
|
});
|
|
100
95
|
return this.sentry().captureException(err);
|
|
101
96
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
_anyToError,
|
|
3
|
-
|
|
3
|
+
_isErrorObject,
|
|
4
4
|
_Memo,
|
|
5
|
-
AppError,
|
|
6
5
|
CommonLogger,
|
|
7
6
|
CommonLogLevel,
|
|
8
|
-
ErrorData,
|
|
9
7
|
} from '@naturalcycles/js-lib'
|
|
10
8
|
import { inspectAny, InspectAnyOptions } from '@naturalcycles/nodejs-lib'
|
|
11
9
|
import type { Breadcrumb, NodeOptions, SeverityLevel } from '@sentry/node'
|
|
@@ -25,6 +23,7 @@ const sentrySeverityMap: Record<SeverityLevel, CommonLogLevel> = {
|
|
|
25
23
|
|
|
26
24
|
const INSPECT_OPT: InspectAnyOptions = {
|
|
27
25
|
colors: false,
|
|
26
|
+
includeErrorData: true,
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
export class SentrySharedService {
|
|
@@ -91,7 +90,7 @@ export class SentrySharedService {
|
|
|
91
90
|
captureException(err_: any, logError = true): string | undefined {
|
|
92
91
|
// normalize the error
|
|
93
92
|
const err = _anyToError(err_)
|
|
94
|
-
const data = err
|
|
93
|
+
const data = _isErrorObject(err) ? err.data : undefined
|
|
95
94
|
|
|
96
95
|
// Using request-aware logger here
|
|
97
96
|
if (logError) {
|
|
@@ -104,20 +103,17 @@ export class SentrySharedService {
|
|
|
104
103
|
return
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
if (
|
|
107
|
+
data?.reportRate && // E.g rate of 0.1 means 10% of errors are reported
|
|
108
|
+
Math.random() > data.reportRate
|
|
109
|
+
)
|
|
110
|
+
return
|
|
112
111
|
|
|
113
112
|
// This is to avoid Sentry cutting err.message to 253 characters
|
|
114
113
|
// It will log additional "breadcrumb object" before the error
|
|
115
114
|
// It's a Breadcrumb, not a console.log, because console.log are NOT automatically attached as Breadcrumbs in cron-job environments (outside of Express)
|
|
116
115
|
this.sentry().addBreadcrumb({
|
|
117
|
-
message:
|
|
118
|
-
.filter(_isNotEmpty)
|
|
119
|
-
.map(a => inspectAny(a, INSPECT_OPT))
|
|
120
|
-
.join('\n'),
|
|
116
|
+
message: inspectAny(err, INSPECT_OPT),
|
|
121
117
|
})
|
|
122
118
|
|
|
123
119
|
return this.sentry().captureException(err)
|