@lambdaorm/lib 3.8.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/README.md +3 -3
- package/connection/infrastructure/adapters/base/connectionPool.d.ts +3 -0
- package/connection/infrastructure/adapters/base/connectionPool.d.ts.map +1 -1
- package/connection/infrastructure/adapters/base/connectionPool.js +17 -0
- package/connection/infrastructure/adapters/base/connectionPool.js.map +1 -1
- package/execution/application/services/executor.d.ts.map +1 -1
- package/execution/application/services/executor.js +9 -1
- package/execution/application/services/executor.js.map +1 -1
- package/execution/application/services/queryExecutor/queryExecutor.d.ts +4 -0
- package/execution/application/services/queryExecutor/queryExecutor.d.ts.map +1 -1
- package/execution/application/services/queryExecutor/queryExecutor.js +48 -0
- package/execution/application/services/queryExecutor/queryExecutor.js.map +1 -1
- package/execution/domain/errors.d.ts +3 -0
- package/execution/domain/errors.d.ts.map +1 -1
- package/execution/domain/errors.js +2 -0
- package/execution/domain/errors.js.map +1 -1
- package/expressions/application/facade.js +1 -1
- package/expressions/application/facade.js.map +1 -1
- package/expressions/application/services/queryBuilder.d.ts +3 -1
- package/expressions/application/services/queryBuilder.d.ts.map +1 -1
- package/expressions/application/services/queryBuilder.js +8 -1
- package/expressions/application/services/queryBuilder.js.map +1 -1
- package/expressions/application/services/queryBuilderCacheDecorator.d.ts.map +1 -1
- package/expressions/application/services/queryBuilderCacheDecorator.js +7 -3
- package/expressions/application/services/queryBuilderCacheDecorator.js.map +1 -1
- package/expressions/application/useCases/execute.d.ts.map +1 -1
- package/expressions/application/useCases/execute.js +7 -3
- package/expressions/application/useCases/execute.js.map +1 -1
- package/expressions/application/useCases/transaction.d.ts +3 -1
- package/expressions/application/useCases/transaction.d.ts.map +1 -1
- package/expressions/application/useCases/transaction.js +7 -3
- package/expressions/application/useCases/transaction.js.map +1 -1
- package/language/domain/ports/DmlBuilder.d.ts +2 -0
- package/language/domain/ports/DmlBuilder.d.ts.map +1 -1
- package/orm/infrastructure/orm.d.ts +9 -0
- package/orm/infrastructure/orm.d.ts.map +1 -1
- package/orm/infrastructure/orm.js +41 -0
- package/orm/infrastructure/orm.js.map +1 -1
- package/package.json +72 -3
- package/query/domain/query.d.ts +2 -0
- package/query/domain/query.d.ts.map +1 -1
- package/query/domain/query.js.map +1 -1
- package/sentence/infrastructure/adapters/NoSql/NoSqlDmlBuilder.d.ts.map +1 -1
- package/sentence/infrastructure/adapters/NoSql/NoSqlDmlBuilder.js +3 -0
- package/sentence/infrastructure/adapters/NoSql/NoSqlDmlBuilder.js.map +1 -1
- package/sentence/infrastructure/adapters/base/dmlBuilder.d.ts +2 -0
- package/sentence/infrastructure/adapters/base/dmlBuilder.d.ts.map +1 -1
- package/sentence/infrastructure/adapters/base/dmlBuilder.js +5 -0
- package/sentence/infrastructure/adapters/base/dmlBuilder.js.map +1 -1
- package/shared/infrastructure/helper.d.ts +3 -0
- package/shared/infrastructure/helper.d.ts.map +1 -1
- package/shared/infrastructure/helper.js +2 -0
- package/shared/infrastructure/helper.js.map +1 -1
- package/shared/infrastructure/index.d.ts +1 -0
- package/shared/infrastructure/index.d.ts.map +1 -1
- package/shared/infrastructure/index.js +1 -0
- package/shared/infrastructure/index.js.map +1 -1
- package/shared/infrastructure/observability/index.d.ts +7 -0
- package/shared/infrastructure/observability/index.d.ts.map +1 -0
- package/shared/infrastructure/observability/index.js +23 -0
- package/shared/infrastructure/observability/index.js.map +1 -0
- package/shared/infrastructure/observability/ruleBasedSpanProcessor.d.ts +60 -0
- package/shared/infrastructure/observability/ruleBasedSpanProcessor.d.ts.map +1 -0
- package/shared/infrastructure/observability/ruleBasedSpanProcessor.js +131 -0
- package/shared/infrastructure/observability/ruleBasedSpanProcessor.js.map +1 -0
- package/shared/infrastructure/observability/sanitizer.d.ts +7 -0
- package/shared/infrastructure/observability/sanitizer.d.ts.map +1 -0
- package/shared/infrastructure/observability/sanitizer.js +43 -0
- package/shared/infrastructure/observability/sanitizer.js.map +1 -0
- package/shared/infrastructure/observability/sdk.d.ts +47 -0
- package/shared/infrastructure/observability/sdk.d.ts.map +1 -0
- package/shared/infrastructure/observability/sdk.js +251 -0
- package/shared/infrastructure/observability/sdk.js.map +1 -0
- package/shared/infrastructure/observability/semconv.d.ts +50 -0
- package/shared/infrastructure/observability/semconv.d.ts.map +1 -0
- package/shared/infrastructure/observability/semconv.js +81 -0
- package/shared/infrastructure/observability/semconv.js.map +1 -0
- package/shared/infrastructure/observability/telemetry.d.ts +103 -0
- package/shared/infrastructure/observability/telemetry.d.ts.map +1 -0
- package/shared/infrastructure/observability/telemetry.js +408 -0
- package/shared/infrastructure/observability/telemetry.js.map +1 -0
- package/shared/infrastructure/observability/traceRules.d.ts +56 -0
- package/shared/infrastructure/observability/traceRules.d.ts.map +1 -0
- package/shared/infrastructure/observability/traceRules.js +68 -0
- package/shared/infrastructure/observability/traceRules.js.map +1 -0
- package/stage/application/facade.d.ts +8 -0
- package/stage/application/facade.d.ts.map +1 -1
- package/stage/application/facade.js +27 -11
- package/stage/application/facade.js.map +1 -1
- package/stage/application/services/schemaEventService.d.ts +29 -0
- package/stage/application/services/schemaEventService.d.ts.map +1 -0
- package/stage/application/services/schemaEventService.js +123 -0
- package/stage/application/services/schemaEventService.js.map +1 -0
- package/stage/application/services/stateService.d.ts +9 -2
- package/stage/application/services/stateService.d.ts.map +1 -1
- package/stage/application/services/stateService.js +20 -0
- package/stage/application/services/stateService.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/shared/infrastructure/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/shared/infrastructure/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA"}
|
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./helper"), exports);
|
|
18
|
+
__exportStar(require("./observability"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/shared/infrastructure/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/shared/infrastructure/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,kDAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/lib/shared/infrastructure/observability/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,OAAO,CAAA;AACrB,cAAc,cAAc,CAAA;AAC5B,cAAc,0BAA0B,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./semconv"), exports);
|
|
18
|
+
__exportStar(require("./sanitizer"), exports);
|
|
19
|
+
__exportStar(require("./telemetry"), exports);
|
|
20
|
+
__exportStar(require("./sdk"), exports);
|
|
21
|
+
__exportStar(require("./traceRules"), exports);
|
|
22
|
+
__exportStar(require("./ruleBasedSpanProcessor"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/shared/infrastructure/observability/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,8CAA2B;AAC3B,8CAA2B;AAC3B,wCAAqB;AACrB,+CAA4B;AAC5B,2DAAwC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Attributes, Context, SpanContext } from '@opentelemetry/api';
|
|
2
|
+
/** what the processor reads of a span (structural: the types of the SDK are an optional dependency) */
|
|
3
|
+
export interface ProcessedSpan {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly attributes: Attributes;
|
|
6
|
+
readonly parentSpanContext?: SpanContext;
|
|
7
|
+
readonly instrumentationScope?: {
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
spanContext(): SpanContext;
|
|
11
|
+
}
|
|
12
|
+
/** the next processor of the SDK (a BatchSpanProcessor) */
|
|
13
|
+
export interface NextSpanProcessor {
|
|
14
|
+
onStart(span: any, parentContext: Context): void;
|
|
15
|
+
onEnding?(span: any): void;
|
|
16
|
+
onEnd(span: any): void;
|
|
17
|
+
forceFlush(): Promise<void>;
|
|
18
|
+
shutdown(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface RuleBasedSpanProcessorOptions {
|
|
21
|
+
/** the spans kept for one expression; beyond them they are dropped (default 1000) */
|
|
22
|
+
maxSpansPerRoot?: number;
|
|
23
|
+
/** the expressions waiting for their decision; beyond them the oldest is dropped (default 1000) */
|
|
24
|
+
maxPendingRoots?: number;
|
|
25
|
+
/** the time an expression can wait for its decision (default 60000 ms) */
|
|
26
|
+
maxAgeMs?: number;
|
|
27
|
+
}
|
|
28
|
+
export declare const LAMBDAORM_ROOT_SPAN = "lambdaorm.execute";
|
|
29
|
+
export declare const LAMBDAORM_TRANSACTION_SPAN = "lambdaorm.transaction";
|
|
30
|
+
export declare const TRACE_RECORD = "lambdaorm.trace.record";
|
|
31
|
+
export declare const TRACE_RULE = "lambdaorm.trace.rule";
|
|
32
|
+
/**
|
|
33
|
+
* Applies the decision of the trace rules of λORM (docs/OBSERVABILITY.md §7.2): each lambdaorm.execute and its
|
|
34
|
+
* descendants are kept until it ends, and go to the next processor only if its attribute lambdaorm.trace.record is not
|
|
35
|
+
* false. A lambdaorm.transaction goes if one of its expressions goes. The other spans (of the caller, of other
|
|
36
|
+
* libraries) go on as they are. It reads the decision from the span, not from a schema: one processor serves several.
|
|
37
|
+
*/
|
|
38
|
+
export declare class RuleBasedSpanProcessor implements NextSpanProcessor {
|
|
39
|
+
private readonly next;
|
|
40
|
+
private readonly owners;
|
|
41
|
+
private readonly roots;
|
|
42
|
+
private readonly decided;
|
|
43
|
+
private readonly transactions;
|
|
44
|
+
private readonly maxSpansPerRoot;
|
|
45
|
+
private readonly maxPendingRoots;
|
|
46
|
+
private readonly maxAgeMs;
|
|
47
|
+
private droppedCounter?;
|
|
48
|
+
/** the spans dropped by the limits (not the ones a rule discarded) */
|
|
49
|
+
dropped: number;
|
|
50
|
+
constructor(next: NextSpanProcessor, options?: RuleBasedSpanProcessorOptions);
|
|
51
|
+
onStart(span: ProcessedSpan, parentContext: Context): void;
|
|
52
|
+
onEnding(span: any): void;
|
|
53
|
+
onEnd(span: ProcessedSpan): void;
|
|
54
|
+
forceFlush(): Promise<void>;
|
|
55
|
+
shutdown(): Promise<void>;
|
|
56
|
+
private evict;
|
|
57
|
+
private remember;
|
|
58
|
+
private drop;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=ruleBasedSpanProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ruleBasedSpanProcessor.d.ts","sourceRoot":"","sources":["../../../../../src/lib/shared/infrastructure/observability/ruleBasedSpanProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAoB,MAAM,oBAAoB,CAAA;AAEvF,uGAAuG;AACvG,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAA;IAC/B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,WAAW,CAAA;IACxC,QAAQ,CAAC,oBAAoB,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IAChD,WAAW,IAAK,WAAW,CAAA;CAC3B;AAED,2DAA2D;AAC3D,MAAM,WAAW,iBAAiB;IACjC,OAAO,CAAE,IAAI,EAAE,GAAG,EAAE,aAAa,EAAE,OAAO,GAAG,IAAI,CAAA;IACjD,QAAQ,CAAC,CAAE,IAAI,EAAE,GAAG,GAAG,IAAI,CAAA;IAC3B,KAAK,CAAE,IAAI,EAAE,GAAG,GAAG,IAAI,CAAA;IACvB,UAAU,IAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,QAAQ,IAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1B;AAED,MAAM,WAAW,6BAA6B;IAC7C,qFAAqF;IACrF,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,mGAAmG;IACnG,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,eAAO,MAAM,mBAAmB,sBAAsB,CAAA;AACtD,eAAO,MAAM,0BAA0B,0BAA0B,CAAA;AACjE,eAAO,MAAM,YAAY,2BAA2B,CAAA;AACpD,eAAO,MAAM,UAAU,yBAAyB,CAAA;AAUhD;;;;;GAKG;AACH,qBAAa,sBAAuB,YAAW,iBAAiB;IAYlD,OAAO,CAAC,QAAQ,CAAC,IAAI;IAXlC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IACnD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IACvD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA6B;IAC1D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,cAAc,CAAC,CAAS;IAChC,sEAAsE;IAC/D,OAAO,SAAI;gBAEY,IAAI,EAAE,iBAAiB,EAAE,OAAO,GAAE,6BAAkC;IAM3F,OAAO,CAAE,IAAI,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,GAAG,IAAI;IAqB3D,QAAQ,CAAE,IAAI,EAAE,GAAG,GAAG,IAAI;IAI1B,KAAK,CAAE,IAAI,EAAE,aAAa,GAAG,IAAI;IAwCjC,UAAU,IAAK,OAAO,CAAC,IAAI,CAAC;IAItB,QAAQ,IAAK,OAAO,CAAC,IAAI,CAAC;IAMvC,OAAO,CAAC,KAAK;IAUb,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,IAAI;CAOZ"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RuleBasedSpanProcessor = exports.TRACE_RULE = exports.TRACE_RECORD = exports.LAMBDAORM_TRANSACTION_SPAN = exports.LAMBDAORM_ROOT_SPAN = void 0;
|
|
4
|
+
const api_1 = require("@opentelemetry/api");
|
|
5
|
+
exports.LAMBDAORM_ROOT_SPAN = 'lambdaorm.execute';
|
|
6
|
+
exports.LAMBDAORM_TRANSACTION_SPAN = 'lambdaorm.transaction';
|
|
7
|
+
exports.TRACE_RECORD = 'lambdaorm.trace.record';
|
|
8
|
+
exports.TRACE_RULE = 'lambdaorm.trace.rule';
|
|
9
|
+
/**
|
|
10
|
+
* Applies the decision of the trace rules of λORM (docs/OBSERVABILITY.md §7.2): each lambdaorm.execute and its
|
|
11
|
+
* descendants are kept until it ends, and go to the next processor only if its attribute lambdaorm.trace.record is not
|
|
12
|
+
* false. A lambdaorm.transaction goes if one of its expressions goes. The other spans (of the caller, of other
|
|
13
|
+
* libraries) go on as they are. It reads the decision from the span, not from a schema: one processor serves several.
|
|
14
|
+
*/
|
|
15
|
+
class RuleBasedSpanProcessor {
|
|
16
|
+
constructor(next, options = {}) {
|
|
17
|
+
this.next = next;
|
|
18
|
+
this.owners = new Map();
|
|
19
|
+
this.roots = new Map();
|
|
20
|
+
this.decided = new Map();
|
|
21
|
+
this.transactions = new Map();
|
|
22
|
+
/** the spans dropped by the limits (not the ones a rule discarded) */
|
|
23
|
+
this.dropped = 0;
|
|
24
|
+
this.maxSpansPerRoot = options.maxSpansPerRoot ?? 1000;
|
|
25
|
+
this.maxPendingRoots = options.maxPendingRoots ?? 1000;
|
|
26
|
+
this.maxAgeMs = options.maxAgeMs ?? 60000;
|
|
27
|
+
}
|
|
28
|
+
onStart(span, parentContext) {
|
|
29
|
+
this.next.onStart(span, parentContext);
|
|
30
|
+
const id = span.spanContext().spanId;
|
|
31
|
+
const parent = span.parentSpanContext?.spanId;
|
|
32
|
+
const owner = parent ? this.owners.get(parent) : undefined;
|
|
33
|
+
if (owner) {
|
|
34
|
+
this.owners.set(id, owner);
|
|
35
|
+
}
|
|
36
|
+
else if (span.name === exports.LAMBDAORM_ROOT_SPAN) {
|
|
37
|
+
this.owners.set(id, id);
|
|
38
|
+
this.roots.set(id, {
|
|
39
|
+
spans: [],
|
|
40
|
+
started: Date.now(),
|
|
41
|
+
passthrough: span.attributes[exports.TRACE_RECORD] === true,
|
|
42
|
+
transaction: parent && this.transactions.has(parent) ? parent : undefined
|
|
43
|
+
});
|
|
44
|
+
this.evict();
|
|
45
|
+
}
|
|
46
|
+
else if (span.name === exports.LAMBDAORM_TRANSACTION_SPAN) {
|
|
47
|
+
this.transactions.set(id, false);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
onEnding(span) {
|
|
51
|
+
this.next.onEnding?.(span);
|
|
52
|
+
}
|
|
53
|
+
onEnd(span) {
|
|
54
|
+
const id = span.spanContext().spanId;
|
|
55
|
+
if (this.transactions.has(id)) {
|
|
56
|
+
const recorded = this.transactions.get(id);
|
|
57
|
+
this.transactions.delete(id);
|
|
58
|
+
if (recorded)
|
|
59
|
+
this.next.onEnd(span);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const rootId = this.owners.get(id);
|
|
63
|
+
if (rootId === undefined) {
|
|
64
|
+
this.next.onEnd(span);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this.owners.delete(id);
|
|
68
|
+
const root = this.roots.get(rootId);
|
|
69
|
+
if (!root) {
|
|
70
|
+
// its expression already decided (or was dropped)
|
|
71
|
+
if (this.decided.get(rootId))
|
|
72
|
+
this.next.onEnd(span);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (rootId === id) {
|
|
76
|
+
this.roots.delete(rootId);
|
|
77
|
+
const record = span.attributes[exports.TRACE_RECORD] !== false;
|
|
78
|
+
this.remember(rootId, record);
|
|
79
|
+
if (record) {
|
|
80
|
+
for (const kept of root.spans)
|
|
81
|
+
this.next.onEnd(kept);
|
|
82
|
+
this.next.onEnd(span);
|
|
83
|
+
if (root.transaction && this.transactions.has(root.transaction))
|
|
84
|
+
this.transactions.set(root.transaction, true);
|
|
85
|
+
}
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (root.passthrough) {
|
|
89
|
+
this.next.onEnd(span);
|
|
90
|
+
}
|
|
91
|
+
else if (root.spans.length < this.maxSpansPerRoot) {
|
|
92
|
+
root.spans.push(span);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
this.drop(1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
forceFlush() {
|
|
99
|
+
return this.next.forceFlush();
|
|
100
|
+
}
|
|
101
|
+
async shutdown() {
|
|
102
|
+
this.roots.clear();
|
|
103
|
+
this.owners.clear();
|
|
104
|
+
await this.next.shutdown();
|
|
105
|
+
}
|
|
106
|
+
evict() {
|
|
107
|
+
const now = Date.now();
|
|
108
|
+
for (const [id, root] of this.roots) {
|
|
109
|
+
if (this.roots.size <= this.maxPendingRoots && now - root.started <= this.maxAgeMs)
|
|
110
|
+
break;
|
|
111
|
+
this.roots.delete(id);
|
|
112
|
+
this.remember(id, false);
|
|
113
|
+
this.drop(root.spans.length + 1);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
remember(rootId, record) {
|
|
117
|
+
this.decided.set(rootId, record);
|
|
118
|
+
if (this.decided.size > this.maxPendingRoots) {
|
|
119
|
+
this.decided.delete(this.decided.keys().next().value);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
drop(count) {
|
|
123
|
+
this.dropped += count;
|
|
124
|
+
if (!this.droppedCounter) {
|
|
125
|
+
this.droppedCounter = api_1.metrics.getMeter('@lambdaorm/lib').createCounter('lambdaorm.trace.dropped', { description: 'Spans dropped by the limits of the trace rules', unit: '{span}' });
|
|
126
|
+
}
|
|
127
|
+
this.droppedCounter.add(count);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.RuleBasedSpanProcessor = RuleBasedSpanProcessor;
|
|
131
|
+
//# sourceMappingURL=ruleBasedSpanProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ruleBasedSpanProcessor.js","sourceRoot":"","sources":["../../../../../src/lib/shared/infrastructure/observability/ruleBas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E,CAAC;YAC9C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAe,CAAC,CAAA;QAChE,CAAC;IACF,CAAC;IAEO,IAAI,CAAE,KAAa;QAC1B,IAAI,CAAC,OAAO,IAAI,KAAK,CAAA;QACrB,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YAC1B,IAAI,CAAC,cAAc,GAAG,aAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC,aAAa,CAAC,yBAAyB,EAAE,EAAE,WAAW,EAAE,gDAAgD,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;QACrL,CAAC;QACD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;CACD;AArHD,wDAqHC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replaces the literals of a λORM expression (strings and numbers) by "?", so its text can go in a span without the
|
|
3
|
+
* values written in it: Customers.filter(p => p.email == "x@y.com") → Customers.filter(p => p.email == ?).
|
|
4
|
+
* Identifiers with digits (p.col1) and environment variables ($VAR) stay.
|
|
5
|
+
*/
|
|
6
|
+
export declare const sanitizeExpression: (expression: string) => string;
|
|
7
|
+
//# sourceMappingURL=sanitizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizer.d.ts","sourceRoot":"","sources":["../../../../../src/lib/shared/infrastructure/observability/sanitizer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,YAAY,MAAM,KAAG,MA+BvD,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sanitizeExpression = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Replaces the literals of a λORM expression (strings and numbers) by "?", so its text can go in a span without the
|
|
6
|
+
* values written in it: Customers.filter(p => p.email == "x@y.com") → Customers.filter(p => p.email == ?).
|
|
7
|
+
* Identifiers with digits (p.col1) and environment variables ($VAR) stay.
|
|
8
|
+
*/
|
|
9
|
+
const sanitizeExpression = (expression) => {
|
|
10
|
+
let result = '';
|
|
11
|
+
let i = 0;
|
|
12
|
+
const length = expression.length;
|
|
13
|
+
while (i < length) {
|
|
14
|
+
const char = expression[i];
|
|
15
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
16
|
+
let j = i + 1;
|
|
17
|
+
while (j < length && expression[j] !== char) {
|
|
18
|
+
j += expression[j] === '\\' ? 2 : 1;
|
|
19
|
+
}
|
|
20
|
+
result += '?';
|
|
21
|
+
i = j + 1;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const previous = i > 0 ? expression[i - 1] : '';
|
|
25
|
+
const isNumberStart = /[0-9]/.test(char) || (char === '.' && /[0-9]/.test(expression[i + 1] ?? ''));
|
|
26
|
+
if (isNumberStart && !/[A-Za-z0-9_$.]/.test(previous)) {
|
|
27
|
+
let j = i;
|
|
28
|
+
while (j < length && /[0-9._eE]/.test(expression[j])) {
|
|
29
|
+
if ((expression[j] === 'e' || expression[j] === 'E') && /[+-]/.test(expression[j + 1] ?? ''))
|
|
30
|
+
j++;
|
|
31
|
+
j++;
|
|
32
|
+
}
|
|
33
|
+
result += '?';
|
|
34
|
+
i = j;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
result += char;
|
|
38
|
+
i++;
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
exports.sanitizeExpression = sanitizeExpression;
|
|
43
|
+
//# sourceMappingURL=sanitizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizer.js","sourceRoot":"","sources":["../../../../../src/lib/shared/infrastructure/observability/sanitizer.ts"],"names":[],"mappings":";;;AAAA;;;;GAI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CAAC;gBACtD,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;oBAAE,CAAC,EAAE,CAAA;gBACjG,CAAC,EAAE,CAAA;YACJ,CAAC;YACD,MAAM,IAAI,GAAG,CAAA;YACb,CAAC,GAAG,CAAC,CAAA;YACL,SAAQ;QACT,CAAC;QACD,MAAM,IAAI,IAAI,CAAA;QACd,CAAC,EAAE,CAAA;IACJ,CAAC;IACD,OAAO,MAAM,CAAA;AACd,CAAC,CAAA;AA/BY,QAAA,kBAAkB,sBA+B9B"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ResolvedObservability } from '@lambdaorm/base';
|
|
2
|
+
type Signal = 'traces' | 'metrics' | 'logs';
|
|
3
|
+
/** what each signal needs of the configuration */
|
|
4
|
+
export declare const sdkSignals: (config: ResolvedObservability) => Signal[];
|
|
5
|
+
/**
|
|
6
|
+
* The OpenTelemetry SDK that λORM starts when the configuration asks for it and nobody registered one before (a
|
|
7
|
+
* gateway, or an application with its own SDK, registers it first and λORM uses it). Once per process: each Orm that
|
|
8
|
+
* starts it takes a reference, and the last one that releases it shuts it down. The SDK packages are optional peer
|
|
9
|
+
* dependencies: they are loaded only here, and a missing one is a clear warning, without that signal.
|
|
10
|
+
* λORM doesn't listen to SIGTERM (it would take away the default exit of Node): the application calls shutdown().
|
|
11
|
+
*/
|
|
12
|
+
export declare class ObservabilitySdk {
|
|
13
|
+
private readonly config;
|
|
14
|
+
private static current?;
|
|
15
|
+
private static references;
|
|
16
|
+
private readonly shutdowns;
|
|
17
|
+
private prometheusReader?;
|
|
18
|
+
readonly signals: Signal[];
|
|
19
|
+
readonly warnings: string[];
|
|
20
|
+
private constructor();
|
|
21
|
+
/** starts the SDK (or takes a reference to the one already started); undefined when there is nothing to start */
|
|
22
|
+
static start(config: ResolvedObservability, warn?: (message: string) => void): Promise<ObservabilitySdk | undefined>;
|
|
23
|
+
/** releases a reference; the last one shuts the SDK down (flushing what is pending) */
|
|
24
|
+
static release(): Promise<void>;
|
|
25
|
+
/** shuts the SDK down whatever its references: for the application, when the process ends */
|
|
26
|
+
static shutdown(): Promise<void>;
|
|
27
|
+
static get started(): ObservabilitySdk | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* the metrics as the SDK has them (ResourceMetrics of @opentelemetry/sdk-metrics), when the metrics exporter
|
|
30
|
+
* prometheus is configured: for whoever renders them with others (a gateway that adds those of several workers)
|
|
31
|
+
*/
|
|
32
|
+
static collectMetrics(): Promise<any | undefined>;
|
|
33
|
+
/** the metrics in the text format of Prometheus, when the metrics exporter prometheus is configured */
|
|
34
|
+
static prometheusMetrics(): Promise<string | undefined>;
|
|
35
|
+
private load;
|
|
36
|
+
private resource;
|
|
37
|
+
/** the context manager (so the spans nest across awaits) and the W3C propagators, if nobody set them */
|
|
38
|
+
private startContext;
|
|
39
|
+
private otlpExporter;
|
|
40
|
+
/** true when the signal was registered; false when another SDK has it */
|
|
41
|
+
private startSignal;
|
|
42
|
+
private startTraces;
|
|
43
|
+
private startMetrics;
|
|
44
|
+
private startLogs;
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../../../../src/lib/shared/infrastructure/observability/sdk.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAgB,MAAM,iBAAiB,CAAA;AAGrE,KAAK,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAA;AAU3C,kDAAkD;AAClD,eAAO,MAAM,UAAU,GAAI,QAAQ,qBAAqB,KAAG,MAAM,EAQhE,CAAA;AAED;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAQP,OAAO,CAAC,QAAQ,CAAC,MAAM;IAP5C,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAkB;IACzC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAI;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IACxD,OAAO,CAAC,gBAAgB,CAAC,CAAK;IAC9B,SAAgB,OAAO,EAAE,MAAM,EAAE,CAAK;IACtC,SAAgB,QAAQ,EAAE,MAAM,EAAE,CAAK;IAEvC,OAAO;IAEP,iHAAiH;WAC7F,KAAK,CAAE,MAAM,EAAE,qBAAqB,EAAE,IAAI,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAmB,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAuBhJ,uFAAuF;WACnE,OAAO,IAAK,OAAO,CAAC,IAAI,CAAC;IAQ7C,6FAA6F;WACzE,QAAQ,IAAK,OAAO,CAAC,IAAI,CAAC;IAS9C,WAAkB,OAAO,IAAK,gBAAgB,GAAG,SAAS,CAEzD;IAED;;;OAGG;WACiB,cAAc,IAAK,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC;IAO/D,uGAAuG;WACnF,iBAAiB,IAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAQrE,OAAO,CAAC,IAAI;IAWZ,OAAO,CAAC,QAAQ;IAKhB,wGAAwG;IACxG,OAAO,CAAC,YAAY;IAkBpB,OAAO,CAAC,YAAY;IAmBpB,yEAAyE;IACzE,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,WAAW;IAwBnB,OAAO,CAAC,YAAY;IA8BpB,OAAO,CAAC,SAAS;CAmBjB"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObservabilitySdk = exports.sdkSignals = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
5
|
+
const api_1 = require("@opentelemetry/api");
|
|
6
|
+
const ruleBasedSpanProcessor_1 = require("./ruleBasedSpanProcessor");
|
|
7
|
+
const OTLP_PACKAGES = {
|
|
8
|
+
traces: { 'http/protobuf': '@opentelemetry/exporter-trace-otlp-proto', 'http/json': '@opentelemetry/exporter-trace-otlp-http', grpc: '@opentelemetry/exporter-trace-otlp-grpc' },
|
|
9
|
+
metrics: { 'http/protobuf': '@opentelemetry/exporter-metrics-otlp-proto', 'http/json': '@opentelemetry/exporter-metrics-otlp-http', grpc: '@opentelemetry/exporter-metrics-otlp-grpc' },
|
|
10
|
+
logs: { 'http/protobuf': '@opentelemetry/exporter-logs-otlp-proto', 'http/json': '@opentelemetry/exporter-logs-otlp-http', grpc: '@opentelemetry/exporter-logs-otlp-grpc' }
|
|
11
|
+
};
|
|
12
|
+
const OTLP_CLASSES = { traces: 'OTLPTraceExporter', metrics: 'OTLPMetricExporter', logs: 'OTLPLogExporter' };
|
|
13
|
+
const OTLP_PATHS = { traces: 'v1/traces', metrics: 'v1/metrics', logs: 'v1/logs' };
|
|
14
|
+
/** what each signal needs of the configuration */
|
|
15
|
+
const sdkSignals = (config) => {
|
|
16
|
+
if (config.sdkDisabled)
|
|
17
|
+
return [];
|
|
18
|
+
const exporting = config.exporter.type !== 'none';
|
|
19
|
+
const signals = [];
|
|
20
|
+
if (config.traces.enabled && exporting)
|
|
21
|
+
signals.push('traces');
|
|
22
|
+
if (config.metrics.enabled && (exporting || config.metrics.exporters.some(p => p.type === 'prometheus')))
|
|
23
|
+
signals.push('metrics');
|
|
24
|
+
if (exporting && config.logs.adapters.some(p => p.type === 'opentelemetry'))
|
|
25
|
+
signals.push('logs');
|
|
26
|
+
return signals;
|
|
27
|
+
};
|
|
28
|
+
exports.sdkSignals = sdkSignals;
|
|
29
|
+
/**
|
|
30
|
+
* The OpenTelemetry SDK that λORM starts when the configuration asks for it and nobody registered one before (a
|
|
31
|
+
* gateway, or an application with its own SDK, registers it first and λORM uses it). Once per process: each Orm that
|
|
32
|
+
* starts it takes a reference, and the last one that releases it shuts it down. The SDK packages are optional peer
|
|
33
|
+
* dependencies: they are loaded only here, and a missing one is a clear warning, without that signal.
|
|
34
|
+
* λORM doesn't listen to SIGTERM (it would take away the default exit of Node): the application calls shutdown().
|
|
35
|
+
*/
|
|
36
|
+
class ObservabilitySdk {
|
|
37
|
+
constructor(config) {
|
|
38
|
+
this.config = config;
|
|
39
|
+
this.shutdowns = [];
|
|
40
|
+
this.signals = [];
|
|
41
|
+
this.warnings = [];
|
|
42
|
+
}
|
|
43
|
+
/** starts the SDK (or takes a reference to the one already started); undefined when there is nothing to start */
|
|
44
|
+
static async start(config, warn = console.warn) {
|
|
45
|
+
if (ObservabilitySdk.current) {
|
|
46
|
+
ObservabilitySdk.references++;
|
|
47
|
+
return ObservabilitySdk.current;
|
|
48
|
+
}
|
|
49
|
+
if ((0, exports.sdkSignals)(config).length === 0) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const sdk = new ObservabilitySdk(config);
|
|
53
|
+
sdk.startContext();
|
|
54
|
+
for (const signal of (0, exports.sdkSignals)(config)) {
|
|
55
|
+
try {
|
|
56
|
+
if (sdk.startSignal(signal))
|
|
57
|
+
sdk.signals.push(signal);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
sdk.warnings.push(error.message);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (const warning of sdk.warnings)
|
|
64
|
+
warn(`WARNING|observability|${warning}`);
|
|
65
|
+
ObservabilitySdk.current = sdk;
|
|
66
|
+
ObservabilitySdk.references = 1;
|
|
67
|
+
return sdk;
|
|
68
|
+
}
|
|
69
|
+
/** releases a reference; the last one shuts the SDK down (flushing what is pending) */
|
|
70
|
+
static async release() {
|
|
71
|
+
if (!ObservabilitySdk.current)
|
|
72
|
+
return;
|
|
73
|
+
ObservabilitySdk.references--;
|
|
74
|
+
if (ObservabilitySdk.references <= 0) {
|
|
75
|
+
await ObservabilitySdk.shutdown();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** shuts the SDK down whatever its references: for the application, when the process ends */
|
|
79
|
+
static async shutdown() {
|
|
80
|
+
const sdk = ObservabilitySdk.current;
|
|
81
|
+
ObservabilitySdk.current = undefined;
|
|
82
|
+
ObservabilitySdk.references = 0;
|
|
83
|
+
if (sdk) {
|
|
84
|
+
await Promise.allSettled(sdk.shutdowns.map(p => p()));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
static get started() {
|
|
88
|
+
return ObservabilitySdk.current;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* the metrics as the SDK has them (ResourceMetrics of @opentelemetry/sdk-metrics), when the metrics exporter
|
|
92
|
+
* prometheus is configured: for whoever renders them with others (a gateway that adds those of several workers)
|
|
93
|
+
*/
|
|
94
|
+
static async collectMetrics() {
|
|
95
|
+
const reader = ObservabilitySdk.current?.prometheusReader;
|
|
96
|
+
if (!reader)
|
|
97
|
+
return undefined;
|
|
98
|
+
const { resourceMetrics } = await reader.collect();
|
|
99
|
+
return resourceMetrics;
|
|
100
|
+
}
|
|
101
|
+
/** the metrics in the text format of Prometheus, when the metrics exporter prometheus is configured */
|
|
102
|
+
static async prometheusMetrics() {
|
|
103
|
+
const reader = ObservabilitySdk.current?.prometheusReader;
|
|
104
|
+
if (!reader)
|
|
105
|
+
return undefined;
|
|
106
|
+
const { PrometheusSerializer } = require('@opentelemetry/exporter-prometheus');
|
|
107
|
+
const { resourceMetrics } = await reader.collect();
|
|
108
|
+
return new PrometheusSerializer().serialize(resourceMetrics);
|
|
109
|
+
}
|
|
110
|
+
load(name) {
|
|
111
|
+
try {
|
|
112
|
+
return require(name);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (error?.code === 'MODULE_NOT_FOUND') {
|
|
116
|
+
throw new Error(`install ${name} to export this signal (it is an optional dependency of @lambdaorm/lib)`);
|
|
117
|
+
}
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
resource() {
|
|
122
|
+
const { resourceFromAttributes, defaultResource } = this.load('@opentelemetry/resources');
|
|
123
|
+
return defaultResource().merge(resourceFromAttributes({ ...this.config.resource, 'service.name': this.config.serviceName }));
|
|
124
|
+
}
|
|
125
|
+
/** the context manager (so the spans nest across awaits) and the W3C propagators, if nobody set them */
|
|
126
|
+
startContext() {
|
|
127
|
+
try {
|
|
128
|
+
const { AsyncLocalStorageContextManager } = this.load('@opentelemetry/context-async-hooks');
|
|
129
|
+
const manager = new AsyncLocalStorageContextManager().enable();
|
|
130
|
+
if (api_1.context.setGlobalContextManager(manager)) {
|
|
131
|
+
this.shutdowns.push(async () => { api_1.context.disable(); });
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
manager.disable();
|
|
135
|
+
}
|
|
136
|
+
const { CompositePropagator, W3CTraceContextPropagator, W3CBaggagePropagator } = this.load('@opentelemetry/core');
|
|
137
|
+
if (api_1.propagation.setGlobalPropagator(new CompositePropagator({ propagators: [new W3CTraceContextPropagator(), new W3CBaggagePropagator()] }))) {
|
|
138
|
+
this.shutdowns.push(async () => { api_1.propagation.disable(); });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
this.warnings.push(error.message);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
otlpExporter(signal) {
|
|
146
|
+
const exporter = this.config.exporter;
|
|
147
|
+
if (exporter.type === 'console') {
|
|
148
|
+
switch (signal) {
|
|
149
|
+
case 'traces': return new (this.load('@opentelemetry/sdk-trace').ConsoleSpanExporter)();
|
|
150
|
+
case 'metrics': return new (this.load('@opentelemetry/sdk-metrics').ConsoleMetricExporter)();
|
|
151
|
+
case 'logs': return new (this.load('@opentelemetry/sdk-logs').ConsoleLogRecordExporter)();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const Exporter = this.load(OTLP_PACKAGES[signal][exporter.protocol])[OTLP_CLASSES[signal]];
|
|
155
|
+
const options = {};
|
|
156
|
+
if (Object.keys(exporter.headers).length > 0)
|
|
157
|
+
options.headers = exporter.headers;
|
|
158
|
+
if (exporter.endpoint) {
|
|
159
|
+
// OTEL_EXPORTER_OTLP_ENDPOINT is the base: the path of each signal goes after it (not with grpc)
|
|
160
|
+
options.url = exporter.protocol === 'grpc' ? exporter.endpoint : `${exporter.endpoint.replace(/\/+$/, '')}/${OTLP_PATHS[signal]}`;
|
|
161
|
+
}
|
|
162
|
+
return new Exporter(options);
|
|
163
|
+
}
|
|
164
|
+
/** true when the signal was registered; false when another SDK has it */
|
|
165
|
+
startSignal(signal) {
|
|
166
|
+
switch (signal) {
|
|
167
|
+
case 'traces': return this.startTraces();
|
|
168
|
+
case 'metrics': return this.startMetrics();
|
|
169
|
+
case 'logs': return this.startLogs();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
startTraces() {
|
|
173
|
+
const { TracerProvider, BatchSpanProcessor, ParentBasedSampler, TraceIdRatioBasedSampler } = this.load('@opentelemetry/sdk-trace');
|
|
174
|
+
const { ratio, parentBased } = this.config.traces.sampler;
|
|
175
|
+
const root = new TraceIdRatioBasedSampler(ratio);
|
|
176
|
+
const provider = new TracerProvider({
|
|
177
|
+
resource: this.resource(),
|
|
178
|
+
sampler: parentBased ? new ParentBasedSampler({ root }) : root,
|
|
179
|
+
// the decision of the trace rules first, then the batch that exports
|
|
180
|
+
spanProcessors: [new ruleBasedSpanProcessor_1.RuleBasedSpanProcessor(new BatchSpanProcessor({ exporter: this.otlpExporter('traces') }))]
|
|
181
|
+
});
|
|
182
|
+
if (!api_1.trace.setGlobalTracerProvider(provider)) {
|
|
183
|
+
provider.shutdown().catch(() => undefined);
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
this.shutdowns.push(async () => {
|
|
187
|
+
try {
|
|
188
|
+
await provider.shutdown();
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
api_1.trace.disable();
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
startMetrics() {
|
|
197
|
+
const { MeterProvider, PeriodicExportingMetricReader } = this.load('@opentelemetry/sdk-metrics');
|
|
198
|
+
const readers = [];
|
|
199
|
+
for (const exporter of this.config.metrics.exporters) {
|
|
200
|
+
if (exporter.type === 'prometheus') {
|
|
201
|
+
const { PrometheusExporter } = this.load('@opentelemetry/exporter-prometheus');
|
|
202
|
+
// without its own HTTP server: whoever serves /metrics asks for the text (prometheusMetrics)
|
|
203
|
+
this.prometheusReader = new PrometheusExporter({ preventServerStart: true });
|
|
204
|
+
readers.push(this.prometheusReader);
|
|
205
|
+
}
|
|
206
|
+
else if (this.config.exporter.type !== 'none') {
|
|
207
|
+
readers.push(new PeriodicExportingMetricReader({ exporter: this.otlpExporter('metrics'), exportIntervalMillis: exporter.exportIntervalMs }));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (readers.length === 0)
|
|
211
|
+
return false;
|
|
212
|
+
const provider = new MeterProvider({ resource: this.resource(), readers });
|
|
213
|
+
if (!api_1.metrics.setGlobalMeterProvider(provider)) {
|
|
214
|
+
provider.shutdown().catch(() => undefined);
|
|
215
|
+
this.prometheusReader = undefined;
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
this.shutdowns.push(async () => {
|
|
219
|
+
try {
|
|
220
|
+
await provider.shutdown();
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
api_1.metrics.disable();
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
startLogs() {
|
|
229
|
+
const { LoggerProvider, BatchLogRecordProcessor } = this.load('@opentelemetry/sdk-logs');
|
|
230
|
+
const provider = new LoggerProvider({
|
|
231
|
+
resource: this.resource(),
|
|
232
|
+
processors: [new BatchLogRecordProcessor({ exporter: this.otlpExporter('logs') })]
|
|
233
|
+
});
|
|
234
|
+
if (!api_1.logs.setGlobalLoggerProvider(provider)) {
|
|
235
|
+
provider.shutdown().catch(() => undefined);
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
this.shutdowns.push(async () => {
|
|
239
|
+
try {
|
|
240
|
+
await provider.shutdown();
|
|
241
|
+
}
|
|
242
|
+
finally {
|
|
243
|
+
api_1.logs.disable();
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.ObservabilitySdk = ObservabilitySdk;
|
|
250
|
+
ObservabilitySdk.references = 0;
|
|
251
|
+
//# sourceMappingURL=sdk.js.map
|