@rxap/nest-sentry 9.0.3-dev.2 → 9.0.3-dev.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.
- package/CHANGELOG.md +11 -0
- package/package.json +1 -1
- package/src/lib/sentry.logger.d.ts +6 -4
- package/src/lib/sentry.logger.js +87 -11
- package/src/lib/sentry.logger.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [9.0.3-dev.3](https://gitlab.com/rxap/nest/compare/@rxap/nest-sentry@9.0.3-dev.2...@rxap/nest-sentry@9.0.3-dev.3) (2023-04-04)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **logger:** mirror the ConsoleLogger implementation ([4ce7f2a](https://gitlab.com/rxap/nest/commit/4ce7f2a144d1e1ab3f0b3e6f858c928cc0482587))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [9.0.3-dev.2](https://gitlab.com/rxap/nest/compare/@rxap/nest-sentry@9.0.3-dev.1...@rxap/nest-sentry@9.0.3-dev.2) (2023-04-04)
|
|
7
18
|
|
|
8
19
|
|
package/package.json
CHANGED
|
@@ -5,8 +5,10 @@ export declare class SentryLogger extends ConsoleLogger {
|
|
|
5
5
|
protected readonly options: ConsoleLoggerOptions;
|
|
6
6
|
private readonly sentryOptions;
|
|
7
7
|
constructor(options: ConsoleLoggerOptions, sentryOptions: SentryModuleOptions);
|
|
8
|
-
log(message: string,
|
|
9
|
-
error(message: string,
|
|
10
|
-
warn(message: string,
|
|
11
|
-
debug(message: string,
|
|
8
|
+
log(message: string, ...optionalParams: any[]): void;
|
|
9
|
+
error(message: string, ...optionalParams: any[]): void;
|
|
10
|
+
warn(message: string, ...optionalParams: any[]): void;
|
|
11
|
+
debug(message: string, ...optionalParams: any[]): void;
|
|
12
|
+
private _getContextAndMessagesToPrint;
|
|
13
|
+
private _getContextAndStackAndMessagesToPrint;
|
|
12
14
|
}
|
package/src/lib/sentry.logger.js
CHANGED
|
@@ -5,14 +5,25 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const Sentry = require("@sentry/node");
|
|
7
7
|
const tokens_1 = require("./tokens");
|
|
8
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
8
9
|
let SentryLogger = class SentryLogger extends common_1.ConsoleLogger {
|
|
9
10
|
constructor(options, sentryOptions) {
|
|
10
11
|
super();
|
|
11
12
|
this.options = options;
|
|
12
13
|
this.sentryOptions = sentryOptions;
|
|
13
14
|
}
|
|
14
|
-
log(message,
|
|
15
|
-
|
|
15
|
+
log(message, ...optionalParams) {
|
|
16
|
+
let asBreadcrumb = false;
|
|
17
|
+
if (optionalParams.length) {
|
|
18
|
+
if (typeof optionalParams[optionalParams.length - 1] === 'boolean') {
|
|
19
|
+
asBreadcrumb = optionalParams.pop();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const { context } = this._getContextAndMessagesToPrint([
|
|
23
|
+
message,
|
|
24
|
+
...optionalParams,
|
|
25
|
+
]);
|
|
26
|
+
super.log(message, ...optionalParams);
|
|
16
27
|
if (!this.sentryOptions.dsn) {
|
|
17
28
|
return;
|
|
18
29
|
}
|
|
@@ -30,14 +41,19 @@ let SentryLogger = class SentryLogger extends common_1.ConsoleLogger {
|
|
|
30
41
|
}) :
|
|
31
42
|
Sentry.captureMessage(message, {
|
|
32
43
|
level: 'log',
|
|
44
|
+
extra: { context },
|
|
33
45
|
});
|
|
34
46
|
}
|
|
35
47
|
catch (err) {
|
|
36
48
|
console.error('Failed to capture message with sentry: ' + err.message);
|
|
37
49
|
}
|
|
38
50
|
}
|
|
39
|
-
error(message,
|
|
40
|
-
|
|
51
|
+
error(message, ...optionalParams) {
|
|
52
|
+
const { context, stack } = this._getContextAndStackAndMessagesToPrint([
|
|
53
|
+
message,
|
|
54
|
+
...optionalParams,
|
|
55
|
+
]);
|
|
56
|
+
super.error(message, ...optionalParams);
|
|
41
57
|
if (!this.sentryOptions.dsn) {
|
|
42
58
|
return;
|
|
43
59
|
}
|
|
@@ -45,14 +61,27 @@ let SentryLogger = class SentryLogger extends common_1.ConsoleLogger {
|
|
|
45
61
|
return;
|
|
46
62
|
}
|
|
47
63
|
try {
|
|
48
|
-
Sentry.captureMessage(message, {
|
|
64
|
+
Sentry.captureMessage(message, {
|
|
65
|
+
level: 'error',
|
|
66
|
+
extra: { context, stack },
|
|
67
|
+
});
|
|
49
68
|
}
|
|
50
69
|
catch (err) {
|
|
51
70
|
console.error('Failed to capture message with sentry: ' + err.message);
|
|
52
71
|
}
|
|
53
72
|
}
|
|
54
|
-
warn(message,
|
|
55
|
-
|
|
73
|
+
warn(message, ...optionalParams) {
|
|
74
|
+
let asBreadcrumb = false;
|
|
75
|
+
if (optionalParams.length) {
|
|
76
|
+
if (typeof optionalParams[optionalParams.length - 1] === 'boolean') {
|
|
77
|
+
asBreadcrumb = optionalParams.pop();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const { context } = this._getContextAndMessagesToPrint([
|
|
81
|
+
message,
|
|
82
|
+
...optionalParams,
|
|
83
|
+
]);
|
|
84
|
+
super.warn(message, ...optionalParams);
|
|
56
85
|
if (!this.sentryOptions.dsn) {
|
|
57
86
|
return;
|
|
58
87
|
}
|
|
@@ -68,14 +97,27 @@ let SentryLogger = class SentryLogger extends common_1.ConsoleLogger {
|
|
|
68
97
|
context
|
|
69
98
|
}
|
|
70
99
|
}) :
|
|
71
|
-
Sentry.captureMessage(message, {
|
|
100
|
+
Sentry.captureMessage(message, {
|
|
101
|
+
level: 'warning',
|
|
102
|
+
extra: { context },
|
|
103
|
+
});
|
|
72
104
|
}
|
|
73
105
|
catch (err) {
|
|
74
106
|
console.error('Failed to capture message with sentry: ' + err.message);
|
|
75
107
|
}
|
|
76
108
|
}
|
|
77
|
-
debug(message,
|
|
78
|
-
|
|
109
|
+
debug(message, ...optionalParams) {
|
|
110
|
+
let asBreadcrumb = false;
|
|
111
|
+
if (optionalParams.length) {
|
|
112
|
+
if (typeof optionalParams[optionalParams.length - 1] === 'boolean') {
|
|
113
|
+
asBreadcrumb = optionalParams.pop();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const { context } = this._getContextAndMessagesToPrint([
|
|
117
|
+
message,
|
|
118
|
+
...optionalParams,
|
|
119
|
+
]);
|
|
120
|
+
super.debug(message, ...optionalParams);
|
|
79
121
|
if (!this.sentryOptions.dsn) {
|
|
80
122
|
return;
|
|
81
123
|
}
|
|
@@ -91,12 +133,46 @@ let SentryLogger = class SentryLogger extends common_1.ConsoleLogger {
|
|
|
91
133
|
context
|
|
92
134
|
}
|
|
93
135
|
}) :
|
|
94
|
-
Sentry.captureMessage(message, {
|
|
136
|
+
Sentry.captureMessage(message, {
|
|
137
|
+
level: 'debug',
|
|
138
|
+
extra: { context },
|
|
139
|
+
});
|
|
95
140
|
}
|
|
96
141
|
catch (err) {
|
|
97
142
|
console.error('Failed to capture message with sentry: ' + err.message);
|
|
98
143
|
}
|
|
99
144
|
}
|
|
145
|
+
_getContextAndMessagesToPrint(args) {
|
|
146
|
+
if ((args === null || args === void 0 ? void 0 : args.length) <= 1) {
|
|
147
|
+
return { messages: args, context: this.context };
|
|
148
|
+
}
|
|
149
|
+
const lastElement = args[args.length - 1];
|
|
150
|
+
const isContext = (0, shared_utils_1.isString)(lastElement);
|
|
151
|
+
if (!isContext) {
|
|
152
|
+
return { messages: args, context: this.context };
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
context: lastElement,
|
|
156
|
+
messages: args.slice(0, args.length - 1),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
_getContextAndStackAndMessagesToPrint(args) {
|
|
160
|
+
const { messages, context } = this._getContextAndMessagesToPrint(args);
|
|
161
|
+
if ((messages === null || messages === void 0 ? void 0 : messages.length) <= 1) {
|
|
162
|
+
return { messages, context };
|
|
163
|
+
}
|
|
164
|
+
const lastElement = messages[messages.length - 1];
|
|
165
|
+
const isStack = (0, shared_utils_1.isString)(lastElement);
|
|
166
|
+
// https://github.com/nestjs/nest/issues/11074#issuecomment-1421680060
|
|
167
|
+
if (!isStack && !(0, shared_utils_1.isUndefined)(lastElement)) {
|
|
168
|
+
return { messages, context };
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
stack: lastElement,
|
|
172
|
+
messages: messages.slice(0, messages.length - 1),
|
|
173
|
+
context,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
100
176
|
};
|
|
101
177
|
SentryLogger = tslib_1.__decorate([
|
|
102
178
|
(0, common_1.Injectable)(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry.logger.js","sourceRoot":"","sources":["../../../../../libs/sentry/src/lib/sentry.logger.ts"],"names":[],"mappings":";;;;AAAA,2CAAmE;AACnE,uCAAuC;AAEvC,qCAAyE;
|
|
1
|
+
{"version":3,"file":"sentry.logger.js","sourceRoot":"","sources":["../../../../../libs/sentry/src/lib/sentry.logger.ts"],"names":[],"mappings":";;;;AAAA,2CAAmE;AACnE,uCAAuC;AAEvC,qCAAyE;AAEzE,oEAA0E;AAGnE,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,sBAAa;IAE7C,YAE8B,OAA6B,EAExC,aAAkC;QAEnD,KAAK,EAAE,CAAC;QAJoB,YAAO,GAAP,OAAO,CAAsB;QAExC,kBAAa,GAAb,aAAa,CAAqB;IAGrD,CAAC;IAEQ,GAAG,CAAC,OAAe,EAAE,GAAG,cAAqB;QACpD,IAAI,YAAY,GAAG,KAAK,CAAC;QACzB,IAAI,cAAc,CAAC,MAAM,EAAE;YACzB,IAAI,OAAO,cAAc,CAAC,cAAc,CAAC,MAAM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