@naturalcycles/backend-lib 4.18.2 → 4.18.3

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.
@@ -13,6 +13,9 @@ const sentrySeverityMap = {
13
13
  error: 'error',
14
14
  fatal: 'error',
15
15
  };
16
+ const INSPECT_OPT = {
17
+ colors: false,
18
+ };
16
19
  class SentrySharedService {
17
20
  constructor(sentryServiceCfg) {
18
21
  this.sentryServiceCfg = sentryServiceCfg;
@@ -89,10 +92,14 @@ class SentrySharedService {
89
92
  // It will log additional "breadcrumb object" before the error
90
93
  // It's a Breadcrumb, not a console.log, because console.log are NOT automatically attached as Breadcrumbs in cron-job environments (outside of Express)
91
94
  this.sentry().addBreadcrumb({
92
- message: (0, nodejs_lib_1.inspectAny)(err, {
93
- colors: false,
94
- }),
95
+ message: (0, nodejs_lib_1.inspectAny)(err, INSPECT_OPT),
95
96
  });
97
+ if (data) {
98
+ // Log the attached ErrorData (if any)
99
+ this.sentry().addBreadcrumb({
100
+ message: (0, nodejs_lib_1.inspectAny)(data, INSPECT_OPT),
101
+ });
102
+ }
96
103
  return this.sentry().captureException(err);
97
104
  }
98
105
  /**
@@ -117,11 +124,7 @@ class SentrySharedService {
117
124
  log: () => { },
118
125
  warn: () => { },
119
126
  error: (...args) => {
120
- const message = args
121
- .map(arg => (0, nodejs_lib_1.inspectAny)(arg, {
122
- colors: false,
123
- }))
124
- .join(' ');
127
+ const message = args.map(arg => (0, nodejs_lib_1.inspectAny)(arg, INSPECT_OPT)).join(' ');
125
128
  this.sentry().addBreadcrumb({
126
129
  message,
127
130
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
- "version": "4.18.2",
3
+ "version": "4.18.3",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "serve": "APP_ENV=dev nodemon",
@@ -6,7 +6,7 @@ import {
6
6
  CommonLogLevel,
7
7
  ErrorData,
8
8
  } from '@naturalcycles/js-lib'
9
- import { inspectAny } from '@naturalcycles/nodejs-lib'
9
+ import { inspectAny, InspectAnyOptions } from '@naturalcycles/nodejs-lib'
10
10
  import type { Breadcrumb, NodeOptions, SeverityLevel } from '@sentry/node'
11
11
  import type * as SentryLib from '@sentry/node'
12
12
  import { BackendErrorRequestHandler, BackendRequestHandler, getRequestLogger } from '../index'
@@ -22,6 +22,10 @@ const sentrySeverityMap: Record<SeverityLevel, CommonLogLevel> = {
22
22
  fatal: 'error',
23
23
  }
24
24
 
25
+ const INSPECT_OPT: InspectAnyOptions = {
26
+ colors: false,
27
+ }
28
+
25
29
  export class SentrySharedService {
26
30
  constructor(private sentryServiceCfg: SentrySharedServiceCfg) {}
27
31
 
@@ -109,11 +113,16 @@ export class SentrySharedService {
109
113
  // It will log additional "breadcrumb object" before the error
110
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)
111
115
  this.sentry().addBreadcrumb({
112
- message: inspectAny(err, {
113
- colors: false,
114
- }),
116
+ message: inspectAny(err, INSPECT_OPT),
115
117
  })
116
118
 
119
+ if (data) {
120
+ // Log the attached ErrorData (if any)
121
+ this.sentry().addBreadcrumb({
122
+ message: inspectAny(data, INSPECT_OPT),
123
+ })
124
+ }
125
+
117
126
  return this.sentry().captureException(err)
118
127
  }
119
128
 
@@ -141,13 +150,7 @@ export class SentrySharedService {
141
150
  log: () => {}, // noop
142
151
  warn: () => {}, // noop
143
152
  error: (...args) => {
144
- const message = args
145
- .map(arg =>
146
- inspectAny(arg, {
147
- colors: false,
148
- }),
149
- )
150
- .join(' ')
153
+ const message = args.map(arg => inspectAny(arg, INSPECT_OPT)).join(' ')
151
154
 
152
155
  this.sentry().addBreadcrumb({
153
156
  message,