@rxap/nest-sentry 11.0.0-dev.1 → 11.0.0-dev.10
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 +48 -0
- package/package.json +22 -22
- package/src/index.d.ts +2 -6
- package/src/index.js +2 -6
- package/src/lib/determine-sentry-release.js +4 -0
- package/src/lib/get-sentry-log-levels.d.ts +2 -0
- package/src/lib/get-sentry-log-levels.js +46 -0
- package/src/lib/sentry-app-config.d.ts +4 -8
- package/src/lib/sentry-app-config.js +3 -16
- package/src/lib/sentry-init-hook.d.ts +2 -1
- package/src/lib/sentry-init-hook.js +12 -8
- package/src/lib/sentry-logger.module.d.ts +14 -4
- package/src/lib/sentry-logger.module.js +42 -6
- package/src/lib/sentry-module-options.factory.d.ts +7 -0
- package/src/lib/sentry-module-options.factory.js +35 -0
- package/src/lib/sentry.interfaces.d.ts +5 -39
- package/src/lib/sentry.logger.d.ts +3 -0
- package/src/lib/sentry.logger.js +63 -20
- package/src/lib/tokens.d.ts +0 -4
- package/src/lib/tokens.js +1 -5
- package/src/lib/use-sentry-logger-factory.d.ts +1 -1
- package/src/lib/use-sentry-logger-factory.js +2 -2
- package/src/lib/sentry-options.factory.d.ts +0 -4
- package/src/lib/sentry-options.factory.js +0 -23
- package/src/lib/sentry.interceptor.d.ts +0 -13
- package/src/lib/sentry.interceptor.js +0 -71
- package/src/lib/sentry.module.d.ts +0 -22
- package/src/lib/sentry.module.js +0 -93
- package/src/lib/sentry.service.d.ts +0 -10
- package/src/lib/sentry.service.js +0 -66
- package/src/lib/setup-sentry-error-handler.d.ts +0 -2
- package/src/lib/setup-sentry-error-handler.js +0 -11
- package/src/lib/setup-sentry-logger.d.ts +0 -6
- package/src/lib/setup-sentry-logger.js +0 -18
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,54 @@
|
|
|
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
|
+
# [11.0.0-dev.10](https://gitlab.com/rxap/packages/compare/@rxap/nest-sentry@11.0.0-dev.9...@rxap/nest-sentry@11.0.0-dev.10) (2025-09-15)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **sentry:** replace config checks with `sentryOptions.enabled` ([fe790ed](https://gitlab.com/rxap/packages/commit/fe790ed6c725529ef654a18a3f5810990fec4584))
|
|
11
|
+
|
|
12
|
+
# [11.0.0-dev.9](https://gitlab.com/rxap/packages/compare/@rxap/nest-sentry@11.0.0-dev.8...@rxap/nest-sentry@11.0.0-dev.9) (2025-09-08)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @rxap/nest-sentry
|
|
15
|
+
|
|
16
|
+
# [11.0.0-dev.8](https://gitlab.com/rxap/packages/compare/@rxap/nest-sentry@11.0.0-dev.7...@rxap/nest-sentry@11.0.0-dev.8) (2025-09-08)
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
- **nest-sentry:** set default value for sentryInitHook options ([db26f24](https://gitlab.com/rxap/packages/commit/db26f24ca7e5d52b3f8ef37aa2d224ca26d3d754))
|
|
21
|
+
|
|
22
|
+
# [11.0.0-dev.7](https://gitlab.com/rxap/packages/compare/@rxap/nest-sentry@11.0.0-dev.6...@rxap/nest-sentry@11.0.0-dev.7) (2025-09-08)
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
- **nest-sentry:** upgrade to sentry 10 ([2302e70](https://gitlab.com/rxap/packages/commit/2302e70ee4ac4e13b925d812de762d3b6c5a8968))
|
|
27
|
+
|
|
28
|
+
# [11.0.0-dev.6](https://gitlab.com/rxap/packages/compare/@rxap/nest-sentry@11.0.0-dev.5...@rxap/nest-sentry@11.0.0-dev.6) (2025-09-01)
|
|
29
|
+
|
|
30
|
+
**Note:** Version bump only for package @rxap/nest-sentry
|
|
31
|
+
|
|
32
|
+
# [11.0.0-dev.5](https://gitlab.com/rxap/packages/compare/@rxap/nest-sentry@11.0.0-dev.4...@rxap/nest-sentry@11.0.0-dev.5) (2025-07-02)
|
|
33
|
+
|
|
34
|
+
### Bug Fixes
|
|
35
|
+
|
|
36
|
+
- disable warn monitoring by default ([e6edec5](https://gitlab.com/rxap/packages/commit/e6edec5b16a83179f3e2892e74be5f1c99cdd7a0))
|
|
37
|
+
|
|
38
|
+
# [11.0.0-dev.4](https://gitlab.com/rxap/packages/compare/@rxap/nest-sentry@11.0.0-dev.3...@rxap/nest-sentry@11.0.0-dev.4) (2025-05-19)
|
|
39
|
+
|
|
40
|
+
### Bug Fixes
|
|
41
|
+
|
|
42
|
+
- update package groups ([e533203](https://gitlab.com/rxap/packages/commit/e5332030cd4d1996d6e9b0dd99bfb66334571400))
|
|
43
|
+
|
|
44
|
+
# [11.0.0-dev.3](https://gitlab.com/rxap/packages/compare/@rxap/nest-sentry@11.0.0-dev.2...@rxap/nest-sentry@11.0.0-dev.3) (2025-05-19)
|
|
45
|
+
|
|
46
|
+
**Note:** Version bump only for package @rxap/nest-sentry
|
|
47
|
+
|
|
48
|
+
# [11.0.0-dev.2](https://gitlab.com/rxap/packages/compare/@rxap/nest-sentry@11.0.0-dev.1...@rxap/nest-sentry@11.0.0-dev.2) (2025-05-19)
|
|
49
|
+
|
|
50
|
+
### Bug Fixes
|
|
51
|
+
|
|
52
|
+
- ensure sentry release is a valid semvar ([70706d2](https://gitlab.com/rxap/packages/commit/70706d2e1d98226de51ce69307b4666d39c34227))
|
|
53
|
+
|
|
6
54
|
# [11.0.0-dev.1](https://gitlab.com/rxap/packages/compare/@rxap/nest-sentry@10.6.0...@rxap/nest-sentry@11.0.0-dev.1) (2025-05-16)
|
|
7
55
|
|
|
8
56
|
**Note:** Version bump only for package @rxap/nest-sentry
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "11.0.0-dev.
|
|
2
|
+
"version": "11.0.0-dev.10",
|
|
3
3
|
"name": "@rxap/nest-sentry",
|
|
4
4
|
"description": "This package provides a Sentry integration for NestJS applications. It includes a logger, interceptor, and module to simplify error tracking and performance monitoring with Sentry. It offers configurable options for setting up Sentry in your NestJS application.\n",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@nx/devkit": "20.5.0",
|
|
8
|
-
"@rxap/ts-morph": "^1.
|
|
9
|
-
"@rxap/workspace-utilities": "^19.8.0",
|
|
8
|
+
"@rxap/ts-morph": "^1.6.0-dev.0",
|
|
9
|
+
"@rxap/workspace-utilities": "^19.8.1-dev.0",
|
|
10
10
|
"tslib": "2.6.2"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
13
|
"@nestjs/common": "^11.1.1",
|
|
14
14
|
"@nestjs/config": "^4.0.2",
|
|
15
15
|
"@nestjs/core": "^11.1.1",
|
|
16
|
-
"@rxap/nest-logger": "^11.0.0-dev.
|
|
17
|
-
"@rxap/nest-utilities": "^11.0.0-dev.
|
|
16
|
+
"@rxap/nest-logger": "^11.0.0-dev.3",
|
|
17
|
+
"@rxap/nest-utilities": "^11.0.0-dev.7",
|
|
18
18
|
"@sentry/core": "^8.55.0",
|
|
19
19
|
"@sentry/nestjs": "^8.55.0",
|
|
20
20
|
"@sentry/node": "^8.55.0",
|
|
@@ -49,67 +49,67 @@
|
|
|
49
49
|
"packageGroup": [
|
|
50
50
|
{
|
|
51
51
|
"package": "@nestjs/cache-manager",
|
|
52
|
-
"version": "
|
|
52
|
+
"version": "3.0.1"
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
"package": "@nestjs/common",
|
|
56
|
-
"version": "
|
|
56
|
+
"version": "11.1.1"
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
"package": "@nestjs/config",
|
|
60
|
-
"version": "
|
|
60
|
+
"version": "4.0.2"
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
63
|
"package": "@nestjs/core",
|
|
64
|
-
"version": "
|
|
64
|
+
"version": "11.1.1"
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
"package": "@nestjs/microservices",
|
|
68
|
-
"version": "
|
|
68
|
+
"version": "11.1.1"
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
71
|
"package": "@nestjs/platform-express",
|
|
72
|
-
"version": "
|
|
72
|
+
"version": "11.1.1"
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
75
|
"package": "@nestjs/throttler",
|
|
76
|
-
"version": "
|
|
76
|
+
"version": "6.4.0"
|
|
77
77
|
},
|
|
78
78
|
{
|
|
79
79
|
"package": "@nestjs/websockets",
|
|
80
|
-
"version": "
|
|
80
|
+
"version": "11.0.0"
|
|
81
81
|
},
|
|
82
82
|
{
|
|
83
83
|
"package": "@rxap/nest-logger",
|
|
84
|
-
"version": "
|
|
84
|
+
"version": "11.0.0-dev.3"
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
87
|
"package": "@rxap/nest-utilities",
|
|
88
|
-
"version": "
|
|
88
|
+
"version": "11.0.0-dev.7"
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
91
|
"package": "@rxap/utilities",
|
|
92
|
-
"version": "16.4.
|
|
92
|
+
"version": "16.4.5-dev.0"
|
|
93
93
|
},
|
|
94
94
|
{
|
|
95
95
|
"package": "@sentry/core",
|
|
96
|
-
"version": "
|
|
96
|
+
"version": "10.10.0"
|
|
97
97
|
},
|
|
98
98
|
{
|
|
99
99
|
"package": "@sentry/nestjs",
|
|
100
|
-
"version": "
|
|
100
|
+
"version": "10.10.0"
|
|
101
101
|
},
|
|
102
102
|
{
|
|
103
103
|
"package": "@sentry/node",
|
|
104
|
-
"version": "
|
|
104
|
+
"version": "10.10.0"
|
|
105
105
|
},
|
|
106
106
|
{
|
|
107
107
|
"package": "@sentry/profiling-node",
|
|
108
|
-
"version": "
|
|
108
|
+
"version": "10.10.0"
|
|
109
109
|
},
|
|
110
110
|
{
|
|
111
111
|
"package": "@sentry/types",
|
|
112
|
-
"version": "
|
|
112
|
+
"version": "10.10.0"
|
|
113
113
|
},
|
|
114
114
|
{
|
|
115
115
|
"package": "@sentry/utils",
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
},
|
|
129
129
|
"schematics": "./generators.json",
|
|
130
130
|
"type": "commonjs",
|
|
131
|
-
"gitHead": "
|
|
131
|
+
"gitHead": "c59b8be86a6b1c9eba00c73f6d96b548904e89b4",
|
|
132
132
|
"types": "./src/index.d.ts",
|
|
133
133
|
"main": "./src/index.js"
|
|
134
134
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
export * from './lib/determine-sentry-environment';
|
|
2
2
|
export * from './lib/determine-sentry-release';
|
|
3
|
+
export * from './lib/get-sentry-log-levels';
|
|
3
4
|
export * from './lib/sentry-app-config';
|
|
4
5
|
export * from './lib/sentry-init-hook';
|
|
5
6
|
export * from './lib/sentry-logger.module';
|
|
6
|
-
export * from './lib/sentry-options.factory';
|
|
7
|
-
export * from './lib/sentry.interceptor';
|
|
7
|
+
export * from './lib/sentry-module-options.factory';
|
|
8
8
|
export * from './lib/sentry.interfaces';
|
|
9
9
|
export * from './lib/sentry.logger';
|
|
10
|
-
export * from './lib/sentry.module';
|
|
11
|
-
export * from './lib/sentry.service';
|
|
12
|
-
export * from './lib/setup-sentry-error-handler';
|
|
13
|
-
export * from './lib/setup-sentry-logger';
|
|
14
10
|
export * from './lib/tokens';
|
|
15
11
|
export * from './lib/use-sentry-logger-factory';
|
package/src/index.js
CHANGED
|
@@ -4,17 +4,13 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
// region
|
|
5
5
|
tslib_1.__exportStar(require("./lib/determine-sentry-environment"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./lib/determine-sentry-release"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/get-sentry-log-levels"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./lib/sentry-app-config"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./lib/sentry-init-hook"), exports);
|
|
9
10
|
tslib_1.__exportStar(require("./lib/sentry-logger.module"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./lib/sentry-options.factory"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./lib/sentry.interceptor"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./lib/sentry-module-options.factory"), exports);
|
|
12
12
|
tslib_1.__exportStar(require("./lib/sentry.interfaces"), exports);
|
|
13
13
|
tslib_1.__exportStar(require("./lib/sentry.logger"), exports);
|
|
14
|
-
tslib_1.__exportStar(require("./lib/sentry.module"), exports);
|
|
15
|
-
tslib_1.__exportStar(require("./lib/sentry.service"), exports);
|
|
16
|
-
tslib_1.__exportStar(require("./lib/setup-sentry-error-handler"), exports);
|
|
17
|
-
tslib_1.__exportStar(require("./lib/setup-sentry-logger"), exports);
|
|
18
14
|
tslib_1.__exportStar(require("./lib/tokens"), exports);
|
|
19
15
|
tslib_1.__exportStar(require("./lib/use-sentry-logger-factory"), exports);
|
|
20
16
|
// endregion
|
|
@@ -17,6 +17,10 @@ function DetermineSentryRelease(environment) {
|
|
|
17
17
|
case 'testing':
|
|
18
18
|
case 'staging':
|
|
19
19
|
case 'production':
|
|
20
|
+
if (environment.tag?.match(/^v\d+\.\d+\.\d+/)) {
|
|
21
|
+
// if the tag is a semvar remove the v prefix as sentry does not expect a v as prefix
|
|
22
|
+
return environment.tag.replace(/^v/, '');
|
|
23
|
+
}
|
|
20
24
|
return environment.tag ?? undefined;
|
|
21
25
|
default:
|
|
22
26
|
return undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetSentryLogLevels = GetSentryLogLevels;
|
|
4
|
+
function GetSentryLogLevels(sentryLogLevel = process.env['SENTRY_LOG_LEVEL']) {
|
|
5
|
+
const logLevels = [];
|
|
6
|
+
switch (sentryLogLevel?.toLowerCase()) {
|
|
7
|
+
case 'verbose':
|
|
8
|
+
case 'trace':
|
|
9
|
+
logLevels.push('trace');
|
|
10
|
+
logLevels.push('debug');
|
|
11
|
+
logLevels.push('info');
|
|
12
|
+
logLevels.push('warn');
|
|
13
|
+
logLevels.push('error');
|
|
14
|
+
logLevels.push('fatal');
|
|
15
|
+
break;
|
|
16
|
+
case 'debug':
|
|
17
|
+
logLevels.push('debug');
|
|
18
|
+
logLevels.push('info');
|
|
19
|
+
logLevels.push('warn');
|
|
20
|
+
logLevels.push('error');
|
|
21
|
+
logLevels.push('fatal');
|
|
22
|
+
break;
|
|
23
|
+
case 'log':
|
|
24
|
+
case 'info':
|
|
25
|
+
logLevels.push('info');
|
|
26
|
+
logLevels.push('warn');
|
|
27
|
+
logLevels.push('error');
|
|
28
|
+
logLevels.push('fatal');
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
case 'warn':
|
|
32
|
+
logLevels.push('warn');
|
|
33
|
+
logLevels.push('error');
|
|
34
|
+
logLevels.push('fatal');
|
|
35
|
+
break;
|
|
36
|
+
case 'error':
|
|
37
|
+
logLevels.push('error');
|
|
38
|
+
logLevels.push('fatal');
|
|
39
|
+
break;
|
|
40
|
+
case 'fatal':
|
|
41
|
+
logLevels.push('fatal');
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
console.debug('SentryLogLevels:', logLevels.join(', '));
|
|
45
|
+
return logLevels;
|
|
46
|
+
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { Environment } from '@rxap/nest-utilities';
|
|
2
|
+
import { LogSeverityLevel } from '@sentry/core';
|
|
2
3
|
import type { SchemaMap } from 'joi';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
serverName: string;
|
|
6
|
-
release: string;
|
|
7
|
-
environment: string;
|
|
4
|
+
export declare function sentryValidationSchema(environment: Environment, { logLevel, enabled, }?: Partial<{
|
|
5
|
+
logLevel: LogSeverityLevel;
|
|
8
6
|
enabled: boolean;
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
export declare function sentryValidationSchema(environment: Environment, { debug, serverName, release, environment: environmentName, enabled, dsn, }?: Partial<SentryConfig>): SchemaMap;
|
|
7
|
+
}>): SchemaMap;
|
|
@@ -2,22 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sentryValidationSchema = sentryValidationSchema;
|
|
4
4
|
const Joi = require("joi");
|
|
5
|
-
function sentryValidationSchema(environment, {
|
|
5
|
+
function sentryValidationSchema(environment, { logLevel = 'warn', enabled = environment.sentry?.enabled ?? false, } = {}) {
|
|
6
6
|
const schema = {};
|
|
7
|
-
schema['
|
|
8
|
-
schema['
|
|
9
|
-
schema['SENTRY_ENABLED'] = Joi.string().default(enabled);
|
|
10
|
-
schema['SENTRY_RELEASE'] = Joi.string();
|
|
11
|
-
if (release) {
|
|
12
|
-
schema['SENTRY_RELEASE'] = schema['SENTRY_RELEASE'].default(release);
|
|
13
|
-
}
|
|
14
|
-
schema['SENTRY_ENVIRONMENT'] = Joi.string();
|
|
15
|
-
if (environmentName) {
|
|
16
|
-
schema['SENTRY_ENVIRONMENT'] = schema['SENTRY_ENVIRONMENT'].default(environmentName);
|
|
17
|
-
}
|
|
18
|
-
schema['SENTRY_DSN'] = Joi.string();
|
|
19
|
-
if (dsn) {
|
|
20
|
-
schema['SENTRY_DSN'] = schema['SENTRY_DSN'].default(dsn);
|
|
21
|
-
}
|
|
7
|
+
schema['SENTRY_LOG_LEVEL'] = Joi.string().allow('trace', 'debug', 'info', 'warn', 'error', 'fatal').default(logLevel);
|
|
8
|
+
schema['SENTRY_ENABLED'] = Joi.boolean().default(enabled);
|
|
22
9
|
return schema;
|
|
23
10
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { Environment } from '@rxap/nest-utilities';
|
|
2
|
-
|
|
2
|
+
import type { NodeOptions } from '@sentry/node/build/types/types';
|
|
3
|
+
export declare function sentryInitHook(options?: Partial<NodeOptions>): (_: any, environment: Environment) => void;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sentryInitHook = sentryInitHook;
|
|
4
4
|
const Sentry = require("@sentry/nestjs");
|
|
5
|
+
const profiling_node_1 = require("@sentry/profiling-node");
|
|
5
6
|
const determine_sentry_environment_1 = require("./determine-sentry-environment");
|
|
6
7
|
const determine_sentry_release_1 = require("./determine-sentry-release");
|
|
7
|
-
|
|
8
|
-
function sentryInitHook() {
|
|
8
|
+
function sentryInitHook(options = {}) {
|
|
9
9
|
return (_, environment) => {
|
|
10
10
|
const dsn = process.env['SENTRY_DSN'] ?? environment.sentry?.dsn;
|
|
11
11
|
if (!dsn) {
|
|
@@ -13,19 +13,23 @@ function sentryInitHook() {
|
|
|
13
13
|
}
|
|
14
14
|
Sentry.init({
|
|
15
15
|
dsn,
|
|
16
|
-
enabled: process.env['SENTRY_ENABLED'] === 'true' ||
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
enabled: process.env['SENTRY_ENABLED'] === 'true' ||
|
|
17
|
+
(environment.sentry?.enabled ?? false),
|
|
18
|
+
debug: process.env['SENTRY_DEBUG'] === 'true' ||
|
|
19
|
+
(environment.sentry?.debug ?? false),
|
|
20
|
+
environment: process.env['ENVIRONMENT'] ?? (0, determine_sentry_environment_1.DetermineSentryEnvironment)(environment),
|
|
19
21
|
release: (0, determine_sentry_release_1.DetermineSentryRelease)(environment),
|
|
20
22
|
integrations: [
|
|
21
23
|
Sentry.captureConsoleIntegration({
|
|
22
|
-
levels: ['error'
|
|
24
|
+
levels: ['error'],
|
|
23
25
|
}),
|
|
24
26
|
(0, profiling_node_1.nodeProfilingIntegration)(),
|
|
25
|
-
Sentry.anrIntegration({ captureStackTrace: true }),
|
|
26
27
|
],
|
|
27
28
|
tracesSampleRate: 1.0,
|
|
28
|
-
|
|
29
|
+
profileSessionSampleRate: 1.0,
|
|
30
|
+
profileLifecycle: 'trace',
|
|
31
|
+
enableLogs: true,
|
|
32
|
+
...options,
|
|
29
33
|
});
|
|
30
34
|
};
|
|
31
35
|
}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare
|
|
1
|
+
import { ConsoleLoggerOptions, DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { PrintMessagesFunction } from '@rxap/nest-logger';
|
|
3
|
+
import { SentryModuleOptions } from './sentry.interfaces';
|
|
4
|
+
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<SentryModuleOptions, "register", "create", {
|
|
5
|
+
isGlobal: boolean;
|
|
6
|
+
}>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: SentryModuleOptions & Partial<{
|
|
7
|
+
isGlobal: boolean;
|
|
8
|
+
}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<SentryModuleOptions, "create"> & Partial<{
|
|
9
|
+
isGlobal: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
export declare class SentryLoggerModule extends ConfigurableModuleClass {
|
|
12
|
+
static register(options: typeof OPTIONS_TYPE, consoleLoggerOptions?: ConsoleLoggerOptions | null, printMessagesFunction?: PrintMessagesFunction | null): DynamicModule;
|
|
13
|
+
static registerAsync(options: typeof ASYNC_OPTIONS_TYPE, consoleLoggerOptions?: ConsoleLoggerOptions | null, printMessagesFunction?: PrintMessagesFunction | null): DynamicModule;
|
|
14
|
+
private static updateProviders;
|
|
5
15
|
}
|
|
@@ -1,15 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SentryLoggerModule = void 0;
|
|
4
|
+
exports.SentryLoggerModule = exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
5
6
|
const common_1 = require("@nestjs/common");
|
|
6
7
|
const config_1 = require("@nestjs/config");
|
|
7
8
|
const nest_logger_1 = require("@rxap/nest-logger");
|
|
9
|
+
const nest_utilities_1 = require("@rxap/nest-utilities");
|
|
8
10
|
const sentry_logger_1 = require("./sentry.logger");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const tokens_1 = require("./tokens");
|
|
12
|
+
_a = new common_1.ConfigurableModuleBuilder()
|
|
13
|
+
.setExtras({
|
|
14
|
+
isGlobal: true,
|
|
15
|
+
})
|
|
16
|
+
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
|
|
17
|
+
let SentryLoggerModule = class SentryLoggerModule extends exports.ConfigurableModuleClass {
|
|
18
|
+
static register(options, consoleLoggerOptions = null, printMessagesFunction = null) {
|
|
19
|
+
return this.updateProviders(super.register(options), consoleLoggerOptions, printMessagesFunction);
|
|
20
|
+
}
|
|
21
|
+
static registerAsync(options, consoleLoggerOptions = null, printMessagesFunction = null) {
|
|
22
|
+
return this.updateProviders(super.registerAsync(options), consoleLoggerOptions, printMessagesFunction);
|
|
23
|
+
}
|
|
24
|
+
static updateProviders(module, consoleLoggerOptions = null, printMessagesFunction) {
|
|
25
|
+
module.providers ??= [];
|
|
26
|
+
module.providers.push({
|
|
27
|
+
provide: tokens_1.SENTRY_MODULE_OPTIONS,
|
|
28
|
+
useExisting: exports.MODULE_OPTIONS_TOKEN,
|
|
29
|
+
});
|
|
30
|
+
module.providers.push({
|
|
31
|
+
provide: nest_logger_1.CONSOLE_LOGGER_OPTIONS,
|
|
32
|
+
useFactory: (options) => ({
|
|
33
|
+
timestamp: true,
|
|
34
|
+
logLevels: (0, nest_utilities_1.GetLogLevels)(),
|
|
35
|
+
...options.logger ?? {},
|
|
36
|
+
...consoleLoggerOptions ?? {},
|
|
37
|
+
}),
|
|
38
|
+
inject: [tokens_1.SENTRY_MODULE_OPTIONS],
|
|
39
|
+
});
|
|
40
|
+
if (printMessagesFunction) {
|
|
41
|
+
module.providers.push({
|
|
42
|
+
provide: nest_logger_1.RXAP_LOGGER_PRINT_MESSAGES,
|
|
43
|
+
useValue: printMessagesFunction
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return module;
|
|
47
|
+
}
|
|
13
48
|
};
|
|
14
49
|
exports.SentryLoggerModule = SentryLoggerModule;
|
|
15
50
|
exports.SentryLoggerModule = SentryLoggerModule = tslib_1.__decorate([
|
|
@@ -26,11 +61,12 @@ exports.SentryLoggerModule = SentryLoggerModule = tslib_1.__decorate([
|
|
|
26
61
|
return rxap;
|
|
27
62
|
}
|
|
28
63
|
},
|
|
29
|
-
inject: [config_1.ConfigService, sentry_logger_1.SentryLogger, nest_logger_1.RxapLogger]
|
|
64
|
+
inject: [config_1.ConfigService, sentry_logger_1.SentryLogger, nest_logger_1.RxapLogger],
|
|
30
65
|
},
|
|
31
66
|
sentry_logger_1.SentryLogger,
|
|
32
67
|
nest_logger_1.RxapLogger,
|
|
33
68
|
],
|
|
69
|
+
imports: [],
|
|
34
70
|
exports: [common_1.Logger],
|
|
35
71
|
})
|
|
36
72
|
], SentryLoggerModule);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConfigurableModuleOptionsFactory } from '@nestjs/common';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { SentryModuleOptions } from '@rxap/nest-sentry';
|
|
4
|
+
export declare class SentryModuleOptionsFactory implements ConfigurableModuleOptionsFactory<SentryModuleOptions, 'create'> {
|
|
5
|
+
protected readonly config: ConfigService;
|
|
6
|
+
create(): Promise<SentryModuleOptions>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SentryModuleOptionsFactory = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const config_1 = require("@nestjs/config");
|
|
7
|
+
const nest_utilities_1 = require("@rxap/nest-utilities");
|
|
8
|
+
const get_sentry_log_levels_1 = require("./get-sentry-log-levels");
|
|
9
|
+
let SentryModuleOptionsFactory = class SentryModuleOptionsFactory {
|
|
10
|
+
// Do not inject the logger, because it will be created circularly with the SentryModule
|
|
11
|
+
// @Inject(Logger)
|
|
12
|
+
// protected readonly logger!: Logger;
|
|
13
|
+
// Do not inject the logger, because it will be created circularly with the SentryModule
|
|
14
|
+
// @Optional()
|
|
15
|
+
// @Inject(CONSOLE_LOGGER_OPTIONS)
|
|
16
|
+
// protected readonly options?: ConsoleLoggerOptions;
|
|
17
|
+
async create() {
|
|
18
|
+
return {
|
|
19
|
+
logLevels: (0, get_sentry_log_levels_1.GetSentryLogLevels)(this.config.getOrThrow('SENTRY_LOG_LEVEL')),
|
|
20
|
+
logger: {
|
|
21
|
+
timestamp: true,
|
|
22
|
+
logLevels: (0, nest_utilities_1.GetLogLevels)(),
|
|
23
|
+
},
|
|
24
|
+
enabled: this.config.getOrThrow('SENTRY_ENABLED'),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.SentryModuleOptionsFactory = SentryModuleOptionsFactory;
|
|
29
|
+
tslib_1.__decorate([
|
|
30
|
+
(0, common_1.Inject)(config_1.ConfigService),
|
|
31
|
+
tslib_1.__metadata("design:type", config_1.ConfigService)
|
|
32
|
+
], SentryModuleOptionsFactory.prototype, "config", void 0);
|
|
33
|
+
exports.SentryModuleOptionsFactory = SentryModuleOptionsFactory = tslib_1.__decorate([
|
|
34
|
+
(0, common_1.Injectable)()
|
|
35
|
+
], SentryModuleOptionsFactory);
|
|
@@ -1,41 +1,7 @@
|
|
|
1
1
|
import { ConsoleLoggerOptions } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
enabled: boolean;
|
|
8
|
-
timeout?: number;
|
|
9
|
-
}
|
|
10
|
-
export type SentryModuleOptions = Omit<NodeOptions, 'integrations'> & {
|
|
11
|
-
integrations?: Integration[];
|
|
12
|
-
close?: SentryCloseOptions;
|
|
13
|
-
interceptors?: SentryInterceptorOptions;
|
|
14
|
-
} & ConsoleLoggerOptions;
|
|
15
|
-
export interface ISentryOptionsFactory {
|
|
16
|
-
createSentryModuleOptions(): Promise<SentryModuleOptions> | SentryModuleOptions;
|
|
17
|
-
}
|
|
18
|
-
export interface SentryModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
19
|
-
inject?: any[];
|
|
20
|
-
useClass?: Type<ISentryOptionsFactory>;
|
|
21
|
-
useExisting?: Type<ISentryOptionsFactory>;
|
|
22
|
-
useFactory?: (...args: any[]) => Promise<SentryModuleOptions> | SentryModuleOptions;
|
|
23
|
-
}
|
|
24
|
-
export interface SentryFilterFunction {
|
|
25
|
-
(exception: any): boolean;
|
|
26
|
-
}
|
|
27
|
-
export interface SentryInterceptorOptionsFilter {
|
|
28
|
-
type: any;
|
|
29
|
-
filter?: SentryFilterFunction;
|
|
30
|
-
}
|
|
31
|
-
export type SentryInterceptorOptions = AddRequestDataToEventOptions['include'] & {
|
|
32
|
-
filters?: SentryInterceptorOptionsFilter[];
|
|
33
|
-
tags?: {
|
|
34
|
-
[key: string]: string;
|
|
35
|
-
};
|
|
36
|
-
extra?: {
|
|
37
|
-
[key: string]: any;
|
|
38
|
-
};
|
|
39
|
-
fingerprint?: string[];
|
|
40
|
-
level?: SeverityLevel;
|
|
2
|
+
import { LogSeverityLevel } from '@sentry/core';
|
|
3
|
+
export type SentryModuleOptions = {
|
|
4
|
+
logLevels: LogSeverityLevel[];
|
|
5
|
+
logger?: ConsoleLoggerOptions;
|
|
6
|
+
enabled?: boolean;
|
|
41
7
|
};
|
|
@@ -8,10 +8,13 @@ import { RxapLogger } from '@rxap/nest-logger';
|
|
|
8
8
|
export declare class SentryLogger extends RxapLogger {
|
|
9
9
|
protected readonly options: ConsoleLoggerOptions;
|
|
10
10
|
private readonly sentryOptions;
|
|
11
|
+
private readonly config;
|
|
11
12
|
log(message: string, ...optionalParams: any[]): void;
|
|
12
13
|
error(message: string, ...optionalParams: any[]): void;
|
|
14
|
+
fatal(message: string, ...optionalParams: any[]): void;
|
|
13
15
|
warn(message: string, ...optionalParams: any[]): void;
|
|
14
16
|
debug(message: string, ...optionalParams: any[]): void;
|
|
17
|
+
verbose(message: string, ...optionalParams: any[]): void;
|
|
15
18
|
private _getContextAndMessagesToPrint;
|
|
16
19
|
private _getContextAndStackAndMessagesToPrint;
|
|
17
20
|
}
|
package/src/lib/sentry.logger.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.SentryLogger = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
7
|
+
const config_1 = require("@nestjs/config");
|
|
7
8
|
const nest_logger_1 = require("@rxap/nest-logger");
|
|
8
9
|
const Sentry = require("@sentry/node");
|
|
9
10
|
const tokens_1 = require("./tokens");
|
|
@@ -25,10 +26,10 @@ let SentryLogger = class SentryLogger extends nest_logger_1.RxapLogger {
|
|
|
25
26
|
...optionalParams,
|
|
26
27
|
]);
|
|
27
28
|
super.log(message, ...optionalParams);
|
|
28
|
-
if (!this.sentryOptions.
|
|
29
|
+
if (!this.sentryOptions.enabled) {
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
31
|
-
if (this.sentryOptions.logLevels && !this.sentryOptions.logLevels.includes(
|
|
32
|
+
if (this.sentryOptions.logLevels && !['log', 'info'].some(level => this.sentryOptions.logLevels.includes(level))) {
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
35
|
try {
|
|
@@ -39,11 +40,7 @@ let SentryLogger = class SentryLogger extends nest_logger_1.RxapLogger {
|
|
|
39
40
|
data: {
|
|
40
41
|
context,
|
|
41
42
|
},
|
|
42
|
-
}) :
|
|
43
|
-
Sentry.captureMessage(message, {
|
|
44
|
-
level: 'log',
|
|
45
|
-
extra: { context },
|
|
46
|
-
});
|
|
43
|
+
}) : Sentry.logger.info(message, { data: context });
|
|
47
44
|
}
|
|
48
45
|
catch (err) {
|
|
49
46
|
console.error('Failed to capture message with sentry: ' + err.message);
|
|
@@ -55,16 +52,39 @@ let SentryLogger = class SentryLogger extends nest_logger_1.RxapLogger {
|
|
|
55
52
|
...optionalParams,
|
|
56
53
|
]);
|
|
57
54
|
super.error(message, ...optionalParams);
|
|
58
|
-
if (!this.sentryOptions.
|
|
55
|
+
if (!this.sentryOptions.enabled) {
|
|
59
56
|
return;
|
|
60
57
|
}
|
|
61
58
|
if (this.sentryOptions.logLevels && !this.sentryOptions.logLevels.includes('error')) {
|
|
62
59
|
return;
|
|
63
60
|
}
|
|
64
61
|
try {
|
|
65
|
-
Sentry.
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
Sentry.logger.error(message, {
|
|
63
|
+
data: {
|
|
64
|
+
context,
|
|
65
|
+
stack,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
console.error('Failed to capture message with sentry: ' + err.message);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
fatal(message, ...optionalParams) {
|
|
74
|
+
const { context, stack, } = this._getContextAndStackAndMessagesToPrint([
|
|
75
|
+
message,
|
|
76
|
+
...optionalParams,
|
|
77
|
+
]);
|
|
78
|
+
super.error(message, ...optionalParams);
|
|
79
|
+
if (!this.sentryOptions.enabled) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (this.sentryOptions.logLevels && !this.sentryOptions.logLevels.includes('fatal')) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
Sentry.logger.fatal(message, {
|
|
87
|
+
data: {
|
|
68
88
|
context,
|
|
69
89
|
stack,
|
|
70
90
|
},
|
|
@@ -86,10 +106,10 @@ let SentryLogger = class SentryLogger extends nest_logger_1.RxapLogger {
|
|
|
86
106
|
...optionalParams,
|
|
87
107
|
]);
|
|
88
108
|
super.warn(message, ...optionalParams);
|
|
89
|
-
if (!this.sentryOptions.
|
|
109
|
+
if (!this.sentryOptions.enabled) {
|
|
90
110
|
return;
|
|
91
111
|
}
|
|
92
|
-
if (this.sentryOptions.logLevels && !this.sentryOptions.logLevels.includes(
|
|
112
|
+
if (this.sentryOptions.logLevels && !['warn', 'warning'].some(level => this.sentryOptions.logLevels.includes(level))) {
|
|
93
113
|
return;
|
|
94
114
|
}
|
|
95
115
|
try {
|
|
@@ -101,9 +121,8 @@ let SentryLogger = class SentryLogger extends nest_logger_1.RxapLogger {
|
|
|
101
121
|
context,
|
|
102
122
|
},
|
|
103
123
|
}) :
|
|
104
|
-
Sentry.
|
|
105
|
-
|
|
106
|
-
extra: { context },
|
|
124
|
+
Sentry.logger.warn(message, {
|
|
125
|
+
data: { context },
|
|
107
126
|
});
|
|
108
127
|
}
|
|
109
128
|
catch (err) {
|
|
@@ -122,7 +141,7 @@ let SentryLogger = class SentryLogger extends nest_logger_1.RxapLogger {
|
|
|
122
141
|
...optionalParams,
|
|
123
142
|
]);
|
|
124
143
|
super.debug(message, ...optionalParams);
|
|
125
|
-
if (!this.sentryOptions.
|
|
144
|
+
if (!this.sentryOptions.enabled) {
|
|
126
145
|
return;
|
|
127
146
|
}
|
|
128
147
|
if (this.sentryOptions.logLevels && !this.sentryOptions.logLevels.includes('debug')) {
|
|
@@ -137,15 +156,35 @@ let SentryLogger = class SentryLogger extends nest_logger_1.RxapLogger {
|
|
|
137
156
|
context,
|
|
138
157
|
},
|
|
139
158
|
}) :
|
|
140
|
-
Sentry.
|
|
141
|
-
|
|
142
|
-
extra: { context },
|
|
159
|
+
Sentry.logger.debug(message, {
|
|
160
|
+
data: { context },
|
|
143
161
|
});
|
|
144
162
|
}
|
|
145
163
|
catch (err) {
|
|
146
164
|
console.error('Failed to capture message with sentry: ' + err.message);
|
|
147
165
|
}
|
|
148
166
|
}
|
|
167
|
+
verbose(message, ...optionalParams) {
|
|
168
|
+
const { context } = this._getContextAndMessagesToPrint([
|
|
169
|
+
message,
|
|
170
|
+
...optionalParams,
|
|
171
|
+
]);
|
|
172
|
+
super.verbose(message, ...optionalParams);
|
|
173
|
+
if (!this.sentryOptions.enabled) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (this.sentryOptions.logLevels && !['verbose', 'trace'].some(level => this.sentryOptions.logLevels.includes(level))) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
Sentry.logger.trace(message, {
|
|
181
|
+
data: { context },
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
console.error('Failed to capture message with sentry: ' + err.message);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
149
188
|
_getContextAndMessagesToPrint(args) {
|
|
150
189
|
if (args?.length <= 1) {
|
|
151
190
|
return {
|
|
@@ -199,6 +238,10 @@ tslib_1.__decorate([
|
|
|
199
238
|
(0, common_1.Inject)(tokens_1.SENTRY_MODULE_OPTIONS),
|
|
200
239
|
tslib_1.__metadata("design:type", Object)
|
|
201
240
|
], SentryLogger.prototype, "sentryOptions", void 0);
|
|
241
|
+
tslib_1.__decorate([
|
|
242
|
+
(0, common_1.Inject)(config_1.ConfigService),
|
|
243
|
+
tslib_1.__metadata("design:type", config_1.ConfigService)
|
|
244
|
+
], SentryLogger.prototype, "config", void 0);
|
|
202
245
|
exports.SentryLogger = SentryLogger = tslib_1.__decorate([
|
|
203
246
|
(0, common_1.Injectable)()
|
|
204
247
|
], SentryLogger);
|
package/src/lib/tokens.d.ts
CHANGED
package/src/lib/tokens.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SENTRY_MODULE_OPTIONS = void 0;
|
|
4
4
|
exports.SENTRY_MODULE_OPTIONS = Symbol('SentryModuleOptions');
|
|
5
|
-
/**
|
|
6
|
-
* InjectionToken for an object of type SentryInterceptorOptions
|
|
7
|
-
*/
|
|
8
|
-
exports.SENTRY_INTERCEPTOR_OPTIONS = Symbol('SENTRY_INTERCEPTOR_OPTIONS');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { INestApplicationContext } from '@nestjs/common';
|
|
2
2
|
import { ConfigService } from '@nestjs/config';
|
|
3
3
|
import { RxapLogger } from '@rxap/nest-logger';
|
|
4
|
-
import { SentryLogger } from '
|
|
4
|
+
import { SentryLogger } from './sentry.logger';
|
|
5
5
|
export declare function UseSentryLoggerFactory(): (app: INestApplicationContext, config: ConfigService) => SentryLogger | RxapLogger;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UseSentryLoggerFactory = UseSentryLoggerFactory;
|
|
4
4
|
const nest_logger_1 = require("@rxap/nest-logger");
|
|
5
|
-
const
|
|
5
|
+
const sentry_logger_1 = require("./sentry.logger");
|
|
6
6
|
function UseSentryLoggerFactory() {
|
|
7
7
|
return (app, config) => {
|
|
8
8
|
if (config.get('SENTRY_ENABLED')) {
|
|
9
|
-
return app.get(
|
|
9
|
+
return app.get(sentry_logger_1.SentryLogger);
|
|
10
10
|
}
|
|
11
11
|
else {
|
|
12
12
|
return app.get(nest_logger_1.RxapLogger);
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ConfigService } from '@nestjs/config';
|
|
2
|
-
import { Environment } from '@rxap/nest-utilities';
|
|
3
|
-
import { SentryModuleOptions } from './sentry.interfaces';
|
|
4
|
-
export declare function SentryOptionsFactory(environment: Environment): (config: ConfigService) => SentryModuleOptions;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SentryOptionsFactory = SentryOptionsFactory;
|
|
4
|
-
const nest_utilities_1 = require("@rxap/nest-utilities");
|
|
5
|
-
function SentryOptionsFactory(environment) {
|
|
6
|
-
return (config) => {
|
|
7
|
-
const options = {
|
|
8
|
-
dsn: config.get('SENTRY_DSN'),
|
|
9
|
-
enabled: config.get('SENTRY_ENABLED', false),
|
|
10
|
-
environment: config.get('SENTRY_ENVIRONMENT', (0, nest_utilities_1.DetermineEnvironment)(environment)),
|
|
11
|
-
release: config.get('SENTRY_RELEASE', (0, nest_utilities_1.DetermineRelease)(environment)),
|
|
12
|
-
serverName: config.get('SENTRY_SERVER_NAME', environment.name),
|
|
13
|
-
debug: config.get('SENTRY_DEBUG', false),
|
|
14
|
-
tracesSampleRate: config.get('SENTRY_TRACES_SAMPLE_RATE', 1.0),
|
|
15
|
-
profilesSampleRate: config.get('SENTRY_PROFILES_SAMPLE_RATE', 1.0),
|
|
16
|
-
logLevels: config.get('SENTRY_LOG_LEVELS', ['warn', 'error']),
|
|
17
|
-
maxValueLength: config.get('SENTRY_MAX_VALUE_LENGTH', Number.MAX_SAFE_INTEGER),
|
|
18
|
-
normalizeDepth: config.get('SENTRY_NORMALIZE_DEPTH', 5),
|
|
19
|
-
};
|
|
20
|
-
console.debug(`[SentryOptionsFactory] SentryOptions: ${JSON.stringify(options)}`);
|
|
21
|
-
return options;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
-
import { Scope } from '@sentry/core';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
4
|
-
import { SentryInterceptorOptions } from './sentry.interfaces';
|
|
5
|
-
export declare class SentryInterceptor implements NestInterceptor {
|
|
6
|
-
protected readonly options?: SentryInterceptorOptions;
|
|
7
|
-
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
8
|
-
protected captureException(context: ExecutionContext, scope: Scope, exception: unknown): void;
|
|
9
|
-
private captureHttpException;
|
|
10
|
-
private captureRpcException;
|
|
11
|
-
private captureWsException;
|
|
12
|
-
private shouldReport;
|
|
13
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SentryInterceptor = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@nestjs/common");
|
|
6
|
-
const Sentry = require("@sentry/nestjs");
|
|
7
|
-
const node_1 = require("@sentry/node");
|
|
8
|
-
const operators_1 = require("rxjs/operators");
|
|
9
|
-
const tokens_1 = require("./tokens");
|
|
10
|
-
let SentryInterceptor = class SentryInterceptor {
|
|
11
|
-
intercept(context, next) {
|
|
12
|
-
return next.handle().pipe((0, operators_1.tap)({
|
|
13
|
-
error: (exception) => {
|
|
14
|
-
if (this.shouldReport(exception)) {
|
|
15
|
-
Sentry.withScope((scope) => {
|
|
16
|
-
return this.captureException(context, scope, exception);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
}));
|
|
21
|
-
}
|
|
22
|
-
captureException(context, scope, exception) {
|
|
23
|
-
if (exception && typeof exception === 'object' && typeof exception['setScope'] === 'function') {
|
|
24
|
-
exception['setScope'](scope);
|
|
25
|
-
}
|
|
26
|
-
switch (context.getType()) {
|
|
27
|
-
case 'http':
|
|
28
|
-
return this.captureHttpException(scope, context.switchToHttp(), exception);
|
|
29
|
-
case 'rpc':
|
|
30
|
-
return this.captureRpcException(scope, context.switchToRpc(), exception);
|
|
31
|
-
case 'ws':
|
|
32
|
-
return this.captureWsException(scope, context.switchToWs(), exception);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
captureHttpException(scope, http, exception) {
|
|
36
|
-
const data = (0, node_1.addRequestDataToEvent)({}, http.getRequest(), { include: this.options });
|
|
37
|
-
scope.setExtra('req', data.request);
|
|
38
|
-
if (data.extra) {
|
|
39
|
-
scope.setExtras(data.extra);
|
|
40
|
-
}
|
|
41
|
-
if (data.user) {
|
|
42
|
-
scope.setUser(data.user);
|
|
43
|
-
}
|
|
44
|
-
Sentry.captureException(exception);
|
|
45
|
-
}
|
|
46
|
-
captureRpcException(scope, rpc, exception) {
|
|
47
|
-
scope.setExtra('rpc_data', rpc.getData());
|
|
48
|
-
Sentry.captureException(exception);
|
|
49
|
-
}
|
|
50
|
-
captureWsException(scope, ws, exception) {
|
|
51
|
-
scope.setExtra('ws_client', ws.getClient());
|
|
52
|
-
scope.setExtra('ws_data', ws.getData());
|
|
53
|
-
Sentry.captureException(exception);
|
|
54
|
-
}
|
|
55
|
-
shouldReport(exception) {
|
|
56
|
-
if (!this.options?.filters) {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
return this.options.filters
|
|
60
|
-
.some(({ type, filter, }) => !(exception instanceof type && (!filter || filter(exception))));
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
exports.SentryInterceptor = SentryInterceptor;
|
|
64
|
-
tslib_1.__decorate([
|
|
65
|
-
(0, common_1.Optional)(),
|
|
66
|
-
(0, common_1.Inject)(tokens_1.SENTRY_INTERCEPTOR_OPTIONS),
|
|
67
|
-
tslib_1.__metadata("design:type", Object)
|
|
68
|
-
], SentryInterceptor.prototype, "options", void 0);
|
|
69
|
-
exports.SentryInterceptor = SentryInterceptor = tslib_1.__decorate([
|
|
70
|
-
(0, common_1.Injectable)()
|
|
71
|
-
], SentryInterceptor);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ConsoleLoggerOptions, DynamicModule } from '@nestjs/common';
|
|
2
|
-
import { PrintMessagesFunction } from '@rxap/nest-logger';
|
|
3
|
-
import { SentryInterceptorOptions, SentryModuleOptions } from './sentry.interfaces';
|
|
4
|
-
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<SentryModuleOptions, "register", "create", {
|
|
5
|
-
isGlobal: boolean;
|
|
6
|
-
}>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: Omit<import("@sentry/node").NodeOptions, "integrations"> & {
|
|
7
|
-
integrations?: import("@sentry/types").Integration[];
|
|
8
|
-
close?: import("./sentry.interfaces").SentryCloseOptions;
|
|
9
|
-
interceptors?: SentryInterceptorOptions;
|
|
10
|
-
} & ConsoleLoggerOptions & Partial<{
|
|
11
|
-
isGlobal: boolean;
|
|
12
|
-
}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<SentryModuleOptions, "create"> & Partial<{
|
|
13
|
-
isGlobal: boolean;
|
|
14
|
-
}>;
|
|
15
|
-
export declare const DEFAULT_SENTRY_INTERCEPTOR_OPTIONS: SentryInterceptorOptions;
|
|
16
|
-
export declare class SentryModule extends ConfigurableModuleClass {
|
|
17
|
-
static register(options?: typeof OPTIONS_TYPE, consoleLoggerOptions?: ConsoleLoggerOptions, printMessagesFunction?: PrintMessagesFunction | null): DynamicModule;
|
|
18
|
-
static registerAsync(options: typeof ASYNC_OPTIONS_TYPE, consoleLoggerOptions?: ConsoleLoggerOptions, printMessagesFunction?: PrintMessagesFunction | null): DynamicModule;
|
|
19
|
-
private static updateProviders;
|
|
20
|
-
static forRoot(options: typeof OPTIONS_TYPE, consoleLoggerOptions?: ConsoleLoggerOptions): DynamicModule;
|
|
21
|
-
static forRootAsync(options: typeof ASYNC_OPTIONS_TYPE, consoleLoggerOptions?: ConsoleLoggerOptions): DynamicModule;
|
|
22
|
-
}
|
package/src/lib/sentry.module.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.SentryModule = exports.DEFAULT_SENTRY_INTERCEPTOR_OPTIONS = exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const common_1 = require("@nestjs/common");
|
|
7
|
-
const config_1 = require("@nestjs/config");
|
|
8
|
-
const core_1 = require("@nestjs/core");
|
|
9
|
-
const nest_logger_1 = require("@rxap/nest-logger");
|
|
10
|
-
const sentry_interceptor_1 = require("./sentry.interceptor");
|
|
11
|
-
const sentry_logger_1 = require("./sentry.logger");
|
|
12
|
-
const tokens_1 = require("./tokens");
|
|
13
|
-
_a = new common_1.ConfigurableModuleBuilder()
|
|
14
|
-
.setExtras({
|
|
15
|
-
isGlobal: true,
|
|
16
|
-
})
|
|
17
|
-
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
|
|
18
|
-
exports.DEFAULT_SENTRY_INTERCEPTOR_OPTIONS = {
|
|
19
|
-
filters: [
|
|
20
|
-
{
|
|
21
|
-
type: common_1.HttpException,
|
|
22
|
-
filter: (exception) => 500 > exception.getStatus(),
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
};
|
|
26
|
-
let SentryModule = class SentryModule extends exports.ConfigurableModuleClass {
|
|
27
|
-
static register(options = {}, consoleLoggerOptions = {}, printMessagesFunction = null) {
|
|
28
|
-
return this.updateProviders(super.register(options), consoleLoggerOptions, printMessagesFunction);
|
|
29
|
-
}
|
|
30
|
-
static registerAsync(options, consoleLoggerOptions = {}, printMessagesFunction = null) {
|
|
31
|
-
return this.updateProviders(super.registerAsync(options), consoleLoggerOptions, printMessagesFunction);
|
|
32
|
-
}
|
|
33
|
-
static updateProviders(module, { timestamp, logLevels, ...consoleLoggerOptions }, printMessagesFunction) {
|
|
34
|
-
module.providers ??= [];
|
|
35
|
-
module.providers.push({
|
|
36
|
-
provide: tokens_1.SENTRY_MODULE_OPTIONS,
|
|
37
|
-
useExisting: exports.MODULE_OPTIONS_TOKEN,
|
|
38
|
-
});
|
|
39
|
-
module.providers.push({
|
|
40
|
-
provide: nest_logger_1.CONSOLE_LOGGER_OPTIONS,
|
|
41
|
-
useValue: {
|
|
42
|
-
...consoleLoggerOptions,
|
|
43
|
-
timestamp: timestamp ?? true,
|
|
44
|
-
logLevels: logLevels ?? ['log', 'error', 'warn'],
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
module.providers.push({
|
|
48
|
-
provide: tokens_1.SENTRY_INTERCEPTOR_OPTIONS,
|
|
49
|
-
useFactory: (options) => options.interceptors ?? exports.DEFAULT_SENTRY_INTERCEPTOR_OPTIONS,
|
|
50
|
-
inject: [exports.MODULE_OPTIONS_TOKEN]
|
|
51
|
-
});
|
|
52
|
-
if (printMessagesFunction) {
|
|
53
|
-
module.providers.push({
|
|
54
|
-
provide: nest_logger_1.RXAP_LOGGER_PRINT_MESSAGES,
|
|
55
|
-
useValue: printMessagesFunction
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
module.providers.push({
|
|
59
|
-
provide: core_1.APP_INTERCEPTOR,
|
|
60
|
-
useClass: sentry_interceptor_1.SentryInterceptor,
|
|
61
|
-
});
|
|
62
|
-
return module;
|
|
63
|
-
}
|
|
64
|
-
static forRoot(options, consoleLoggerOptions = {}) {
|
|
65
|
-
return this.register(options, consoleLoggerOptions);
|
|
66
|
-
}
|
|
67
|
-
static forRootAsync(options, consoleLoggerOptions = {}) {
|
|
68
|
-
return this.registerAsync(options, consoleLoggerOptions);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
exports.SentryModule = SentryModule;
|
|
72
|
-
exports.SentryModule = SentryModule = tslib_1.__decorate([
|
|
73
|
-
(0, common_1.Global)(),
|
|
74
|
-
(0, common_1.Module)({
|
|
75
|
-
providers: [
|
|
76
|
-
{
|
|
77
|
-
provide: common_1.Logger,
|
|
78
|
-
useFactory: (config, sentry, rxap) => {
|
|
79
|
-
if (config.get('SENTRY_ENABLED')) {
|
|
80
|
-
return sentry;
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
return rxap;
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
inject: [config_1.ConfigService, sentry_logger_1.SentryLogger, nest_logger_1.RxapLogger],
|
|
87
|
-
},
|
|
88
|
-
sentry_logger_1.SentryLogger,
|
|
89
|
-
nest_logger_1.RxapLogger,
|
|
90
|
-
],
|
|
91
|
-
exports: [common_1.Logger],
|
|
92
|
-
})
|
|
93
|
-
], SentryModule);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { OnApplicationBootstrap, OnApplicationShutdown } from '@nestjs/common';
|
|
2
|
-
import * as Sentry from "@sentry/nestjs";
|
|
3
|
-
export declare class SentryService implements OnApplicationShutdown, OnApplicationBootstrap {
|
|
4
|
-
private readonly options;
|
|
5
|
-
private readonly logger;
|
|
6
|
-
get hasInstance(): boolean;
|
|
7
|
-
onApplicationBootstrap(): any;
|
|
8
|
-
instance(): typeof Sentry;
|
|
9
|
-
onApplicationShutdown(signal?: string): Promise<void>;
|
|
10
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SentryService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@nestjs/common");
|
|
6
|
-
const tokens_1 = require("./tokens");
|
|
7
|
-
const Sentry = require("@sentry/nestjs");
|
|
8
|
-
const profiling_node_1 = require("@sentry/profiling-node");
|
|
9
|
-
let SentryService = class SentryService {
|
|
10
|
-
get hasInstance() {
|
|
11
|
-
return !!this.options.dsn;
|
|
12
|
-
}
|
|
13
|
-
onApplicationBootstrap() {
|
|
14
|
-
if (!this.options.dsn) {
|
|
15
|
-
if (this.options.enabled !== false) {
|
|
16
|
-
this.logger.warn('Could not create SentryService instance. The required option dsn is not defined', 'SentryService');
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
this.logger.verbose('Dsn is not defined, but sentry is disabled', 'SentryService');
|
|
20
|
-
}
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const { integrations = [], ...sentryOptions } = this.options;
|
|
24
|
-
Sentry.init({
|
|
25
|
-
...sentryOptions,
|
|
26
|
-
integrations: [
|
|
27
|
-
(0, profiling_node_1.nodeProfilingIntegration)(),
|
|
28
|
-
Sentry.onUncaughtExceptionIntegration({
|
|
29
|
-
onFatalError: async (err) => {
|
|
30
|
-
// console.error('uncaughtException, not cool!')
|
|
31
|
-
// console.error(err);
|
|
32
|
-
if (err.name === 'SentryError') {
|
|
33
|
-
console.log(err);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
Sentry.getCurrentHub().getClient().captureException(err);
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
}),
|
|
41
|
-
Sentry.onUnhandledRejectionIntegration({ mode: 'warn' }),
|
|
42
|
-
...integrations,
|
|
43
|
-
],
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
instance() {
|
|
47
|
-
return Sentry;
|
|
48
|
-
}
|
|
49
|
-
async onApplicationShutdown(signal) {
|
|
50
|
-
if (this.hasInstance && this.options.close?.enabled === true) {
|
|
51
|
-
await Sentry.close(this.options.close.timeout);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
exports.SentryService = SentryService;
|
|
56
|
-
tslib_1.__decorate([
|
|
57
|
-
(0, common_1.Inject)(tokens_1.SENTRY_MODULE_OPTIONS),
|
|
58
|
-
tslib_1.__metadata("design:type", Object)
|
|
59
|
-
], SentryService.prototype, "options", void 0);
|
|
60
|
-
tslib_1.__decorate([
|
|
61
|
-
(0, common_1.Inject)(common_1.Logger),
|
|
62
|
-
tslib_1.__metadata("design:type", common_1.Logger)
|
|
63
|
-
], SentryService.prototype, "logger", void 0);
|
|
64
|
-
exports.SentryService = SentryService = tslib_1.__decorate([
|
|
65
|
-
(0, common_1.Injectable)()
|
|
66
|
-
], SentryService);
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SetupSentryErrorHandler = SetupSentryErrorHandler;
|
|
4
|
-
const core_1 = require("@nestjs/core");
|
|
5
|
-
const Sentry = require("@sentry/nestjs");
|
|
6
|
-
function SetupSentryErrorHandler() {
|
|
7
|
-
return (app) => {
|
|
8
|
-
const { httpAdapter } = app.get(core_1.HttpAdapterHost);
|
|
9
|
-
Sentry.setupNestErrorHandler(app, new core_1.BaseExceptionFilter(httpAdapter));
|
|
10
|
-
};
|
|
11
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { INestApplication } from '@nestjs/common';
|
|
2
|
-
import { ConfigService } from '@nestjs/config';
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated instead import the module SentryLoggerModule in the AppModule
|
|
5
|
-
*/
|
|
6
|
-
export declare function SetupSentryLogger(): (app: INestApplication, config: ConfigService) => void;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SetupSentryLogger = SetupSentryLogger;
|
|
4
|
-
const nest_logger_1 = require("@rxap/nest-logger");
|
|
5
|
-
const sentry_logger_1 = require("./sentry.logger");
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated instead import the module SentryLoggerModule in the AppModule
|
|
8
|
-
*/
|
|
9
|
-
function SetupSentryLogger() {
|
|
10
|
-
return (app, config) => {
|
|
11
|
-
if (config.get('SENTRY_ENABLED')) {
|
|
12
|
-
app.useLogger(app.get(sentry_logger_1.SentryLogger));
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
app.useLogger(new nest_logger_1.RxapLogger());
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|