@naturalcycles/backend-lib 4.18.4 → 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(Boolean)
|
|
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,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
_anyToError,
|
|
3
|
+
_isErrorObject,
|
|
3
4
|
_Memo,
|
|
4
|
-
AppError,
|
|
5
5
|
CommonLogger,
|
|
6
6
|
CommonLogLevel,
|
|
7
|
-
ErrorData,
|
|
8
7
|
} from '@naturalcycles/js-lib'
|
|
9
8
|
import { inspectAny, InspectAnyOptions } from '@naturalcycles/nodejs-lib'
|
|
10
9
|
import type { Breadcrumb, NodeOptions, SeverityLevel } from '@sentry/node'
|
|
@@ -24,6 +23,7 @@ const sentrySeverityMap: Record<SeverityLevel, CommonLogLevel> = {
|
|
|
24
23
|
|
|
25
24
|
const INSPECT_OPT: InspectAnyOptions = {
|
|
26
25
|
colors: false,
|
|
26
|
+
includeErrorData: true,
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export class SentrySharedService {
|
|
@@ -90,7 +90,7 @@ export class SentrySharedService {
|
|
|
90
90
|
captureException(err_: any, logError = true): string | undefined {
|
|
91
91
|
// normalize the error
|
|
92
92
|
const err = _anyToError(err_)
|
|
93
|
-
const data = err
|
|
93
|
+
const data = _isErrorObject(err) ? err.data : undefined
|
|
94
94
|
|
|
95
95
|
// Using request-aware logger here
|
|
96
96
|
if (logError) {
|
|
@@ -103,20 +103,17 @@ export class SentrySharedService {
|
|
|
103
103
|
return
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
|
111
111
|
|
|
112
112
|
// This is to avoid Sentry cutting err.message to 253 characters
|
|
113
113
|
// It will log additional "breadcrumb object" before the error
|
|
114
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)
|
|
115
115
|
this.sentry().addBreadcrumb({
|
|
116
|
-
message:
|
|
117
|
-
.filter(Boolean)
|
|
118
|
-
.map(a => inspectAny(a, INSPECT_OPT))
|
|
119
|
-
.join('\n'),
|
|
116
|
+
message: inspectAny(err, INSPECT_OPT),
|
|
120
117
|
})
|
|
121
118
|
|
|
122
119
|
return this.sentry().captureException(err)
|