@naturalcycles/backend-lib 5.0.2 → 5.1.0

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.
@@ -1,4 +1,4 @@
1
- import { CommonLogger } from '@naturalcycles/js-lib';
1
+ import { CommonLogger, Primitive, StringMap } from '@naturalcycles/js-lib';
2
2
  import type { Breadcrumb, NodeOptions, SeverityLevel } from '@sentry/node';
3
3
  import type * as SentryLib from '@sentry/node';
4
4
  import { BackendErrorRequestHandler, BackendRequestHandler } from '../index';
@@ -24,7 +24,17 @@ export declare class SentrySharedService {
24
24
  /**
25
25
  * For GDPR reasons we never send more information than just User ID.
26
26
  */
27
- setUserId(id: string): void;
27
+ setUserId(id: string | null): void;
28
+ /**
29
+ * Tag keys have a maximum length of 32 characters and can contain only
30
+ * letters (a-zA-Z), numbers (0-9), underscores (_), periods (.), colons (:), and dashes (-).
31
+ *
32
+ * Tag values have a maximum length of 200 characters and they
33
+ * cannot contain the newline (\n) character.
34
+ *
35
+ * https://docs.sentry.io/platforms/node/enriching-events/scopes/
36
+ */
37
+ setTags(tags: StringMap<Primitive>): void;
28
38
  /**
29
39
  * Does console.log(err)
30
40
  * Returns "eventId" or undefined (if error was not reported).
@@ -60,12 +60,26 @@ class SentrySharedService {
60
60
  * For GDPR reasons we never send more information than just User ID.
61
61
  */
62
62
  setUserId(id) {
63
- this.sentry().configureScope(scope => {
64
- scope.setUser({
65
- id,
66
- });
63
+ if (id === null) {
64
+ this.sentry().setUser(null);
65
+ return;
66
+ }
67
+ this.sentry().setUser({
68
+ id,
67
69
  });
68
70
  }
71
+ /**
72
+ * Tag keys have a maximum length of 32 characters and can contain only
73
+ * letters (a-zA-Z), numbers (0-9), underscores (_), periods (.), colons (:), and dashes (-).
74
+ *
75
+ * Tag values have a maximum length of 200 characters and they
76
+ * cannot contain the newline (\n) character.
77
+ *
78
+ * https://docs.sentry.io/platforms/node/enriching-events/scopes/
79
+ */
80
+ setTags(tags) {
81
+ this.sentry().setTags(tags);
82
+ }
69
83
  /**
70
84
  * Does console.log(err)
71
85
  * Returns "eventId" or undefined (if error was not reported).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
- "version": "5.0.2",
3
+ "version": "5.1.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "dev": "APP_ENV=dev nodemon",
@@ -4,6 +4,8 @@ import {
4
4
  _Memo,
5
5
  CommonLogger,
6
6
  CommonLogLevel,
7
+ Primitive,
8
+ StringMap,
7
9
  } from '@naturalcycles/js-lib'
8
10
  import { _inspect, InspectAnyOptions } from '@naturalcycles/nodejs-lib'
9
11
  // eslint-disable-next-line import/no-duplicates
@@ -77,14 +79,30 @@ export class SentrySharedService {
77
79
  /**
78
80
  * For GDPR reasons we never send more information than just User ID.
79
81
  */
80
- setUserId(id: string): void {
81
- this.sentry().configureScope(scope => {
82
- scope.setUser({
83
- id,
84
- })
82
+ setUserId(id: string | null): void {
83
+ if (id === null) {
84
+ this.sentry().setUser(null)
85
+ return
86
+ }
87
+
88
+ this.sentry().setUser({
89
+ id,
85
90
  })
86
91
  }
87
92
 
93
+ /**
94
+ * Tag keys have a maximum length of 32 characters and can contain only
95
+ * letters (a-zA-Z), numbers (0-9), underscores (_), periods (.), colons (:), and dashes (-).
96
+ *
97
+ * Tag values have a maximum length of 200 characters and they
98
+ * cannot contain the newline (\n) character.
99
+ *
100
+ * https://docs.sentry.io/platforms/node/enriching-events/scopes/
101
+ */
102
+ setTags(tags: StringMap<Primitive>): void {
103
+ this.sentry().setTags(tags)
104
+ }
105
+
88
106
  /**
89
107
  * Does console.log(err)
90
108
  * Returns "eventId" or undefined (if error was not reported).