@rsdk/core 5.0.0-next.2 → 5.0.0-next.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 +10 -0
- package/dist/config/metadata/decorators/inject-property.decorator.d.ts +1 -1
- package/dist/config/metadata/decorators/property.decorator.d.ts +1 -1
- package/dist/config/parsers/url/exception.d.ts +0 -1
- package/dist/config/parsers/url/url.parser.d.ts +0 -1
- package/dist/config/reload/config-reload.events.d.ts +0 -1
- package/dist/exceptions.handling/global-exceptions.filter.d.ts +1 -1
- package/dist/exceptions.handling/global-exceptions.filter.js +2 -5
- package/dist/exceptions.handling/global-exceptions.filter.js.map +1 -1
- package/dist/health/indicators.abstract/ping.indicator.d.ts +0 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/dist/logging/logger-initializing.module.d.ts +1 -1
- package/dist/logging/logger-initializing.module.js +1 -1
- package/dist/logging/logger-initializing.module.js.map +1 -1
- package/dist/metrics/metadata/decorators/metric.decorator.js +1 -2
- package/dist/metrics/metadata/decorators/metric.decorator.js.map +1 -1
- package/dist/metrics/metric-initializing.module.d.ts +1 -1
- package/dist/metrics/metric-initializing.module.js +1 -1
- package/dist/metrics/metric-initializing.module.js.map +1 -1
- package/dist/platform.context.d.ts +5 -5
- package/dist/platform.context.js +28 -24
- package/dist/platform.context.js.map +1 -1
- package/dist/platform.module.d.ts +1 -1
- package/dist/platform.module.js +10 -9
- package/dist/platform.module.js.map +1 -1
- package/dist/tracing/constants.d.ts +12 -9
- package/dist/tracing/constants.js +13 -11
- package/dist/tracing/constants.js.map +1 -1
- package/dist/tracing/index.d.ts +3 -3
- package/dist/tracing/index.js +3 -3
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/opentelemetry/decorators/index.js.map +1 -0
- package/dist/tracing/{decorators → opentelemetry/decorators}/no-span.decorator.d.ts +1 -1
- package/dist/tracing/{decorators → opentelemetry/decorators}/no-span.decorator.js +3 -3
- package/dist/tracing/opentelemetry/decorators/no-span.decorator.js.map +1 -0
- package/dist/tracing/{decorators → opentelemetry/decorators}/span.decorator.js +5 -4
- package/dist/tracing/opentelemetry/decorators/span.decorator.js.map +1 -0
- package/dist/tracing/opentelemetry/index.d.ts +1 -0
- package/dist/tracing/{services → opentelemetry}/index.js +1 -1
- package/dist/tracing/opentelemetry/index.js.map +1 -0
- package/dist/tracing/opentelemetry/opentelemetry.helpers.d.ts +28 -0
- package/dist/tracing/opentelemetry/opentelemetry.helpers.js +77 -0
- package/dist/tracing/opentelemetry/opentelemetry.helpers.js.map +1 -0
- package/dist/tracing/opentelemetry/opentelemetry.metadata.d.ts +7 -0
- package/dist/tracing/opentelemetry/opentelemetry.metadata.js +27 -0
- package/dist/tracing/opentelemetry/opentelemetry.metadata.js.map +1 -0
- package/dist/tracing/opentelemetry/opentelemetry.wrapper.d.ts +6 -0
- package/dist/tracing/opentelemetry/opentelemetry.wrapper.js +71 -0
- package/dist/tracing/opentelemetry/opentelemetry.wrapper.js.map +1 -0
- package/dist/tracing/tracing.actx.d.ts +1 -0
- package/dist/tracing/tracing.actx.js +9 -0
- package/dist/tracing/tracing.actx.js.map +1 -0
- package/dist/tracing/tracing.interceptor.d.ts +20 -4
- package/dist/tracing/tracing.interceptor.js +59 -9
- package/dist/tracing/tracing.interceptor.js.map +1 -1
- package/dist/tracing/tracing.module.d.ts +10 -4
- package/dist/tracing/tracing.module.js +63 -21
- package/dist/tracing/tracing.module.js.map +1 -1
- package/dist/tracing/types.d.ts +9 -11
- package/dist/tracing/types.js +0 -20
- package/dist/tracing/types.js.map +1 -1
- package/dist/transport/protocol.detector.d.ts +13 -1
- package/dist/transport/protocol.detector.js +17 -24
- package/dist/transport/protocol.detector.js.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +1 -4
- package/dist/types/index.js.map +1 -1
- package/dist/types/options.d.ts +2 -0
- package/dist/types/plugins.d.ts +8 -3
- package/dist/types/plugins.js.map +1 -1
- package/dist/types/transports.d.ts +19 -9
- package/dist/types/transports.js +3 -1
- package/dist/types/transports.js.map +1 -1
- package/package.json +9 -4
- package/src/exceptions.handling/global-exceptions.filter.ts +5 -6
- package/src/index.ts +3 -3
- package/src/logging/logger-initializing.module.ts +2 -2
- package/src/metrics/metric-initializing.module.ts +2 -2
- package/src/platform.context.ts +41 -32
- package/src/platform.module.ts +9 -8
- package/src/tracing/constants.ts +15 -9
- package/src/tracing/index.ts +3 -3
- package/src/tracing/opentelemetry/decorators/no-span.decorator.ts +10 -0
- package/src/tracing/{decorators → opentelemetry/decorators}/span.decorator.ts +8 -4
- package/src/tracing/opentelemetry/index.ts +1 -0
- package/src/tracing/opentelemetry/opentelemetry.helpers.ts +89 -0
- package/src/tracing/opentelemetry/opentelemetry.metadata.ts +24 -0
- package/src/tracing/opentelemetry/opentelemetry.wrapper.ts +90 -0
- package/src/tracing/tracing.actx.ts +8 -0
- package/src/tracing/tracing.interceptor.ts +65 -8
- package/src/tracing/tracing.module.ts +64 -23
- package/src/tracing/types.ts +9 -28
- package/src/transport/protocol.detector.ts +19 -25
- package/src/types/index.ts +0 -2
- package/src/types/options.ts +3 -0
- package/src/types/plugins.ts +9 -2
- package/src/types/transports.ts +27 -11
- package/dist/tracing/decorators/index.js.map +0 -1
- package/dist/tracing/decorators/no-span.decorator.js.map +0 -1
- package/dist/tracing/decorators/span.decorator.js.map +0 -1
- package/dist/tracing/request-metadata.module.d.ts +0 -5
- package/dist/tracing/request-metadata.module.js +0 -21
- package/dist/tracing/request-metadata.module.js.map +0 -1
- package/dist/tracing/services/index.d.ts +0 -1
- package/dist/tracing/services/index.js.map +0 -1
- package/dist/tracing/services/trace.injector.d.ts +0 -12
- package/dist/tracing/services/trace.injector.js +0 -154
- package/dist/tracing/services/trace.injector.js.map +0 -1
- package/dist/tracing/tracing.config.d.ts +0 -6
- package/dist/tracing/tracing.config.js +0 -39
- package/dist/tracing/tracing.config.js.map +0 -1
- package/dist/tracing/utils/create-span.d.ts +0 -10
- package/dist/tracing/utils/create-span.js +0 -20
- package/dist/tracing/utils/create-span.js.map +0 -1
- package/dist/transport/get-transport-id.d.ts +0 -5
- package/dist/transport/get-transport-id.js +0 -14
- package/dist/transport/get-transport-id.js.map +0 -1
- package/dist/types/tracing.headers-extractor.d.ts +0 -15
- package/dist/types/tracing.headers-extractor.js +0 -67
- package/dist/types/tracing.headers-extractor.js.map +0 -1
- package/src/tracing/decorators/no-span.decorator.ts +0 -10
- package/src/tracing/request-metadata.module.ts +0 -8
- package/src/tracing/services/index.ts +0 -1
- package/src/tracing/services/trace.injector.ts +0 -190
- package/src/tracing/tracing.config.ts +0 -25
- package/src/tracing/utils/create-span.ts +0 -20
- package/src/transport/get-transport-id.ts +0 -20
- package/src/types/tracing.headers-extractor.ts +0 -51
- /package/dist/tracing/{decorators → opentelemetry/decorators}/index.d.ts +0 -0
- /package/dist/tracing/{decorators → opentelemetry/decorators}/index.js +0 -0
- /package/dist/tracing/{decorators → opentelemetry/decorators}/span.decorator.d.ts +0 -0
- /package/src/tracing/{decorators → opentelemetry/decorators}/index.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span.decorator.js","sourceRoot":"","sources":["../../../../src/tracing/opentelemetry/decorators/span.decorator.ts"],"names":[],"mappings":";;;AAAA,uCAA+C;AAE/C,oDAAmE;AACnE,oEAAgE;AAEhE,MAAM,eAAe,GAAG,IAAI,sBAAe,EAAE,CAAC;AAE9C,MAAM,OAAO,GAAG,IAAI,4CAAoB,EAAE,CAAC;AAE3C;;;;GAIG;AACI,MAAM,IAAI,GAAG,GAAqC,EAAE;AACzD,+DAA+D;AAC/D,UACE,MAAc,EACd,UAA4B,EAC5B,UAAyC;IAEzC,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,IAAI,yCAA4B,EAAE,CAAC;IAC3C,CAAC;IAED,IAAI,UAAU,IAAI,UAAU,EAAE,CAAC;QAC7B,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QACnD,OAAO;IACT,CAAC;IAED,MAAM,SAAS,GAAI,MAAc,CAAC,SAAS,IAAI,MAAM,CAAC;IAEtD,KAAK,MAAM,IAAI,IAAI,eAAe,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,CAAC;QAChE,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAvBS,QAAA,IAAI,QAuBb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './decorators';
|
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./decorators"), exports);
|
|
18
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tracing/opentelemetry/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AttributeValue, Span } from '@opentelemetry/api';
|
|
2
|
+
import { Size } from '@rsdk/common';
|
|
3
|
+
import { type Observable } from 'rxjs';
|
|
4
|
+
/**
|
|
5
|
+
* Maximum span attribute size
|
|
6
|
+
*/
|
|
7
|
+
export declare const MAX_ATTRIBUTE_SIZE: Size;
|
|
8
|
+
/**
|
|
9
|
+
* Makes correct opentelemetry span attribute from any value
|
|
10
|
+
* @param data unknown value of any type
|
|
11
|
+
* @returns AttributeValue
|
|
12
|
+
*/
|
|
13
|
+
export declare const toAttribute: (data: unknown) => AttributeValue;
|
|
14
|
+
/**
|
|
15
|
+
* Adds data to span with key "result" and ends it.
|
|
16
|
+
* @param span Span
|
|
17
|
+
* @param data Any piece of data
|
|
18
|
+
*/
|
|
19
|
+
export declare const endWithResult: (span: Span, data: unknown) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Adds error object to span and ends it
|
|
22
|
+
* @param span Span
|
|
23
|
+
* @param error Error
|
|
24
|
+
*/
|
|
25
|
+
export declare const endWithError: (span: Span, error: Error) => void;
|
|
26
|
+
export declare const processSyncResult: <T = unknown>(result: T, span: Span) => T;
|
|
27
|
+
export declare const processObservableResult: <T = unknown>(result: Observable<T>, span: Span) => Observable<T>;
|
|
28
|
+
export declare const processPromiseResult: <T = unknown>(result: Promise<T>, span: Span) => Promise<T>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processPromiseResult = exports.processObservableResult = exports.processSyncResult = exports.endWithError = exports.endWithResult = exports.toAttribute = exports.MAX_ATTRIBUTE_SIZE = void 0;
|
|
4
|
+
const api_1 = require("@opentelemetry/api");
|
|
5
|
+
const common_1 = require("@rsdk/common");
|
|
6
|
+
const rxjs_1 = require("rxjs");
|
|
7
|
+
/**
|
|
8
|
+
* Maximum span attribute size
|
|
9
|
+
*/
|
|
10
|
+
exports.MAX_ATTRIBUTE_SIZE = new common_1.Size(100, 'kb');
|
|
11
|
+
/**
|
|
12
|
+
* Makes correct opentelemetry span attribute from any value
|
|
13
|
+
* @param data unknown value of any type
|
|
14
|
+
* @returns AttributeValue
|
|
15
|
+
*/
|
|
16
|
+
const toAttribute = (data) => {
|
|
17
|
+
if ((0, common_1.isPrimitive)(data)) {
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
if ((0, common_1.isRecord)(data) || Array.isArray(data)) {
|
|
21
|
+
const serialized = JSON.stringify((0, common_1.normalizer)()(data));
|
|
22
|
+
return serialized.length <= exports.MAX_ATTRIBUTE_SIZE.bytes()
|
|
23
|
+
? serialized
|
|
24
|
+
: `data exceeds limit of ${exports.MAX_ATTRIBUTE_SIZE.bytes()} bytes`;
|
|
25
|
+
}
|
|
26
|
+
return 'data is undefined';
|
|
27
|
+
};
|
|
28
|
+
exports.toAttribute = toAttribute;
|
|
29
|
+
/**
|
|
30
|
+
* Adds data to span with key "result" and ends it.
|
|
31
|
+
* @param span Span
|
|
32
|
+
* @param data Any piece of data
|
|
33
|
+
*/
|
|
34
|
+
const endWithResult = (span, data) => {
|
|
35
|
+
span.setAttribute('result', (0, exports.toAttribute)(data));
|
|
36
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
37
|
+
span.end();
|
|
38
|
+
};
|
|
39
|
+
exports.endWithResult = endWithResult;
|
|
40
|
+
/**
|
|
41
|
+
* Adds error object to span and ends it
|
|
42
|
+
* @param span Span
|
|
43
|
+
* @param error Error
|
|
44
|
+
*/
|
|
45
|
+
const endWithError = (span, error) => {
|
|
46
|
+
span.recordException(error);
|
|
47
|
+
span.setStatus({
|
|
48
|
+
code: api_1.SpanStatusCode.ERROR,
|
|
49
|
+
message: error.message,
|
|
50
|
+
});
|
|
51
|
+
span.end();
|
|
52
|
+
};
|
|
53
|
+
exports.endWithError = endWithError;
|
|
54
|
+
const processSyncResult = (result, span) => {
|
|
55
|
+
(0, exports.endWithResult)(span, result);
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
exports.processSyncResult = processSyncResult;
|
|
59
|
+
const processObservableResult = (result, span) => result.pipe((0, rxjs_1.mergeMap)((result) => {
|
|
60
|
+
(0, exports.endWithResult)(span, result);
|
|
61
|
+
return (0, rxjs_1.of)(result);
|
|
62
|
+
}), (0, rxjs_1.catchError)((error) => {
|
|
63
|
+
(0, exports.endWithError)(span, error);
|
|
64
|
+
return (0, rxjs_1.throwError)(() => error);
|
|
65
|
+
}));
|
|
66
|
+
exports.processObservableResult = processObservableResult;
|
|
67
|
+
const processPromiseResult = (result, span) => result
|
|
68
|
+
.then((result) => {
|
|
69
|
+
(0, exports.endWithResult)(span, result);
|
|
70
|
+
return result;
|
|
71
|
+
})
|
|
72
|
+
.catch((error) => {
|
|
73
|
+
(0, exports.endWithError)(span, error);
|
|
74
|
+
throw error;
|
|
75
|
+
});
|
|
76
|
+
exports.processPromiseResult = processPromiseResult;
|
|
77
|
+
//# sourceMappingURL=opentelemetry.helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentelemetry.helpers.js","sourceRoot":"","sources":["../../../src/tracing/opentelemetry/opentelemetry.helpers.ts"],"names":[],"mappings":";;;AACA,4CAAoD;AACpD,yCAAuE;AACvE,+BAA6E;AAE7E;;GAEG;AACU,QAAA,kBAAkB,GAAG,IAAI,aAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAEtD;;;;GAIG;AACI,MAAM,WAAW,GAAG,CAAC,IAAa,EAAkB,EAAE;IAC3D,IAAI,IAAA,oBAAW,EAAC,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,IAAA,iBAAQ,EAAC,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1C,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAA,mBAAU,GAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QAEtD,OAAO,UAAU,CAAC,MAAM,IAAI,0BAAkB,CAAC,KAAK,EAAE;YACpD,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,yBAAyB,0BAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC;IAClE,CAAC;IAED,OAAO,mBAAmB,CAAC;AAC7B,CAAC,CAAC;AAdW,QAAA,WAAW,eActB;AAEF;;;;GAIG;AACI,MAAM,aAAa,GAAG,CAAC,IAAU,EAAE,IAAa,EAAQ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CAAC;AAbS,QAAA,uBAAuB,2BAahC;AAEG,MAAM,oBAAoB,GAAG,CAClC,MAAkB,EAClB,IAAU,EACE,EAAE,CACd,MAAM;KACH,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;IACf,IAAA,qBAAa,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;KACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACf,IAAA,oBAAY,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1B,MAAM,KAAK,CAAC;AACd,CAAC,CAAC,CAAC;AAZM,QAAA,oBAAoB,wBAY1B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const OTEL_METADATA: {
|
|
2
|
+
NO_SPAN: string;
|
|
3
|
+
IS_WRAPPED: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const isNoSpan: (prototype: object) => boolean;
|
|
6
|
+
export declare const isWrapped: (prototype: object) => boolean;
|
|
7
|
+
export declare const setWrapped: (prototype: object) => void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setWrapped = exports.isWrapped = exports.isNoSpan = exports.OTEL_METADATA = void 0;
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
exports.OTEL_METADATA = {
|
|
9
|
+
NO_SPAN: 'NO_SPAN_METADATA',
|
|
10
|
+
IS_WRAPPED: 'OPEN_TELEMETRY_TRACE_METADATA_ACTIVE',
|
|
11
|
+
};
|
|
12
|
+
const isNoSpan = (prototype) => {
|
|
13
|
+
node_assert_1.default.ok(prototype);
|
|
14
|
+
return Reflect.hasMetadata(exports.OTEL_METADATA.NO_SPAN, prototype);
|
|
15
|
+
};
|
|
16
|
+
exports.isNoSpan = isNoSpan;
|
|
17
|
+
const isWrapped = (prototype) => {
|
|
18
|
+
node_assert_1.default.ok(prototype);
|
|
19
|
+
return Reflect.hasMetadata(exports.OTEL_METADATA.IS_WRAPPED, prototype);
|
|
20
|
+
};
|
|
21
|
+
exports.isWrapped = isWrapped;
|
|
22
|
+
const setWrapped = (prototype) => {
|
|
23
|
+
node_assert_1.default.ok(prototype);
|
|
24
|
+
Reflect.defineMetadata(exports.OTEL_METADATA.IS_WRAPPED, true, prototype);
|
|
25
|
+
};
|
|
26
|
+
exports.setWrapped = setWrapped;
|
|
27
|
+
//# sourceMappingURL=opentelemetry.metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentelemetry.metadata.js","sourceRoot":"","sources":["../../../src/tracing/opentelemetry/opentelemetry.metadata.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAiC;AAEpB,QAAA,aAAa,GAAG;IAC3B,OAAO,EAAE,kBAAkB;IAC3B,UAAU,EAAE,sCAAsC;CACnD,CAAC;AAEK,MAAM,QAAQ,GAAG,CAAC,SAAiB,EAAW,EAAE;IACrD,qBAAM,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;IAErB,OAAO,OAAO,CAAC,WAAW,CAAC,qBAAa,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AAC/D,CAAC,CAAC;AAJW,QAAA,QAAQ,YAInB;AAEK,MAAM,SAAS,GAAG,CAAC,SAAiB,EAAW,EAAE;IACtD,qBAAM,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;IAErB,OAAO,OAAO,CAAC,WAAW,CAAC,qBAAa,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAClE,CAAC,CAAC;AAJW,QAAA,SAAS,aAIpB;AAEK,MAAM,UAAU,GAAG,CAAC,SAAiB,EAAQ,EAAE;IACpD,qBAAM,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;IAErB,OAAO,CAAC,cAAc,CAAC,qBAAa,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;AACpE,CAAC,CAAC;AAJW,QAAA,UAAU,cAIrB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpentelemetryWrapper = void 0;
|
|
4
|
+
const common_1 = require("@rsdk/common");
|
|
5
|
+
const decorators_1 = require("@rsdk/decorators");
|
|
6
|
+
const logging_1 = require("@rsdk/logging");
|
|
7
|
+
const rxjs_1 = require("rxjs");
|
|
8
|
+
const opentelemetry_helpers_1 = require("./opentelemetry.helpers");
|
|
9
|
+
const opentelemetry_metadata_1 = require("./opentelemetry.metadata");
|
|
10
|
+
class OpentelemetryWrapper {
|
|
11
|
+
logger = logging_1.LoggerFactory.create(OpentelemetryWrapper);
|
|
12
|
+
trace;
|
|
13
|
+
constructor() {
|
|
14
|
+
try {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
16
|
+
const { trace } = require('@opentelemetry/api');
|
|
17
|
+
this.trace = trace;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
this.trace = null;
|
|
21
|
+
this.logger.debug((0, common_1.text) `
|
|
22
|
+
@opentelemetry/api is not installed.
|
|
23
|
+
@Span() decorator will not make any effect.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
wrap(cls,
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
28
|
+
original, descriptor) {
|
|
29
|
+
if (!this.trace || (0, opentelemetry_metadata_1.isWrapped)(original) || (0, opentelemetry_metadata_1.isNoSpan)(original)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const spanName = `${cls.constructor.name} -> ${original.name}`;
|
|
33
|
+
this.logger.debug(`Wrapping method: ${spanName}`);
|
|
34
|
+
const tracer = this.trace.getTracer(`rsdk:${cls.constructor.name}`);
|
|
35
|
+
const wrapped = {
|
|
36
|
+
[original.name](...args) {
|
|
37
|
+
return tracer.startActiveSpan(spanName, (span) => {
|
|
38
|
+
span.setAttribute('args', (0, opentelemetry_helpers_1.toAttribute)(args));
|
|
39
|
+
try {
|
|
40
|
+
const result = original.apply(this, args);
|
|
41
|
+
if (result instanceof Promise) {
|
|
42
|
+
return (0, opentelemetry_helpers_1.processPromiseResult)(result, span);
|
|
43
|
+
}
|
|
44
|
+
if (result instanceof rxjs_1.Observable) {
|
|
45
|
+
return (0, opentelemetry_helpers_1.processObservableResult)(result, span);
|
|
46
|
+
}
|
|
47
|
+
return (0, opentelemetry_helpers_1.processSyncResult)(result, span);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
common_1.Assert.isError(error);
|
|
51
|
+
(0, opentelemetry_helpers_1.endWithError)(span, error);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
}[original.name];
|
|
57
|
+
(0, decorators_1.redecorate)(original, wrapped);
|
|
58
|
+
if (descriptor) {
|
|
59
|
+
descriptor.value = wrapped;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
cls[original.name] = wrapped;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Отмечает метод, как обёрнутый (чтобы избежать повторного оборачивания)
|
|
66
|
+
*/
|
|
67
|
+
(0, opentelemetry_metadata_1.setWrapped)(wrapped);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.OpentelemetryWrapper = OpentelemetryWrapper;
|
|
71
|
+
//# sourceMappingURL=opentelemetry.wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentelemetry.wrapper.js","sourceRoot":"","sources":["../../../src/tracing/opentelemetry/opentelemetry.wrapper.ts"],"names":[],"mappings":";;;AACA,yCAA4C;AAC5C,iDAA8C;AAE9C,2CAA8C;AAC9C,+BAAkC;AAElC,mEAMiC;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G,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;wBAE1C,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;4BAC9B,OAAO,IAAA,4CAAoB,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;wBAC5C,CAAC;wBAED,IAAI,MAAM,YAAY,iBAAU,EAAE,CAAC;4BACjC,OAAO,IAAA,+CAAuB,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;wBAC/C,CAAC;wBAED,OAAO,IAAA,yCAAiB,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;oBACzC,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,eAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;wBACtB,IAAA,oCAAY,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC;wBAC1B,MAAM,KAAK,CAAC;oBACd,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEjB,IAAA,uBAAU,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAE9B,IAAI,UAAU,EAAE,CAAC;YACf,UAAU,CAAC,KAAK,GAAG,OAAO,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;QAC/B,CAAC;QAED;;WAEG;QACH,IAAA,mCAAU,EAAC,OAAO,CAAC,CAAC;IACtB,CAAC;CACF;AAzED,oDAyEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TracingHeaders: import("@rsdk/actx").AsyncContextProvider<Record<string, string>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TracingHeaders = void 0;
|
|
4
|
+
const actx_1 = require("@rsdk/actx");
|
|
5
|
+
exports.TracingHeaders = (0, actx_1.createAsyncContextProvider)({
|
|
6
|
+
name: 'TracingHeaders',
|
|
7
|
+
rewritable: false,
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=tracing.actx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracing.actx.js","sourceRoot":"","sources":["../../src/tracing/tracing.actx.ts"],"names":[],"mappings":";;;AAAA,qCAAwD;AAE3C,QAAA,cAAc,GAAG,IAAA,iCAA0B,EAEtD;IACA,IAAI,EAAE,gBAAgB;IACtB,UAAU,EAAE,KAAK;CAClB,CAAC,CAAC"}
|
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import type { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
2
|
import type { Observable } from 'rxjs';
|
|
3
|
-
import {
|
|
3
|
+
import { ILogger } from '../logging';
|
|
4
|
+
import { ProtocolDetector } from '../transport/protocol.detector';
|
|
5
|
+
import type { ITransport, PlatformAppPlugin } from '../types';
|
|
6
|
+
import type { TracingHeaderMappings } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Extracts headers that should be passed to all logging messages
|
|
9
|
+
* and external calls
|
|
10
|
+
*/
|
|
4
11
|
export declare class TracingInterceptor implements NestInterceptor {
|
|
5
|
-
private
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
private logger;
|
|
13
|
+
private transports;
|
|
14
|
+
private plugins;
|
|
15
|
+
private mappings;
|
|
16
|
+
private detector;
|
|
17
|
+
/**
|
|
18
|
+
* Extractors can be either transports or additional strategies
|
|
19
|
+
* supplied by plugins
|
|
20
|
+
*/
|
|
21
|
+
private readonly extractors;
|
|
22
|
+
constructor(logger: ILogger, transports: Set<ITransport>, plugins: Set<PlatformAppPlugin>, mappings: TracingHeaderMappings[], detector: ProtocolDetector);
|
|
23
|
+
intercept(ctx: ExecutionContext, next: CallHandler): Observable<any>;
|
|
8
24
|
}
|
|
@@ -8,26 +8,76 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.TracingInterceptor = void 0;
|
|
13
16
|
const common_1 = require("@nestjs/common");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
17
|
+
const exceptions_1 = require("../exceptions");
|
|
18
|
+
const logging_1 = require("../logging");
|
|
19
|
+
const protocol_detector_1 = require("../transport/protocol.detector");
|
|
20
|
+
const types_1 = require("../types");
|
|
16
21
|
const constants_1 = require("./constants");
|
|
22
|
+
const tracing_actx_1 = require("./tracing.actx");
|
|
23
|
+
/**
|
|
24
|
+
* Extracts headers that should be passed to all logging messages
|
|
25
|
+
* and external calls
|
|
26
|
+
*/
|
|
17
27
|
let TracingInterceptor = class TracingInterceptor {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
logger;
|
|
29
|
+
transports;
|
|
30
|
+
plugins;
|
|
31
|
+
mappings;
|
|
32
|
+
detector;
|
|
33
|
+
/**
|
|
34
|
+
* Extractors can be either transports or additional strategies
|
|
35
|
+
* supplied by plugins
|
|
36
|
+
*/
|
|
37
|
+
extractors = new Map();
|
|
38
|
+
constructor(logger, transports, plugins, mappings, detector) {
|
|
39
|
+
this.logger = logger;
|
|
40
|
+
this.transports = transports;
|
|
41
|
+
this.plugins = plugins;
|
|
42
|
+
this.mappings = mappings;
|
|
43
|
+
this.detector = detector;
|
|
44
|
+
for (const transport of this.transports) {
|
|
45
|
+
this.extractors.set(transport.getProtocol(), transport);
|
|
46
|
+
}
|
|
47
|
+
for (const plugin of this.plugins) {
|
|
48
|
+
for (const x of plugin.tracingHeadersExtractors?.() ?? []) {
|
|
49
|
+
this.extractors.set(x.protocol, x.extractor);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
21
52
|
}
|
|
22
|
-
intercept(
|
|
23
|
-
const
|
|
24
|
-
|
|
53
|
+
intercept(ctx, next) {
|
|
54
|
+
const protocol = this.detector.getProtocol(ctx) ?? ctx.getType();
|
|
55
|
+
const extractor = this.extractors.get(protocol);
|
|
56
|
+
if (!extractor) {
|
|
57
|
+
throw new exceptions_1.InternalException(`No headers extractor for protocol: ${protocol}`);
|
|
58
|
+
}
|
|
59
|
+
const headers = {};
|
|
60
|
+
for (const aliases of this.mappings) {
|
|
61
|
+
const key = aliases[0];
|
|
62
|
+
const value = aliases
|
|
63
|
+
.map((x) => extractor.extractHeaders(ctx).get(x))
|
|
64
|
+
.filter((x) => x)
|
|
65
|
+
.at(0);
|
|
66
|
+
headers[key] = value || '[missing]';
|
|
67
|
+
}
|
|
68
|
+
this.logger.trace('Extracted traceable headers', { headers });
|
|
69
|
+
tracing_actx_1.TracingHeaders.set(headers);
|
|
25
70
|
return next.handle();
|
|
26
71
|
}
|
|
27
72
|
};
|
|
28
73
|
exports.TracingInterceptor = TracingInterceptor;
|
|
29
74
|
exports.TracingInterceptor = TracingInterceptor = __decorate([
|
|
30
75
|
(0, common_1.Injectable)(),
|
|
31
|
-
|
|
76
|
+
__param(0, (0, logging_1.InjectLogger)(TracingInterceptor)),
|
|
77
|
+
__param(1, (0, common_1.Inject)(types_1.APP_TRANSPORTS)),
|
|
78
|
+
__param(2, (0, common_1.Inject)(types_1.APP_PLUGINS)),
|
|
79
|
+
__param(3, (0, common_1.Inject)(constants_1.HEADER_MAPPINGS)),
|
|
80
|
+
__metadata("design:paramtypes", [Object, Set,
|
|
81
|
+
Set, Array, protocol_detector_1.ProtocolDetector])
|
|
32
82
|
], TracingInterceptor);
|
|
33
83
|
//# sourceMappingURL=tracing.interceptor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.interceptor.js","sourceRoot":"","sources":["../../src/tracing/tracing.interceptor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tracing.interceptor.js","sourceRoot":"","sources":["../../src/tracing/tracing.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,2CAAoD;AAGpD,8CAAkD;AAClD,wCAAmD;AACnD,sEAAkE;AAMlE,oCAAuD;AAEvD,2CAA8C;AAC9C,iDAAgD;AAGhD;;;GAGG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAQe;IACV;IACH;IACI;IACzB;IAXV;;;OAGG;IACc,UAAU,GAAG,IAAI,GAAG,EAA8B,CAAC;IAEpE,YAC4C,MAAe,EACzB,UAA2B,EAC9B,OAA+B,EAC3B,QAAiC,EAC1D,QAA0B;QAJQ,WAAM,GAAN,MAAM,CAAS;QACzB,eAAU,GAAV,UAAU,CAAiB;QAC9B,YAAO,GAAP,OAAO,CAAwB;QAC3B,aAAQ,GAAR,QAAQ,CAAyB;QAC1D,aAAQ,GAAR,QAAQ,CAAkB;QAElC,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACxC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,SAAS,CAAC,CAAC;QAC1D,CAAC;QAED,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,wBAAwB,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC;gBAC1D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;IACH,CAAC;IAED,SAAS,CAAC,GAAqB,EAAE,IAAiB;QAChD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;QAEjE,MAAM,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nModuleInit } from '@nestjs/common';
|
|
2
2
|
import { ILogger } from '@rsdk/logging';
|
|
3
|
-
import {
|
|
3
|
+
import type { PlatformOptions } from '../types';
|
|
4
|
+
import type { TracingHeaderMappings } from './types';
|
|
5
|
+
export interface TracingOptions {
|
|
6
|
+
includeDefault: boolean;
|
|
7
|
+
additionalMappings?: TracingHeaderMappings[];
|
|
8
|
+
}
|
|
4
9
|
export declare class TracingModule implements OnModuleInit {
|
|
5
10
|
private readonly logger;
|
|
6
|
-
private
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
private trace;
|
|
12
|
+
private context;
|
|
13
|
+
constructor(logger: ILogger);
|
|
14
|
+
static forRoot({ tracing, plugins, }: PlatformOptions): DynamicModule;
|
|
9
15
|
onModuleInit(): Promise<void>;
|
|
10
16
|
}
|
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
2
18
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
19
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
20
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
21
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
22
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
23
|
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
8
31
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
32
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
33
|
};
|
|
@@ -16,48 +39,67 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
39
|
exports.TracingModule = void 0;
|
|
17
40
|
const common_1 = require("@nestjs/common");
|
|
18
41
|
const core_1 = require("@nestjs/core");
|
|
19
|
-
const
|
|
42
|
+
const common_2 = require("@rsdk/common");
|
|
20
43
|
const logging_1 = require("@rsdk/logging");
|
|
21
|
-
const tracing_1 = require("@rsdk/tracing");
|
|
22
44
|
const logging_2 = require("../logging");
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const tracing_config_1 = require("./tracing.config");
|
|
45
|
+
const constants_1 = require("./constants");
|
|
46
|
+
const tracing_actx_1 = require("./tracing.actx");
|
|
26
47
|
const tracing_interceptor_1 = require("./tracing.interceptor");
|
|
27
48
|
let TracingModule = TracingModule_1 = class TracingModule {
|
|
28
49
|
logger;
|
|
29
|
-
|
|
30
|
-
|
|
50
|
+
trace = null;
|
|
51
|
+
context = null;
|
|
52
|
+
constructor(logger) {
|
|
31
53
|
this.logger = logger;
|
|
32
|
-
this.config = config;
|
|
33
54
|
}
|
|
34
|
-
static forRoot() {
|
|
55
|
+
static forRoot({ tracing = constants_1.DEFAULT_TRACING_OPTIONS, plugins = [], }) {
|
|
56
|
+
const mappings = [];
|
|
57
|
+
if (tracing?.includeDefault) {
|
|
58
|
+
mappings.push(...constants_1.DEFAULT_TRACING_HEADERS);
|
|
59
|
+
}
|
|
60
|
+
for (const plugin of plugins) {
|
|
61
|
+
mappings.push(...(plugin.additionalTracingHeaders?.() ?? []));
|
|
62
|
+
}
|
|
63
|
+
mappings.push(...(tracing.additionalMappings ?? []));
|
|
35
64
|
return {
|
|
65
|
+
global: true,
|
|
36
66
|
module: TracingModule_1,
|
|
37
|
-
imports: [request_metadata_module_1.RequestMetadataModule],
|
|
38
67
|
providers: [
|
|
39
68
|
{ provide: core_1.APP_INTERCEPTOR, useClass: tracing_interceptor_1.TracingInterceptor },
|
|
40
|
-
|
|
69
|
+
{ provide: constants_1.HEADER_MAPPINGS, useValue: mappings },
|
|
41
70
|
],
|
|
42
71
|
};
|
|
43
72
|
}
|
|
44
73
|
// Можно добавить включение и выключение при изменении конфига.
|
|
45
74
|
async onModuleInit() {
|
|
75
|
+
if (!this.context || !this.trace) {
|
|
76
|
+
try {
|
|
77
|
+
const { context, trace } = await Promise.resolve().then(() => __importStar(require('@opentelemetry/api')));
|
|
78
|
+
this.context = context;
|
|
79
|
+
this.trace = trace;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
this.logger.debug((0, common_2.text) `
|
|
83
|
+
@opentelemetry/api is not installed. Opentelemetry metadata will
|
|
84
|
+
not appear in log messages.
|
|
85
|
+
`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
46
88
|
logging_1.LoggerFactory.applyInstrumentations((record) => {
|
|
47
|
-
record
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
89
|
+
Object.assign(record, tracing_actx_1.TracingHeaders.get() || {});
|
|
90
|
+
if (this.trace && this.context) {
|
|
91
|
+
const { traceId, spanId } = this.trace.getSpan(this.context.active())?.spanContext() ?? {};
|
|
92
|
+
record['trace_id'] = traceId;
|
|
93
|
+
record['span_id'] = spanId;
|
|
51
94
|
}
|
|
52
|
-
const spanContext = span.spanContext();
|
|
53
|
-
record['trace_id'] = spanContext.traceId;
|
|
54
|
-
record['span_id'] = spanContext.spanId;
|
|
55
95
|
});
|
|
56
96
|
this.logger.info('Tracing is enabled');
|
|
57
97
|
this.logger.debug('Attaching log messages to spans...');
|
|
58
98
|
logging_1.LoggerFactory.onMessage((level, msg) => {
|
|
59
|
-
|
|
60
|
-
|
|
99
|
+
if (this.trace && this.context) {
|
|
100
|
+
const span = this.trace.getSpan(this.context.active());
|
|
101
|
+
span?.addEvent('log', { ...msg, level });
|
|
102
|
+
}
|
|
61
103
|
});
|
|
62
104
|
}
|
|
63
105
|
};
|
|
@@ -65,6 +107,6 @@ exports.TracingModule = TracingModule;
|
|
|
65
107
|
exports.TracingModule = TracingModule = TracingModule_1 = __decorate([
|
|
66
108
|
(0, common_1.Module)({}),
|
|
67
109
|
__param(0, (0, logging_2.InjectLogger)(TracingModule)),
|
|
68
|
-
__metadata("design:paramtypes", [Object
|
|
110
|
+
__metadata("design:paramtypes", [Object])
|
|
69
111
|
], TracingModule);
|
|
70
112
|
//# sourceMappingURL=tracing.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.module.js","sourceRoot":"","sources":["../../src/tracing/tracing.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tracing.module.js","sourceRoot":"","sources":["../../src/tracing/tracing.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAAwC;AACxC,uCAA+C;AAE/C,yCAAoC;AACpC,2CAAuD;AAEvD,wCAA0C;AAG1C,2CAIqB;AACrB,iDAAgD;AAChD,+DAA2D;AASpD,IAAM,aAAa,qBAAnB,MAAM,aAAa;IAIkC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CAuEzB"}
|
package/dist/tracing/types.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
private headers;
|
|
11
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* The idea of this mappings is to enable aliases. Ex:
|
|
3
|
+
* ['requestId', 'X-Request-Id', 'X-Requestid] means that first of this
|
|
4
|
+
* headers found will be taken. And then the first one will be used.
|
|
5
|
+
*
|
|
6
|
+
* In other way, the first element is main header name, and other are
|
|
7
|
+
* possible aliases.
|
|
8
|
+
*/
|
|
9
|
+
export type TracingHeaderMappings = [string, ...string[]];
|
package/dist/tracing/types.js
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TracingHeaders = exports.tracingHeaders = void 0;
|
|
4
|
-
const node_crypto_1 = require("node:crypto");
|
|
5
|
-
const constants_1 = require("./constants");
|
|
6
|
-
exports.tracingHeaders = [constants_1.X_REQUEST_ID];
|
|
7
|
-
class TracingHeaders {
|
|
8
|
-
constructor(headers) {
|
|
9
|
-
this.headers = {
|
|
10
|
-
...headers,
|
|
11
|
-
[constants_1.X_REQUEST_ID]: headers[constants_1.X_REQUEST_ID] ?? this.createRequestId(),
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
getHeaders() {
|
|
15
|
-
return this.headers;
|
|
16
|
-
}
|
|
17
|
-
createRequestId() {
|
|
18
|
-
return (0, node_crypto_1.randomUUID)();
|
|
19
|
-
}
|
|
20
|
-
headers;
|
|
21
|
-
}
|
|
22
|
-
exports.TracingHeaders = TracingHeaders;
|
|
23
3
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tracing/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tracing/types.ts"],"names":[],"mappings":""}
|