@rsdk/core 4.0.1-next.0 → 4.0.1-next.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.
- package/CHANGELOG.md +10 -0
- package/dist/tracing/auto-instrumentations.config.d.ts +1 -0
- package/dist/tracing/auto-instrumentations.config.js +43 -0
- package/dist/tracing/auto-instrumentations.config.js.map +1 -0
- package/dist/tracing/services/request-metadata.storage.d.ts +1 -1
- package/dist/tracing/services/request-metadata.storage.js +1 -1
- package/dist/tracing/services/request-metadata.storage.js.map +1 -1
- package/dist/tracing/tracing.module.d.ts +1 -1
- package/dist/tracing/tracing.module.js +32 -19
- package/dist/tracing/tracing.module.js.map +1 -1
- package/package.json +11 -10
- package/src/tracing/auto-instrumentations.config.ts +45 -0
- package/src/tracing/services/request-metadata.storage.ts +1 -1
- package/src/tracing/tracing.module.ts +40 -27
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
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
|
+
## [4.0.1-next.2](https://github.com/R-Vision/rsdk/compare/v4.0.1-next.1...v4.0.1-next.2) (2023-12-07)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **db:** added queued initialization db context ([#169](https://github.com/R-Vision/rsdk/issues/169)) ([ea481ed](https://github.com/R-Vision/rsdk/commit/ea481edce9bbc7bd702fc046a37fb5a5580a88dd))
|
|
11
|
+
|
|
12
|
+
## [4.0.1-next.1](https://github.com/R-Vision/rsdk/compare/v4.0.0...v4.0.1-next.1) (2023-12-06)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @rsdk/core
|
|
15
|
+
|
|
6
16
|
## [4.0.1-next.0](https://github.com/R-Vision/rsdk/compare/v4.0.0...v4.0.1-next.0) (2023-12-06)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @rsdk/core
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const autoInstumentationOptions: any[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.autoInstumentationOptions = void 0;
|
|
4
|
+
const auto_instrumentations_node_1 = require("@opentelemetry/auto-instrumentations-node");
|
|
5
|
+
const node_http_1 = require("node:http");
|
|
6
|
+
const request_metadata_storage_1 = require("./services/request-metadata.storage");
|
|
7
|
+
exports.autoInstumentationOptions = (0, auto_instrumentations_node_1.getNodeAutoInstrumentations)({
|
|
8
|
+
'@opentelemetry/instrumentation-aws-sdk': {
|
|
9
|
+
responseHook: (span, { response }) => {
|
|
10
|
+
if (response.request.commandInput?.Bucket) {
|
|
11
|
+
span.setAttribute('s3.bucket.name', response.request.commandInput?.Bucket);
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
'@opentelemetry/instrumentation-graphql': {
|
|
16
|
+
allowValues: true,
|
|
17
|
+
},
|
|
18
|
+
'@opentelemetry/instrumentation-http': {
|
|
19
|
+
requestHook: (span, request) => {
|
|
20
|
+
if (request instanceof node_http_1.IncomingMessage) {
|
|
21
|
+
if (request.method && request.url) {
|
|
22
|
+
span.updateName(`${request.method} ${request.url}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else if (request instanceof node_http_1.ClientRequest &&
|
|
26
|
+
request.req.method &&
|
|
27
|
+
request.req.url) {
|
|
28
|
+
span.updateName(`${request.req.method} ${request.req.url}`);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
'@opentelemetry/instrumentation-pg': {
|
|
33
|
+
enhancedDatabaseReporting: true,
|
|
34
|
+
},
|
|
35
|
+
'@opentelemetry/instrumentation-pino': {
|
|
36
|
+
enabled: true,
|
|
37
|
+
logHook: (_span, record) => {
|
|
38
|
+
record['request_id'] =
|
|
39
|
+
request_metadata_storage_1.RequestMetadataStorage.getInstance()?.getRequestMetadata().requestId;
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=auto-instrumentations.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-instrumentations.config.js","sourceRoot":"","sources":["../../src/tracing/auto-instrumentations.config.ts"],"names":[],"mappings":";;;AAAA,0FAAwF;AACxF,yCAA2D;AAE3D,kFAA6E;AAEhE,QAAA,yBAAyB,GAAU,IAAA,wDAA2B,EAAC;IAC1E,wCAAwC,EAAE;QACxC,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;YACnC,IAAI,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;gBAC1C,IAAI,CAAC,YAAY,CACf,gBAAgB,EAChB,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CACtC,CAAC;YACJ,CAAC;QACH,CAAC;KACF;IACD,wCAAwC,EAAE;QACxC,WAAW,EAAE,IAAI;KAClB;IACD,qCAAqC,EAAE;QACrC,WAAW,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;YAC7B,IAAI,OAAO,YAAY,2BAAe,EAAE,CAAC;gBACvC,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;oBAClC,IAAI,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;gBACtD,CAAC;YACH,CAAC;iBAAM,IACL,OAAO,YAAY,yBAAa;gBAChC,OAAO,CAAC,GAAG,CAAC,MAAM;gBAClB,OAAO,CAAC,GAAG,CAAC,GAAG,EACf,CAAC;gBACD,IAAI,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC;KACF;IACD,mCAAmC,EAAE;QACnC,yBAAyB,EAAE,IAAI;KAChC;IACD,qCAAqC,EAAE;QACrC,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YACzB,MAAM,CAAC,YAAY,CAAC;gBAClB,iDAAsB,CAAC,WAAW,EAAE,EAAE,kBAAkB,EAAE,CAAC,SAAS,CAAC;QACzE,CAAC;KACF;CACF,CAAC,CAAC"}
|
|
@@ -18,7 +18,7 @@ export declare class RequestMetadataStorage {
|
|
|
18
18
|
/**
|
|
19
19
|
* Получает новое значение из контекста
|
|
20
20
|
*/
|
|
21
|
-
getRequestMetadata():
|
|
21
|
+
getRequestMetadata(): RequestMetadata;
|
|
22
22
|
/**
|
|
23
23
|
* Запускает переданную фунцию в контексте
|
|
24
24
|
* @template TResult
|
|
@@ -37,7 +37,7 @@ let RequestMetadataStorage = class RequestMetadataStorage {
|
|
|
37
37
|
/**
|
|
38
38
|
* Получает новое значение из контекста
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
getRequestMetadata() {
|
|
41
41
|
return (RequestMetadataStorage_1.instance?.asyncLocalStorage.getStore()
|
|
42
42
|
?.requestMetadata ?? {
|
|
43
43
|
requestId: undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-metadata.storage.js","sourceRoot":"","sources":["../../../src/tracing/services/request-metadata.storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,uDAAqD;AAMrD;;;;GAIG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;;IACjC;;;OAGG;IACK,MAAM,CAAC,QAAQ,CAAqC;IAEpD,iBAAiB,GAAG,IAAI,oCAAiB,EAE7C,CAAC;IAEL;QACE,IAAI,CAAC,wBAAsB,CAAC,QAAQ,EAAE,CAAC;YACrC,wBAAsB,CAAC,QAAQ,GAAG,IAAI,CAAC;QACzC,CAAC;IACH,CAAC;IAED,MAAM,CAAC,WAAW;QAChB,OAAO,wBAAsB,CAAC,QAAQ,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,
|
|
1
|
+
{"version":3,"file":"request-metadata.storage.js","sourceRoot":"","sources":["../../../src/tracing/services/request-metadata.storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,uDAAqD;AAMrD;;;;GAIG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;;IACjC;;;OAGG;IACK,MAAM,CAAC,QAAQ,CAAqC;IAEpD,iBAAiB,GAAG,IAAI,oCAAiB,EAE7C,CAAC;IAEL;QACE,IAAI,CAAC,wBAAsB,CAAC,QAAQ,EAAE,CAAC;YACrC,wBAAsB,CAAC,QAAQ,GAAG,IAAI,CAAC;QACzC,CAAC;IACH,CAAC;IAED,MAAM,CAAC,WAAW;QAChB,OAAO,wBAAsB,CAAC,QAAQ,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,CACL,wBAAsB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,EAAE;YAC3D,EAAE,eAAe,IAAI;YACrB,SAAS,EAAE,SAAS;SACrB,CACF,CAAC;IACJ,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CACD,eAAgC,EAChC,EAA+B,EAC/B,GAAG,IAAW;QAEd,OAAO,CACL,wBAAsB,EAAE,QAAQ,EAAE,iBAAiB,CAAC,GAAG,CACrD,EAAE,eAAe,EAAE,EACnB,EAAE,EACF,GAAG,IAAI,CACR,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,CACjB,CAAC;IACJ,CAAC;CACF,CAAA;AAvDY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;;GACA,sBAAsB,CAuDlC"}
|
|
@@ -16,7 +16,7 @@ export declare class TracingModule {
|
|
|
16
16
|
private readonly config;
|
|
17
17
|
constructor(logger: ILogger, instrumentations: InstrumentationService, sdk: NodeSDK, config: TracingModuleConfig);
|
|
18
18
|
static forRoot(options: TracingModuleOptions): DynamicModule;
|
|
19
|
-
private static createSDKProvider;
|
|
20
19
|
onModuleInit(): Promise<void>;
|
|
20
|
+
private static createSDKProvider;
|
|
21
21
|
beforeApplicationShutdown(): Promise<void>;
|
|
22
22
|
}
|
|
@@ -18,7 +18,9 @@ const common_1 = require("@nestjs/common");
|
|
|
18
18
|
const core_1 = require("@nestjs/core");
|
|
19
19
|
const api_1 = require("@opentelemetry/api");
|
|
20
20
|
const context_async_hooks_1 = require("@opentelemetry/context-async-hooks");
|
|
21
|
+
const core_2 = require("@opentelemetry/core");
|
|
21
22
|
const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
|
|
23
|
+
const propagator_b3_1 = require("@opentelemetry/propagator-b3");
|
|
22
24
|
const resources_1 = require("@opentelemetry/resources");
|
|
23
25
|
const sdk_node_1 = require("@opentelemetry/sdk-node");
|
|
24
26
|
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
@@ -26,6 +28,7 @@ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
|
26
28
|
const logging_1 = require("@rsdk/logging");
|
|
27
29
|
const logging_2 = require("../logging");
|
|
28
30
|
const active_span_module_1 = require("./active-span.module");
|
|
31
|
+
const auto_instrumentations_config_1 = require("./auto-instrumentations.config");
|
|
29
32
|
const request_metadata_module_1 = require("./request-metadata.module");
|
|
30
33
|
const services_1 = require("./services");
|
|
31
34
|
const tracing_config_1 = require("./tracing.config");
|
|
@@ -55,6 +58,26 @@ let TracingModule = TracingModule_1 = class TracingModule {
|
|
|
55
58
|
],
|
|
56
59
|
};
|
|
57
60
|
}
|
|
61
|
+
// Можно добавить включение и выключение при изменении конфига.
|
|
62
|
+
async onModuleInit() {
|
|
63
|
+
this.logger.debug('Injecting request-metadata storage...');
|
|
64
|
+
this.instrumentations.injectWrapRequestMetadataInjector();
|
|
65
|
+
if (!this.config.enabled) {
|
|
66
|
+
this.logger.info('Tracing is disabled');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.logger.info('Tracing is enabled');
|
|
70
|
+
this.logger.debug('Starting Open Telemetry SDK...');
|
|
71
|
+
this.sdk.start();
|
|
72
|
+
this.logger.debug('Instrumenting nest.js entities...');
|
|
73
|
+
this.instrumentations.injectWrapTraceInjector();
|
|
74
|
+
this.logger.debug('Attaching log messages to spans...');
|
|
75
|
+
logging_1.LoggerFactory.applyInstrumentations();
|
|
76
|
+
logging_1.LoggerFactory.onMessage((level, msg) => {
|
|
77
|
+
const span = api_1.trace.getSpan(api_1.context.active());
|
|
78
|
+
span?.addEvent('log', { ...msg, level });
|
|
79
|
+
});
|
|
80
|
+
}
|
|
58
81
|
static createSDKProvider(options) {
|
|
59
82
|
return {
|
|
60
83
|
provide: sdk_node_1.NodeSDK,
|
|
@@ -70,33 +93,23 @@ let TracingModule = TracingModule_1 = class TracingModule {
|
|
|
70
93
|
return new sdk_node_1.NodeSDK({
|
|
71
94
|
autoDetectResources: true,
|
|
72
95
|
contextManager: new context_async_hooks_1.AsyncLocalStorageContextManager(),
|
|
96
|
+
instrumentations: [auto_instrumentations_config_1.autoInstumentationOptions],
|
|
73
97
|
resource: new resources_1.Resource({
|
|
74
98
|
[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: options.appName,
|
|
75
99
|
}),
|
|
76
100
|
spanProcessor: processor,
|
|
101
|
+
textMapPropagator: new core_2.CompositePropagator({
|
|
102
|
+
propagators: [
|
|
103
|
+
new propagator_b3_1.B3Propagator(),
|
|
104
|
+
new propagator_b3_1.B3Propagator({
|
|
105
|
+
injectEncoding: propagator_b3_1.B3InjectEncoding.MULTI_HEADER,
|
|
106
|
+
}),
|
|
107
|
+
],
|
|
108
|
+
}),
|
|
77
109
|
});
|
|
78
110
|
},
|
|
79
111
|
};
|
|
80
112
|
}
|
|
81
|
-
// Можно добавить включение и выключение при изменении конфига.
|
|
82
|
-
async onModuleInit() {
|
|
83
|
-
this.logger.debug('Injecting request-metadata storage...');
|
|
84
|
-
this.instrumentations.injectWrapRequestMetadataInjector();
|
|
85
|
-
if (!this.config.enabled) {
|
|
86
|
-
this.logger.info('Tracing is disabled');
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
this.logger.info('Tracing is enabled');
|
|
90
|
-
this.logger.debug('Starting Open Telemetry SDK...');
|
|
91
|
-
await this.sdk.start();
|
|
92
|
-
this.logger.debug('Instrumenting nest.js entities...');
|
|
93
|
-
this.instrumentations.injectWrapTraceInjector();
|
|
94
|
-
this.logger.debug('Attaching log messages to spans...');
|
|
95
|
-
logging_1.LoggerFactory.onMessage((level, msg) => {
|
|
96
|
-
const span = api_1.trace.getSpan(api_1.context.active());
|
|
97
|
-
span?.addEvent('log', { ...msg, level });
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
113
|
async beforeApplicationShutdown() {
|
|
101
114
|
this.logger.info('Shutting down Open Telemetry SDK...');
|
|
102
115
|
await this.sdk.shutdown();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.module.js","sourceRoot":"","sources":["../../src/tracing/tracing.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,2CAAwC;AACxC,uCAA+C;AAC/C,4CAAoD;AACpD,4EAAqF;AACrF,sFAA4E;AAC5E,wDAAoD;AACpD,sDAAkD;AAElD,kEAGuC;AACvC,8EAAiF;AACjF,2CAAuD;AAEvD,wCAA0C;AAE1C,6DAAwD;AACxD,uEAAkE;AAClE,yCAAoD;AACpD,qDAAuD;AACvD,+DAA2D;AASpD,IAAM,aAAa,qBAAnB,MAAM,aAAa;IAEwB;IAC7B;IACA;IACA;IAJnB,YACgD,MAAe,EAC5C,gBAAwC,EACxC,GAAY,EACZ,MAA2B;QAHE,WAAM,GAAN,MAAM,CAAS;QAC5C,qBAAgB,GAAhB,gBAAgB,CAAwB;QACxC,QAAG,GAAH,GAAG,CAAS;QACZ,WAAM,GAAN,MAA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2
|
"name": "@rsdk/core",
|
|
3
|
-
"version": "4.0.1-next.
|
|
3
|
+
"version": "4.0.1-next.2",
|
|
4
4
|
"description": "Nestjs based microservice chassis",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@opentelemetry/api": "1.4.1",
|
|
18
|
+
"@opentelemetry/auto-instrumentations-node": "0.36.1",
|
|
18
19
|
"@opentelemetry/context-async-hooks": "1.13.0",
|
|
19
20
|
"@opentelemetry/core": "1.13.0",
|
|
20
21
|
"@opentelemetry/exporter-trace-otlp-http": "0.39.1",
|
|
@@ -31,18 +32,18 @@
|
|
|
31
32
|
"@nestjs/common": "^10.0.0",
|
|
32
33
|
"@nestjs/core": "^10.0.0",
|
|
33
34
|
"@nestjs/microservices": "^10.0.0",
|
|
34
|
-
"@rsdk/autodoc.protocol": "^4.0.1-next.
|
|
35
|
-
"@rsdk/common": "^4.0.1-next.
|
|
36
|
-
"@rsdk/common.nestjs": "^4.0.1-next.
|
|
37
|
-
"@rsdk/common.node": "^4.0.1-next.
|
|
38
|
-
"@rsdk/decorators": "^4.0.1-next.
|
|
39
|
-
"@rsdk/logging": "^4.0.1-next.
|
|
40
|
-
"@rsdk/metadata": "^4.0.1-next.
|
|
41
|
-
"@rsdk/nest-tools": "^4.0.1-next.
|
|
35
|
+
"@rsdk/autodoc.protocol": "^4.0.1-next.2",
|
|
36
|
+
"@rsdk/common": "^4.0.1-next.2",
|
|
37
|
+
"@rsdk/common.nestjs": "^4.0.1-next.2",
|
|
38
|
+
"@rsdk/common.node": "^4.0.1-next.2",
|
|
39
|
+
"@rsdk/decorators": "^4.0.1-next.2",
|
|
40
|
+
"@rsdk/logging": "^4.0.1-next.2",
|
|
41
|
+
"@rsdk/metadata": "^4.0.1-next.2",
|
|
42
|
+
"@rsdk/nest-tools": "^4.0.1-next.2",
|
|
42
43
|
"axios": "^1.1.3",
|
|
43
44
|
"pino": "^8.16.1",
|
|
44
45
|
"reflect-metadata": "^0.1.13",
|
|
45
46
|
"rxjs": "^7.0.0"
|
|
46
47
|
},
|
|
47
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "f48f893ffc6bccdfd5a0b703cc377a3a770581ff"
|
|
48
49
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
2
|
+
import { ClientRequest, IncomingMessage } from 'node:http';
|
|
3
|
+
|
|
4
|
+
import { RequestMetadataStorage } from './services/request-metadata.storage';
|
|
5
|
+
|
|
6
|
+
export const autoInstumentationOptions: any[] = getNodeAutoInstrumentations({
|
|
7
|
+
'@opentelemetry/instrumentation-aws-sdk': {
|
|
8
|
+
responseHook: (span, { response }) => {
|
|
9
|
+
if (response.request.commandInput?.Bucket) {
|
|
10
|
+
span.setAttribute(
|
|
11
|
+
's3.bucket.name',
|
|
12
|
+
response.request.commandInput?.Bucket,
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
'@opentelemetry/instrumentation-graphql': {
|
|
18
|
+
allowValues: true,
|
|
19
|
+
},
|
|
20
|
+
'@opentelemetry/instrumentation-http': {
|
|
21
|
+
requestHook: (span, request) => {
|
|
22
|
+
if (request instanceof IncomingMessage) {
|
|
23
|
+
if (request.method && request.url) {
|
|
24
|
+
span.updateName(`${request.method} ${request.url}`);
|
|
25
|
+
}
|
|
26
|
+
} else if (
|
|
27
|
+
request instanceof ClientRequest &&
|
|
28
|
+
request.req.method &&
|
|
29
|
+
request.req.url
|
|
30
|
+
) {
|
|
31
|
+
span.updateName(`${request.req.method} ${request.req.url}`);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
'@opentelemetry/instrumentation-pg': {
|
|
36
|
+
enhancedDatabaseReporting: true,
|
|
37
|
+
},
|
|
38
|
+
'@opentelemetry/instrumentation-pino': {
|
|
39
|
+
enabled: true,
|
|
40
|
+
logHook: (_span, record) => {
|
|
41
|
+
record['request_id'] =
|
|
42
|
+
RequestMetadataStorage.getInstance()?.getRequestMetadata().requestId;
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
@@ -35,7 +35,7 @@ export class RequestMetadataStorage {
|
|
|
35
35
|
/**
|
|
36
36
|
* Получает новое значение из контекста
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
getRequestMetadata(): RequestMetadata {
|
|
39
39
|
return (
|
|
40
40
|
RequestMetadataStorage.instance?.asyncLocalStorage.getStore()
|
|
41
41
|
?.requestMetadata ?? {
|
|
@@ -3,7 +3,9 @@ import { Module } from '@nestjs/common';
|
|
|
3
3
|
import { APP_INTERCEPTOR } from '@nestjs/core';
|
|
4
4
|
import { context, trace } from '@opentelemetry/api';
|
|
5
5
|
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
|
|
6
|
+
import { CompositePropagator } from '@opentelemetry/core';
|
|
6
7
|
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
8
|
+
import { B3InjectEncoding, B3Propagator } from '@opentelemetry/propagator-b3';
|
|
7
9
|
import { Resource } from '@opentelemetry/resources';
|
|
8
10
|
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
9
11
|
import type { SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
@@ -17,6 +19,7 @@ import { ILogger, LoggerFactory } from '@rsdk/logging';
|
|
|
17
19
|
import { InjectLogger } from '../logging';
|
|
18
20
|
|
|
19
21
|
import { ActiveSpanModule } from './active-span.module';
|
|
22
|
+
import { autoInstumentationOptions } from './auto-instrumentations.config';
|
|
20
23
|
import { RequestMetadataModule } from './request-metadata.module';
|
|
21
24
|
import { InstrumentationService } from './services';
|
|
22
25
|
import { TracingModuleConfig } from './tracing.config';
|
|
@@ -52,6 +55,34 @@ export class TracingModule {
|
|
|
52
55
|
};
|
|
53
56
|
}
|
|
54
57
|
|
|
58
|
+
// Можно добавить включение и выключение при изменении конфига.
|
|
59
|
+
async onModuleInit(): Promise<void> {
|
|
60
|
+
this.logger.debug('Injecting request-metadata storage...');
|
|
61
|
+
this.instrumentations.injectWrapRequestMetadataInjector();
|
|
62
|
+
|
|
63
|
+
if (!this.config.enabled) {
|
|
64
|
+
this.logger.info('Tracing is disabled');
|
|
65
|
+
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
this.logger.info('Tracing is enabled');
|
|
70
|
+
|
|
71
|
+
this.logger.debug('Starting Open Telemetry SDK...');
|
|
72
|
+
this.sdk.start();
|
|
73
|
+
|
|
74
|
+
this.logger.debug('Instrumenting nest.js entities...');
|
|
75
|
+
this.instrumentations.injectWrapTraceInjector();
|
|
76
|
+
|
|
77
|
+
this.logger.debug('Attaching log messages to spans...');
|
|
78
|
+
LoggerFactory.applyInstrumentations();
|
|
79
|
+
LoggerFactory.onMessage((level, msg) => {
|
|
80
|
+
const span = trace.getSpan(context.active());
|
|
81
|
+
|
|
82
|
+
span?.addEvent('log', { ...msg, level });
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
55
86
|
private static createSDKProvider(options: TracingModuleOptions): Provider {
|
|
56
87
|
return {
|
|
57
88
|
provide: NodeSDK,
|
|
@@ -72,42 +103,24 @@ export class TracingModule {
|
|
|
72
103
|
return new NodeSDK({
|
|
73
104
|
autoDetectResources: true,
|
|
74
105
|
contextManager: new AsyncLocalStorageContextManager(),
|
|
106
|
+
instrumentations: [autoInstumentationOptions],
|
|
75
107
|
resource: new Resource({
|
|
76
108
|
[SemanticResourceAttributes.SERVICE_NAME]: options.appName,
|
|
77
109
|
}),
|
|
78
110
|
spanProcessor: processor,
|
|
111
|
+
textMapPropagator: new CompositePropagator({
|
|
112
|
+
propagators: [
|
|
113
|
+
new B3Propagator(),
|
|
114
|
+
new B3Propagator({
|
|
115
|
+
injectEncoding: B3InjectEncoding.MULTI_HEADER,
|
|
116
|
+
}),
|
|
117
|
+
],
|
|
118
|
+
}),
|
|
79
119
|
});
|
|
80
120
|
},
|
|
81
121
|
};
|
|
82
122
|
}
|
|
83
123
|
|
|
84
|
-
// Можно добавить включение и выключение при изменении конфига.
|
|
85
|
-
async onModuleInit(): Promise<void> {
|
|
86
|
-
this.logger.debug('Injecting request-metadata storage...');
|
|
87
|
-
this.instrumentations.injectWrapRequestMetadataInjector();
|
|
88
|
-
|
|
89
|
-
if (!this.config.enabled) {
|
|
90
|
-
this.logger.info('Tracing is disabled');
|
|
91
|
-
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
this.logger.info('Tracing is enabled');
|
|
96
|
-
|
|
97
|
-
this.logger.debug('Starting Open Telemetry SDK...');
|
|
98
|
-
await this.sdk.start();
|
|
99
|
-
|
|
100
|
-
this.logger.debug('Instrumenting nest.js entities...');
|
|
101
|
-
this.instrumentations.injectWrapTraceInjector();
|
|
102
|
-
|
|
103
|
-
this.logger.debug('Attaching log messages to spans...');
|
|
104
|
-
LoggerFactory.onMessage((level, msg) => {
|
|
105
|
-
const span = trace.getSpan(context.active());
|
|
106
|
-
|
|
107
|
-
span?.addEvent('log', { ...msg, level });
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
124
|
async beforeApplicationShutdown(): Promise<void> {
|
|
112
125
|
this.logger.info('Shutting down Open Telemetry SDK...');
|
|
113
126
|
await this.sdk.shutdown();
|