@naturalcycles/backend-lib 4.18.1 → 4.18.2
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.
|
@@ -26,10 +26,10 @@ export declare class SentrySharedService {
|
|
|
26
26
|
*/
|
|
27
27
|
setUserId(id: string): void;
|
|
28
28
|
/**
|
|
29
|
-
* Does console.
|
|
29
|
+
* Does console.log(err)
|
|
30
30
|
* Returns "eventId" or undefined (if error was not reported).
|
|
31
31
|
*/
|
|
32
|
-
captureException(
|
|
32
|
+
captureException(err_: any, logError?: boolean): string | undefined;
|
|
33
33
|
/**
|
|
34
34
|
* Returns "eventId"
|
|
35
35
|
*/
|
|
@@ -63,20 +63,23 @@ class SentrySharedService {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
* Does console.
|
|
66
|
+
* Does console.log(err)
|
|
67
67
|
* Returns "eventId" or undefined (if error was not reported).
|
|
68
68
|
*/
|
|
69
|
-
captureException(
|
|
70
|
-
//
|
|
69
|
+
captureException(err_, logError = true) {
|
|
70
|
+
// normalize the error
|
|
71
|
+
const err = (0, js_lib_1._anyToError)(err_);
|
|
72
|
+
const data = err instanceof js_lib_1.AppError ? err.data : undefined;
|
|
71
73
|
// Using request-aware logger here
|
|
72
74
|
if (logError) {
|
|
73
|
-
|
|
75
|
+
// Log both the error and attached ErrorData (if any)
|
|
76
|
+
(0, index_1.getRequestLogger)().error('captureException:', ...[err_, data].filter(Boolean));
|
|
74
77
|
}
|
|
75
|
-
if (
|
|
78
|
+
if (data?.report === false) {
|
|
76
79
|
// Skip reporting the error
|
|
77
80
|
return;
|
|
78
81
|
}
|
|
79
|
-
if (
|
|
82
|
+
if (data?.reportRate) {
|
|
80
83
|
const reportRate = err.data.reportRate;
|
|
81
84
|
// E.g rate of 0.1 means 10% of errors are reported
|
|
82
85
|
if (Math.random() > reportRate)
|
|
@@ -89,9 +92,8 @@ class SentrySharedService {
|
|
|
89
92
|
message: (0, nodejs_lib_1.inspectAny)(err, {
|
|
90
93
|
colors: false,
|
|
91
94
|
}),
|
|
92
|
-
// data: (err as AppError).data, // included in message
|
|
93
95
|
});
|
|
94
|
-
return this.sentry().captureException(
|
|
96
|
+
return this.sentry().captureException(err);
|
|
95
97
|
}
|
|
96
98
|
/**
|
|
97
99
|
* Returns "eventId"
|
package/package.json
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
_anyToError,
|
|
3
|
+
_Memo,
|
|
4
|
+
AppError,
|
|
5
|
+
CommonLogger,
|
|
6
|
+
CommonLogLevel,
|
|
7
|
+
ErrorData,
|
|
8
|
+
} from '@naturalcycles/js-lib'
|
|
2
9
|
import { inspectAny } from '@naturalcycles/nodejs-lib'
|
|
3
10
|
import type { Breadcrumb, NodeOptions, SeverityLevel } from '@sentry/node'
|
|
4
11
|
import type * as SentryLib from '@sentry/node'
|
|
@@ -73,22 +80,26 @@ export class SentrySharedService {
|
|
|
73
80
|
}
|
|
74
81
|
|
|
75
82
|
/**
|
|
76
|
-
* Does console.
|
|
83
|
+
* Does console.log(err)
|
|
77
84
|
* Returns "eventId" or undefined (if error was not reported).
|
|
78
85
|
*/
|
|
79
|
-
captureException(
|
|
80
|
-
//
|
|
86
|
+
captureException(err_: any, logError = true): string | undefined {
|
|
87
|
+
// normalize the error
|
|
88
|
+
const err = _anyToError(err_)
|
|
89
|
+
const data = err instanceof AppError ? (err.data as ErrorData) : undefined
|
|
90
|
+
|
|
81
91
|
// Using request-aware logger here
|
|
82
92
|
if (logError) {
|
|
83
|
-
|
|
93
|
+
// Log both the error and attached ErrorData (if any)
|
|
94
|
+
getRequestLogger().error('captureException:', ...[err_, data].filter(Boolean))
|
|
84
95
|
}
|
|
85
96
|
|
|
86
|
-
if (
|
|
97
|
+
if (data?.report === false) {
|
|
87
98
|
// Skip reporting the error
|
|
88
99
|
return
|
|
89
100
|
}
|
|
90
101
|
|
|
91
|
-
if (
|
|
102
|
+
if (data?.reportRate) {
|
|
92
103
|
const reportRate = (err as AppError).data.reportRate!
|
|
93
104
|
// E.g rate of 0.1 means 10% of errors are reported
|
|
94
105
|
if (Math.random() > reportRate) return
|
|
@@ -101,10 +112,9 @@ export class SentrySharedService {
|
|
|
101
112
|
message: inspectAny(err, {
|
|
102
113
|
colors: false,
|
|
103
114
|
}),
|
|
104
|
-
// data: (err as AppError).data, // included in message
|
|
105
115
|
})
|
|
106
116
|
|
|
107
|
-
return this.sentry().captureException(
|
|
117
|
+
return this.sentry().captureException(err)
|
|
108
118
|
}
|
|
109
119
|
|
|
110
120
|
/**
|