@lambdaorm/lib 3.8.1 → 3.10.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.
Files changed (155) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +3 -3
  3. package/connection/infrastructure/adapters/base/connectionPool.d.ts +3 -0
  4. package/connection/infrastructure/adapters/base/connectionPool.d.ts.map +1 -1
  5. package/connection/infrastructure/adapters/base/connectionPool.js +17 -0
  6. package/connection/infrastructure/adapters/base/connectionPool.js.map +1 -1
  7. package/execution/application/services/executor.d.ts.map +1 -1
  8. package/execution/application/services/executor.js +9 -1
  9. package/execution/application/services/executor.js.map +1 -1
  10. package/execution/application/services/queryExecutor/queryBulkInsertExecutor.js +2 -2
  11. package/execution/application/services/queryExecutor/queryBulkInsertExecutor.js.map +1 -1
  12. package/execution/application/services/queryExecutor/queryBulkMergeExecutor.js +2 -2
  13. package/execution/application/services/queryExecutor/queryBulkMergeExecutor.js.map +1 -1
  14. package/execution/application/services/queryExecutor/queryExecutor.d.ts +4 -0
  15. package/execution/application/services/queryExecutor/queryExecutor.d.ts.map +1 -1
  16. package/execution/application/services/queryExecutor/queryExecutor.js +48 -0
  17. package/execution/application/services/queryExecutor/queryExecutor.js.map +1 -1
  18. package/execution/application/services/queryExecutor/queryInsertConditionalExecutor.d.ts.map +1 -1
  19. package/execution/application/services/queryExecutor/queryInsertConditionalExecutor.js +2 -3
  20. package/execution/application/services/queryExecutor/queryInsertConditionalExecutor.js.map +1 -1
  21. package/execution/application/services/queryExecutor/queryInsertExecutor.d.ts.map +1 -1
  22. package/execution/application/services/queryExecutor/queryInsertExecutor.js +2 -3
  23. package/execution/application/services/queryExecutor/queryInsertExecutor.js.map +1 -1
  24. package/execution/application/services/queryExecutor/queryUpsertExecutor.d.ts.map +1 -1
  25. package/execution/application/services/queryExecutor/queryUpsertExecutor.js +2 -3
  26. package/execution/application/services/queryExecutor/queryUpsertExecutor.js.map +1 -1
  27. package/execution/domain/errors.d.ts +3 -0
  28. package/execution/domain/errors.d.ts.map +1 -1
  29. package/execution/domain/errors.js +2 -0
  30. package/execution/domain/errors.js.map +1 -1
  31. package/expressions/application/facade.d.ts.map +1 -1
  32. package/expressions/application/facade.js +5 -1
  33. package/expressions/application/facade.js.map +1 -1
  34. package/expressions/application/services/queryBuilder.d.ts +3 -1
  35. package/expressions/application/services/queryBuilder.d.ts.map +1 -1
  36. package/expressions/application/services/queryBuilder.js +10 -2
  37. package/expressions/application/services/queryBuilder.js.map +1 -1
  38. package/expressions/application/services/queryBuilderCacheDecorator.d.ts.map +1 -1
  39. package/expressions/application/services/queryBuilderCacheDecorator.js +7 -3
  40. package/expressions/application/services/queryBuilderCacheDecorator.js.map +1 -1
  41. package/expressions/application/useCases/execute.d.ts.map +1 -1
  42. package/expressions/application/useCases/execute.js +7 -3
  43. package/expressions/application/useCases/execute.js.map +1 -1
  44. package/expressions/application/useCases/transaction.d.ts +3 -1
  45. package/expressions/application/useCases/transaction.d.ts.map +1 -1
  46. package/expressions/application/useCases/transaction.js +7 -3
  47. package/expressions/application/useCases/transaction.js.map +1 -1
  48. package/language/domain/ports/DmlBuilder.d.ts +2 -0
  49. package/language/domain/ports/DmlBuilder.d.ts.map +1 -1
  50. package/operand/application/services/operandNormalizer.d.ts +5 -0
  51. package/operand/application/services/operandNormalizer.d.ts.map +1 -1
  52. package/operand/application/services/operandNormalizer.js +32 -0
  53. package/operand/application/services/operandNormalizer.js.map +1 -1
  54. package/orm/application/orm.d.ts +7 -7
  55. package/orm/application/orm.d.ts.map +1 -1
  56. package/orm/infrastructure/orm.d.ts +26 -9
  57. package/orm/infrastructure/orm.d.ts.map +1 -1
  58. package/orm/infrastructure/orm.js +63 -8
  59. package/orm/infrastructure/orm.js.map +1 -1
  60. package/orm/infrastructure/ormLibrary.js +8 -8
  61. package/orm/infrastructure/ormLibrary.js.map +1 -1
  62. package/package.json +72 -3
  63. package/query/domain/query.d.ts +2 -0
  64. package/query/domain/query.d.ts.map +1 -1
  65. package/query/domain/query.js.map +1 -1
  66. package/repository/domain/actions.d.ts +2 -1
  67. package/repository/domain/actions.d.ts.map +1 -1
  68. package/repository/domain/actions.js +4 -3
  69. package/repository/domain/actions.js.map +1 -1
  70. package/repository/infrastructure/repository.d.ts +4 -1
  71. package/repository/infrastructure/repository.d.ts.map +1 -1
  72. package/repository/infrastructure/repository.js +9 -4
  73. package/repository/infrastructure/repository.js.map +1 -1
  74. package/sentence/application/facade.d.ts +5 -5
  75. package/sentence/application/facade.d.ts.map +1 -1
  76. package/sentence/application/facade.js +8 -4
  77. package/sentence/application/facade.js.map +1 -1
  78. package/sentence/application/index.d.ts +1 -0
  79. package/sentence/application/index.d.ts.map +1 -1
  80. package/sentence/application/index.js +1 -0
  81. package/sentence/application/index.js.map +1 -1
  82. package/sentence/application/services/sentenceBuilder.d.ts.map +1 -1
  83. package/sentence/application/services/sentenceBuilder.js +4 -1
  84. package/sentence/application/services/sentenceBuilder.js.map +1 -1
  85. package/sentence/application/services/sentenceCompleter.d.ts +6 -0
  86. package/sentence/application/services/sentenceCompleter.d.ts.map +1 -1
  87. package/sentence/application/services/sentenceCompleter.js +41 -15
  88. package/sentence/application/services/sentenceCompleter.js.map +1 -1
  89. package/sentence/application/services/sentenceHelper.js +1 -1
  90. package/sentence/application/services/sentenceHelper.js.map +1 -1
  91. package/sentence/application/services/typeService.d.ts.map +1 -1
  92. package/sentence/application/services/typeService.js +4 -1
  93. package/sentence/application/services/typeService.js.map +1 -1
  94. package/sentence/application/viewSentenceFacade.d.ts +24 -0
  95. package/sentence/application/viewSentenceFacade.d.ts.map +1 -0
  96. package/sentence/application/viewSentenceFacade.js +53 -0
  97. package/sentence/application/viewSentenceFacade.js.map +1 -0
  98. package/sentence/infrastructure/adapters/NoSql/NoSqlDmlBuilder.d.ts.map +1 -1
  99. package/sentence/infrastructure/adapters/NoSql/NoSqlDmlBuilder.js +3 -0
  100. package/sentence/infrastructure/adapters/NoSql/NoSqlDmlBuilder.js.map +1 -1
  101. package/sentence/infrastructure/adapters/base/dmlBuilder.d.ts +7 -0
  102. package/sentence/infrastructure/adapters/base/dmlBuilder.d.ts.map +1 -1
  103. package/sentence/infrastructure/adapters/base/dmlBuilder.js +28 -0
  104. package/sentence/infrastructure/adapters/base/dmlBuilder.js.map +1 -1
  105. package/sentence/infrastructure/facadeBuilder.d.ts.map +1 -1
  106. package/sentence/infrastructure/facadeBuilder.js +4 -1
  107. package/sentence/infrastructure/facadeBuilder.js.map +1 -1
  108. package/shared/infrastructure/helper.d.ts +3 -0
  109. package/shared/infrastructure/helper.d.ts.map +1 -1
  110. package/shared/infrastructure/helper.js +2 -0
  111. package/shared/infrastructure/helper.js.map +1 -1
  112. package/shared/infrastructure/index.d.ts +1 -0
  113. package/shared/infrastructure/index.d.ts.map +1 -1
  114. package/shared/infrastructure/index.js +1 -0
  115. package/shared/infrastructure/index.js.map +1 -1
  116. package/shared/infrastructure/observability/index.d.ts +7 -0
  117. package/shared/infrastructure/observability/index.d.ts.map +1 -0
  118. package/shared/infrastructure/observability/index.js +23 -0
  119. package/shared/infrastructure/observability/index.js.map +1 -0
  120. package/shared/infrastructure/observability/ruleBasedSpanProcessor.d.ts +60 -0
  121. package/shared/infrastructure/observability/ruleBasedSpanProcessor.d.ts.map +1 -0
  122. package/shared/infrastructure/observability/ruleBasedSpanProcessor.js +131 -0
  123. package/shared/infrastructure/observability/ruleBasedSpanProcessor.js.map +1 -0
  124. package/shared/infrastructure/observability/sanitizer.d.ts +7 -0
  125. package/shared/infrastructure/observability/sanitizer.d.ts.map +1 -0
  126. package/shared/infrastructure/observability/sanitizer.js +43 -0
  127. package/shared/infrastructure/observability/sanitizer.js.map +1 -0
  128. package/shared/infrastructure/observability/sdk.d.ts +47 -0
  129. package/shared/infrastructure/observability/sdk.d.ts.map +1 -0
  130. package/shared/infrastructure/observability/sdk.js +251 -0
  131. package/shared/infrastructure/observability/sdk.js.map +1 -0
  132. package/shared/infrastructure/observability/semconv.d.ts +50 -0
  133. package/shared/infrastructure/observability/semconv.d.ts.map +1 -0
  134. package/shared/infrastructure/observability/semconv.js +81 -0
  135. package/shared/infrastructure/observability/semconv.js.map +1 -0
  136. package/shared/infrastructure/observability/telemetry.d.ts +104 -0
  137. package/shared/infrastructure/observability/telemetry.d.ts.map +1 -0
  138. package/shared/infrastructure/observability/telemetry.js +409 -0
  139. package/shared/infrastructure/observability/telemetry.js.map +1 -0
  140. package/shared/infrastructure/observability/traceRules.d.ts +64 -0
  141. package/shared/infrastructure/observability/traceRules.d.ts.map +1 -0
  142. package/shared/infrastructure/observability/traceRules.js +85 -0
  143. package/shared/infrastructure/observability/traceRules.js.map +1 -0
  144. package/stage/application/facade.d.ts +8 -0
  145. package/stage/application/facade.d.ts.map +1 -1
  146. package/stage/application/facade.js +27 -11
  147. package/stage/application/facade.js.map +1 -1
  148. package/stage/application/services/schemaEventService.d.ts +29 -0
  149. package/stage/application/services/schemaEventService.d.ts.map +1 -0
  150. package/stage/application/services/schemaEventService.js +123 -0
  151. package/stage/application/services/schemaEventService.js.map +1 -0
  152. package/stage/application/services/stateService.d.ts +9 -2
  153. package/stage/application/services/stateService.d.ts.map +1 -1
  154. package/stage/application/services/stateService.js +20 -0
  155. package/stage/application/services/stateService.js.map +1 -1
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dbOperationName = exports.dbSystemName = exports.DB_SYSTEM_NAMES = exports.METRIC = exports.ATTR = void 0;
4
+ const base_1 = require("@lambdaorm/base");
5
+ /** The attributes of the OpenTelemetry conventions for databases, and the ones of λORM (prefix lambdaorm.) */
6
+ exports.ATTR = {
7
+ DB_SYSTEM_NAME: 'db.system.name',
8
+ DB_NAMESPACE: 'db.namespace',
9
+ DB_COLLECTION_NAME: 'db.collection.name',
10
+ DB_OPERATION_NAME: 'db.operation.name',
11
+ DB_QUERY_TEXT: 'db.query.text',
12
+ DB_RESPONSE_RETURNED_ROWS: 'db.response.returned_rows',
13
+ SERVER_ADDRESS: 'server.address',
14
+ SERVER_PORT: 'server.port',
15
+ ERROR_TYPE: 'error.type',
16
+ POOL_NAME: 'db.client.connection.pool.name',
17
+ CONNECTION_STATE: 'db.client.connection.state',
18
+ ENDUSER_ID: 'enduser.id',
19
+ SCHEMA: 'lambdaorm.schema',
20
+ STAGE: 'lambdaorm.stage',
21
+ ENTITY: 'lambdaorm.entity',
22
+ ACTION: 'lambdaorm.action',
23
+ CATEGORY: 'lambdaorm.category',
24
+ SOURCE: 'lambdaorm.source',
25
+ DIALECT: 'lambdaorm.dialect',
26
+ EXPRESSION: 'lambdaorm.expression',
27
+ ROWS: 'lambdaorm.rows',
28
+ CACHE_HIT: 'lambdaorm.cache.hit',
29
+ CONSTRAINT: 'lambdaorm.constraint',
30
+ TRANSACTION_RESULT: 'lambdaorm.transaction.result',
31
+ STAGE_ACTION: 'lambdaorm.stage.action',
32
+ CHANGE_KIND: 'lambdaorm.change.kind'
33
+ };
34
+ /** The metrics (docs/OBSERVABILITY.md §6) */
35
+ exports.METRIC = {
36
+ OPERATION_DURATION: 'db.client.operation.duration',
37
+ RETURNED_ROWS: 'db.client.response.returned_rows',
38
+ CONNECTION_COUNT: 'db.client.connection.count',
39
+ CONNECTION_WAIT_TIME: 'db.client.connection.wait_time',
40
+ QUERY_DURATION: 'lambdaorm.query.duration',
41
+ COMPILE_DURATION: 'lambdaorm.query.compile.duration',
42
+ CONSTRAINT_VIOLATIONS: 'lambdaorm.constraint.violations',
43
+ TRANSACTION_DURATION: 'lambdaorm.transaction.duration',
44
+ STAGE_DURATION: 'lambdaorm.stage.operation.duration',
45
+ SCHEMA_LOAD_DURATION: 'lambdaorm.schema.load.duration',
46
+ SCHEMA_CHANGES: 'lambdaorm.schema.changes'
47
+ };
48
+ /** db.system.name of each dialect, the value of the conventions; lambdaorm.dialect keeps the name of λORM */
49
+ exports.DB_SYSTEM_NAMES = {
50
+ [base_1.Dialect.PostgreSQL]: 'postgresql',
51
+ [base_1.Dialect.MySQL]: 'mysql',
52
+ [base_1.Dialect.MariaDB]: 'mariadb',
53
+ [base_1.Dialect.SqlServer]: 'microsoft.sql_server',
54
+ [base_1.Dialect.Oracle]: 'oracle.db',
55
+ [base_1.Dialect.MongoDB]: 'mongodb',
56
+ [base_1.Dialect.SqlLite]: 'sqlite',
57
+ [base_1.Dialect.SQLjs]: 'sqlite'
58
+ };
59
+ const dbSystemName = (dialect) => exports.DB_SYSTEM_NAMES[dialect] ?? 'other_sql';
60
+ exports.dbSystemName = dbSystemName;
61
+ /** the command of MongoDB for each action (its convention names the command) */
62
+ const MONGO_OPERATIONS = {
63
+ [base_1.SentenceAction.select]: 'find',
64
+ [base_1.SentenceAction.insert]: 'insert',
65
+ [base_1.SentenceAction.insertConditional]: 'insert',
66
+ [base_1.SentenceAction.bulkInsert]: 'insert',
67
+ [base_1.SentenceAction.update]: 'update',
68
+ [base_1.SentenceAction.upsert]: 'update',
69
+ [base_1.SentenceAction.bulkMerge]: 'update',
70
+ [base_1.SentenceAction.delete]: 'delete',
71
+ [base_1.SentenceAction.bulkDelete]: 'delete'
72
+ };
73
+ /** db.operation.name: the SQL verb (SELECT, INSERT…), or the command of MongoDB */
74
+ const dbOperationName = (dialect, action, category) => {
75
+ if (dialect === base_1.Dialect.MongoDB) {
76
+ return MONGO_OPERATIONS[action] ?? action;
77
+ }
78
+ return (category || action).toUpperCase();
79
+ };
80
+ exports.dbOperationName = dbOperationName;
81
+ //# sourceMappingURL=semconv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../../../../src/lib/shared/infrastructure/observability/semconv.ts"],"names":[],"mappings":";;;AAAA,0CAAyD;AAEzD,8GAA8G;AACjG,QAAA,IAAI,GAAG;IACnB,cAAc,EAAE,gBAAgB;IAChC,YAAY,EAAE,cAAc;IAC5B,kBAAkB,EAAE,oBAAoB;IACxC,iBAAiB,EAAE,mBAAmB;IACtC,aAAa,EAAE,eAAe;IAC9B,yBAAyB,E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or } from '@lambdaorm/base';
4
+ export declare const SCOPE_NAME = "@lambdaorm/lib";
5
+ /** what a span or a metric needs of a sentence (a Query of λORM) */
6
+ export interface SentenceTelemetry {
7
+ entity: string;
8
+ action: string;
9
+ category: string;
10
+ type?: string;
11
+ dialect: string;
12
+ source: string;
13
+ sentence: string;
14
+ /** the sentence with its constants as parameters, when it was built (queryText: sanitized) */
15
+ sanitized?: string;
16
+ includes?: {
17
+ query: SentenceTelemetry;
18
+ }[];
19
+ }
20
+ /** the table (or collection) of the entity in the source, for db.collection.name */
21
+ export interface SentenceTarget {
22
+ collection?: string;
23
+ }
24
+ export interface ServerInfo {
25
+ address?: string;
26
+ port?: number;
27
+ namespace?: string;
28
+ }
29
+ /** an object whose connections in use can be counted (a pool of a source) */
30
+ export interface TrackedPool {
31
+ readonly name: string;
32
+ readonly used: number;
33
+ }
34
+ /** error.type: the code of the database when there is one, if not the name of the error */
35
+ export declare const errorType: (error: any) => string;
36
+ /**
37
+ * The spans and metrics of λORM, with the API of OpenTelemetry: without an SDK they do nothing. Disabled (the default,
38
+ * and without infrastructure.observability) every method runs what it receives and nothing else.
39
+ */
40
+ export declare class Telemetry {
41
+ private config?;
42
+ private schema;
43
+ private _tracer?;
44
+ private _meter?;
45
+ private instruments?;
46
+ private readonly pools;
47
+ private rules?;
48
+ /** set by compiled(), read right after the (synchronous) build of the expression */
49
+ private lastCacheHit?;
50
+ /** set from the schema loaded (and the OTEL_* variables); can be called again when the schema is reloaded */
51
+ /** entities: observability.trace of each entity (entityTraceConditions of @lambdaorm/base), which decides for it */
52
+ configure(config: ResolvedObservability | undefined, schema?: string, exp?: Expressions, warn?: (message: string) => void, entities?: Record<string, string>): void;
53
+ get tracing(): boolean;
54
+ get measuring(): boolean;
55
+ get active(): boolean;
56
+ get queryText(): QueryTextMode;
57
+ /** build the sanitized text of the sentences when compiling (only if a span will use it) */
58
+ get sanitizeSentences(): boolean;
59
+ get tracer(): Tracer;
60
+ get meter(): Meter;
61
+ /** runs fn inside a span when tracing; the span ends with fn, with the error recorded (without data) if it fails */
62
+ span<T>(name: string, kind: SpanKind, attributes: Attributes, fn: (span?: Span) => Promise<T>, startTime?: number): Promise<T>;
63
+ /**
64
+ * the root span of an expression (lambdaorm.execute) and lambdaorm.query.duration. The span starts after compiling
65
+ * (the rules need the entity and the action) with the time of before compiling. The rules decide before running when
66
+ * they can: no span at all when no rule can keep it; if not, they decide when it ends (lambdaorm.trace.record).
67
+ */
68
+ execute<T, Q extends SentenceTelemetry>(expression: string, options: {
69
+ stage?: string;
70
+ actor?: Actor;
71
+ }, build: () => Q, run: (query: Q) => Promise<T>): Promise<T>;
72
+ /** compiling an expression to sentences (lambdaorm.query.compile.duration, lambdaorm.cache.hit) */
73
+ compiled(seconds: number, cacheHit: boolean): void;
74
+ /** a span of the database for a sentence sent to a source, db.client.operation.duration and returned_rows */
75
+ sentence<T>(query: SentenceTelemetry, stage: string | undefined, server: ServerInfo & SentenceTarget, run: () => Promise<T>): Promise<T>;
76
+ /** a transaction (lambdaorm.transaction): commit when run ends, rollback when it fails */
77
+ transaction<T>(stage: string | undefined, run: () => Promise<T>): Promise<T>;
78
+ /** a command of a stage (lambdaorm.stage.<action>) and lambdaorm.stage.operation.duration */
79
+ stage<T>(action: string, stage: string | undefined, run: () => Promise<T>): Promise<T>;
80
+ /** a constraint of the model that rejected a value (lambdaorm.constraint.violations) */
81
+ constraintViolation(entity: string, constraint: string): void;
82
+ /** a schema.change (lambdaorm.schema.changes) */
83
+ schemaChanged(kind: string): void;
84
+ /** loading and extending the schema (lambdaorm.schema.load.duration) */
85
+ schemaLoaded(seconds: number): void;
86
+ /** the time to get a connection of a pool (db.client.connection.wait_time) */
87
+ connectionAcquired(pool: string, seconds: number): void;
88
+ /** the pool is counted by db.client.connection.count while it is tracked */
89
+ trackPool(pool: TrackedPool): void;
90
+ untrackPool(pool: TrackedPool): void;
91
+ private createInstruments;
92
+ private queryAttributes;
93
+ private entityFiltered;
94
+ private expressionText;
95
+ private sentenceText;
96
+ /** the variables of the rules that the sentence gives (the ones of the condition of a source of a stage) */
97
+ private sentenceVariables;
98
+ /** the sources the expression touches: the one of its sentence and the ones of its includes */
99
+ private sources;
100
+ private rows;
101
+ }
102
+ /** a telemetry that does nothing, for the helpers built without one (tests) */
103
+ export declare const DISABLED_TELEMETRY: Telemetry;
104
+ //# sourceMappingURL=telemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../../../../src/lib/shared/infrastructure/observability/telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EACqC,IAAI,EAAE,QAAQ,EAAkB,MAAM,EAAE,KAAK,EAAsB,UAAU,EAExH,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAS7E,eAAO,MAAM,UAAU,mBAAmB,CAAA;AAU1C,oEAAoE;AACpE,MAAM,WAAW,iBAAiB;IACjC,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,8FAA8F;IAC9F,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE;QAAE,KAAK,EAAE,iBAAiB,CAAA;KAAE,EAAE,CAAA;CACzC;AAED,oFAAoF;AACpF,MAAM,WAAW,cAAc;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,UAAU;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,6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;IACjE,YAAY,CAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAI3C,8EAA8E;IACvE,kBAAkB,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAI/D,4EAA4E;IACrE,SAAS,CAAE,IAAI,EAAE,WAAW,GAAG,IAAI;IAInC,WAAW,CAAE,IAAI,EAAE,WAAW,GAAG,IAAI;IAI5C,OAAO,CAAC,iBAAiB;IAwBzB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,YAAY;IASpB,4GAA4G;IAC5G,OAAO,CAAC,iBAAiB;IAgBzB,+FAA+F;IAC/F,OAAO,CAAC,OAAO;IAQf,OAAO,CAAC,IAAI;CAKZ;AAED,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB,WAAkB,CAAA"}
@@ -0,0 +1,409 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DISABLED_TELEMETRY = exports.Telemetry = exports.errorType = exports.SCOPE_NAME = void 0;
4
+ const api_1 = require("@opentelemetry/api");
5
+ const semconv_1 = require("./semconv");
6
+ const sanitizer_1 = require("./sanitizer");
7
+ const traceRules_1 = require("./traceRules");
8
+ const ruleBasedSpanProcessor_1 = require("./ruleBasedSpanProcessor");
9
+ /** inside an expression that the rules don't trace: no span of λORM is created */
10
+ const TRACE_OFF = (0, api_1.createContextKey)('lambdaorm.trace.off');
11
+ exports.SCOPE_NAME = '@lambdaorm/lib';
12
+ const SCOPE_VERSION = (() => {
13
+ try {
14
+ // src/lib/shared/infrastructure/observability and build/lib/shared/infrastructure/observability: five levels
15
+ return require('../../../../../package.json').version;
16
+ }
17
+ catch {
18
+ return undefined;
19
+ }
20
+ })();
21
+ /** error.type: the code of the database when there is one, if not the name of the error */
22
+ const errorType = (error) => {
23
+ if (error && typeof error.code === 'string' && error.code !== '')
24
+ return error.code;
25
+ return error?.name || error?.constructor?.name || 'Error';
26
+ };
27
+ exports.errorType = errorType;
28
+ /**
29
+ * The message of an error that can go in a span: the errors of λORM carry the data of the sentence in their message
30
+ * (they can be personal data), so only their name goes, and the constraint for a ValidationError.
31
+ */
32
+ const safeMessage = (error) => {
33
+ if (error?.constraint)
34
+ return `${error.name}: ${error.constraint}`;
35
+ return (0, exports.errorType)(error);
36
+ };
37
+ /**
38
+ * The spans and metrics of λORM, with the API of OpenTelemetry: without an SDK they do nothing. Disabled (the default,
39
+ * and without infrastructure.observability) every method runs what it receives and nothing else.
40
+ */
41
+ class Telemetry {
42
+ constructor() {
43
+ this.schema = '';
44
+ this.pools = new Set();
45
+ }
46
+ /** set from the schema loaded (and the OTEL_* variables); can be called again when the schema is reloaded */
47
+ /** entities: observability.trace of each entity (entityTraceConditions of @lambdaorm/base), which decides for it */
48
+ configure(config, schema = '', exp, warn, entities = {}) {
49
+ this.config = config;
50
+ this.schema = schema;
51
+ this.rules = config && exp ? new traceRules_1.TraceRules(config.traces.rules, exp, warn, entities) : undefined;
52
+ this.instruments = undefined;
53
+ // taken again: the providers may have changed (an SDK started for this schema)
54
+ this._tracer = undefined;
55
+ this._meter = undefined;
56
+ if (this.measuring) {
57
+ this.createInstruments();
58
+ }
59
+ }
60
+ get tracing() {
61
+ return this.config?.traces.enabled === true;
62
+ }
63
+ get measuring() {
64
+ return this.config?.metrics.enabled === true;
65
+ }
66
+ get active() {
67
+ return this.tracing || this.measuring;
68
+ }
69
+ get queryText() {
70
+ return this.config?.traces.queryText ?? 'sanitized';
71
+ }
72
+ /** build the sanitized text of the sentences when compiling (only if a span will use it) */
73
+ get sanitizeSentences() {
74
+ return this.tracing && this.queryText === 'sanitized';
75
+ }
76
+ get tracer() {
77
+ if (!this._tracer)
78
+ this._tracer = api_1.trace.getTracer(exports.SCOPE_NAME, SCOPE_VERSION);
79
+ return this._tracer;
80
+ }
81
+ get meter() {
82
+ if (!this._meter)
83
+ this._meter = api_1.metrics.getMeter(exports.SCOPE_NAME, SCOPE_VERSION);
84
+ return this._meter;
85
+ }
86
+ /** runs fn inside a span when tracing; the span ends with fn, with the error recorded (without data) if it fails */
87
+ async span(name, kind, attributes, fn, startTime) {
88
+ if (!this.tracing || api_1.context.active().getValue(TRACE_OFF) === true) {
89
+ return fn(undefined);
90
+ }
91
+ return this.tracer.startActiveSpan(name, { kind, attributes, startTime }, async (span) => {
92
+ try {
93
+ return await fn(span);
94
+ }
95
+ catch (error) {
96
+ span.setAttribute(semconv_1.ATTR.ERROR_TYPE, (0, exports.errorType)(error));
97
+ span.recordException({ name: error?.name ?? 'Error', message: safeMessage(error) });
98
+ span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: safeMessage(error) });
99
+ throw error;
100
+ }
101
+ finally {
102
+ span.end();
103
+ }
104
+ });
105
+ }
106
+ /**
107
+ * the root span of an expression (lambdaorm.execute) and lambdaorm.query.duration. The span starts after compiling
108
+ * (the rules need the entity and the action) with the time of before compiling. The rules decide before running when
109
+ * they can: no span at all when no rule can keep it; if not, they decide when it ends (lambdaorm.trace.record).
110
+ */
111
+ async execute(expression, options, build, run) {
112
+ const stage = options.stage;
113
+ // enduser.id: the credential, or an id of the user; never an email
114
+ const user = options.actor?.credential ?? options.actor?.user ?? null;
115
+ if (!this.active) {
116
+ return run(build());
117
+ }
118
+ const start = performance.now();
119
+ const startTime = Date.now();
120
+ const attributes = { [semconv_1.ATTR.SCHEMA]: this.schema };
121
+ if (stage)
122
+ attributes[semconv_1.ATTR.STAGE] = stage;
123
+ let query;
124
+ let error;
125
+ try {
126
+ this.lastCacheHit = undefined;
127
+ query = build();
128
+ const cacheHit = this.lastCacheHit;
129
+ const tracing = this.tracing && api_1.context.active().getValue(TRACE_OFF) !== true;
130
+ const sentence = tracing ? this.sentenceVariables(query, stage) : undefined;
131
+ const decision = sentence && this.rules ? this.rules.before(sentence) : { kind: 'decided', record: true, rule: -1 };
132
+ if (!tracing || (decision.kind === 'decided' && !decision.record)) {
133
+ return tracing
134
+ ? await api_1.context.with(api_1.context.active().setValue(TRACE_OFF, true), () => run(query))
135
+ : await run(query);
136
+ }
137
+ const spanAttributes = { ...attributes, ...this.queryAttributes(query) };
138
+ if (cacheHit !== undefined)
139
+ spanAttributes[semconv_1.ATTR.CACHE_HIT] = cacheHit;
140
+ const text = this.expressionText(expression);
141
+ if (text !== undefined)
142
+ spanAttributes[semconv_1.ATTR.EXPRESSION] = text;
143
+ if (user)
144
+ spanAttributes[semconv_1.ATTR.ENDUSER_ID] = user;
145
+ if (decision.kind === 'decided') {
146
+ spanAttributes[ruleBasedSpanProcessor_1.TRACE_RECORD] = true;
147
+ spanAttributes[ruleBasedSpanProcessor_1.TRACE_RULE] = decision.rule;
148
+ }
149
+ const _query = query;
150
+ return await this.span('lambdaorm.execute', api_1.SpanKind.INTERNAL, spanAttributes, async (span) => {
151
+ let result;
152
+ let failure;
153
+ try {
154
+ result = await run(_query);
155
+ return result;
156
+ }
157
+ catch (e) {
158
+ failure = e;
159
+ throw e;
160
+ }
161
+ finally {
162
+ const rows = this.rows(result);
163
+ if (span && rows !== undefined)
164
+ span.setAttribute(semconv_1.ATTR.ROWS, rows);
165
+ if (span && decision.kind === 'pending' && this.rules && sentence) {
166
+ const final = this.rules.after(decision.from, {
167
+ ...sentence,
168
+ sources: this.sources(_query),
169
+ durationMs: performance.now() - start,
170
+ rows: rows ?? null,
171
+ error: failure ? (0, exports.errorType)(failure) : null,
172
+ user
173
+ });
174
+ span.setAttribute(ruleBasedSpanProcessor_1.TRACE_RECORD, final.record);
175
+ span.setAttribute(ruleBasedSpanProcessor_1.TRACE_RULE, final.rule);
176
+ }
177
+ }
178
+ }, startTime);
179
+ }
180
+ catch (e) {
181
+ error = e;
182
+ throw e;
183
+ }
184
+ finally {
185
+ if (this.instruments) {
186
+ const metric = { ...attributes, ...(query ? this.queryAttributes(query) : {}) };
187
+ if (error)
188
+ metric[semconv_1.ATTR.ERROR_TYPE] = (0, exports.errorType)(error);
189
+ this.instruments.queryDuration.record((performance.now() - start) / 1000, this.entityFiltered(metric));
190
+ }
191
+ }
192
+ }
193
+ /** compiling an expression to sentences (lambdaorm.query.compile.duration, lambdaorm.cache.hit) */
194
+ compiled(seconds, cacheHit) {
195
+ this.lastCacheHit = cacheHit;
196
+ this.instruments?.compileDuration.record(seconds, { [semconv_1.ATTR.SCHEMA]: this.schema, [semconv_1.ATTR.CACHE_HIT]: cacheHit });
197
+ }
198
+ /** a span of the database for a sentence sent to a source, db.client.operation.duration and returned_rows */
199
+ async sentence(query, stage, server, run) {
200
+ if (!this.active) {
201
+ return run();
202
+ }
203
+ const start = performance.now();
204
+ const operation = (0, semconv_1.dbOperationName)(query.dialect, query.action, query.category);
205
+ const attributes = {
206
+ [semconv_1.ATTR.DB_SYSTEM_NAME]: (0, semconv_1.dbSystemName)(query.dialect),
207
+ [semconv_1.ATTR.DIALECT]: query.dialect,
208
+ [semconv_1.ATTR.DB_OPERATION_NAME]: operation,
209
+ [semconv_1.ATTR.SOURCE]: query.source
210
+ };
211
+ const collection = server.collection ?? query.entity;
212
+ if (collection)
213
+ attributes[semconv_1.ATTR.DB_COLLECTION_NAME] = collection;
214
+ if (stage)
215
+ attributes[semconv_1.ATTR.STAGE] = stage;
216
+ if (server.namespace)
217
+ attributes[semconv_1.ATTR.DB_NAMESPACE] = server.namespace;
218
+ if (server.address)
219
+ attributes[semconv_1.ATTR.SERVER_ADDRESS] = server.address;
220
+ let error;
221
+ let result;
222
+ try {
223
+ const spanAttributes = { ...attributes };
224
+ if (server.port)
225
+ spanAttributes[semconv_1.ATTR.SERVER_PORT] = server.port;
226
+ if (query.entity)
227
+ spanAttributes[semconv_1.ATTR.ENTITY] = query.entity;
228
+ const text = this.sentenceText(query);
229
+ if (text !== undefined)
230
+ spanAttributes[semconv_1.ATTR.DB_QUERY_TEXT] = text;
231
+ const name = collection ? `${operation} ${collection}` : operation;
232
+ result = await this.span(name, api_1.SpanKind.CLIENT, spanAttributes, async (span) => {
233
+ const value = await run();
234
+ if (span) {
235
+ if (Array.isArray(value))
236
+ span.setAttribute(semconv_1.ATTR.DB_RESPONSE_RETURNED_ROWS, value.length);
237
+ else if (typeof value === 'number')
238
+ span.setAttribute(semconv_1.ATTR.ROWS, value);
239
+ }
240
+ return value;
241
+ });
242
+ return result;
243
+ }
244
+ catch (e) {
245
+ error = e;
246
+ throw e;
247
+ }
248
+ finally {
249
+ if (this.instruments) {
250
+ if (error)
251
+ attributes[semconv_1.ATTR.ERROR_TYPE] = (0, exports.errorType)(error);
252
+ this.instruments.operationDuration.record((performance.now() - start) / 1000, attributes);
253
+ if (Array.isArray(result)) {
254
+ this.instruments.returnedRows.record(result.length, attributes);
255
+ }
256
+ }
257
+ }
258
+ }
259
+ /** a transaction (lambdaorm.transaction): commit when run ends, rollback when it fails */
260
+ async transaction(stage, run) {
261
+ if (!this.active) {
262
+ return run();
263
+ }
264
+ const start = performance.now();
265
+ const attributes = { [semconv_1.ATTR.SCHEMA]: this.schema };
266
+ if (stage)
267
+ attributes[semconv_1.ATTR.STAGE] = stage;
268
+ let failed = false;
269
+ try {
270
+ return await this.span('lambdaorm.transaction', api_1.SpanKind.INTERNAL, attributes, async () => run());
271
+ }
272
+ catch (error) {
273
+ failed = true;
274
+ throw error;
275
+ }
276
+ finally {
277
+ this.instruments?.transactionDuration.record((performance.now() - start) / 1000, { ...attributes, [semconv_1.ATTR.TRANSACTION_RESULT]: failed ? 'rollback' : 'commit' });
278
+ }
279
+ }
280
+ /** a command of a stage (lambdaorm.stage.<action>) and lambdaorm.stage.operation.duration */
281
+ async stage(action, stage, run) {
282
+ if (!this.active) {
283
+ return run();
284
+ }
285
+ const start = performance.now();
286
+ const attributes = { [semconv_1.ATTR.SCHEMA]: this.schema, [semconv_1.ATTR.STAGE_ACTION]: action };
287
+ if (stage)
288
+ attributes[semconv_1.ATTR.STAGE] = stage;
289
+ let error;
290
+ try {
291
+ return await this.span(`lambdaorm.stage.${action}`, api_1.SpanKind.INTERNAL, attributes, async () => run());
292
+ }
293
+ catch (e) {
294
+ error = e;
295
+ throw e;
296
+ }
297
+ finally {
298
+ const metric = { ...attributes };
299
+ if (error)
300
+ metric[semconv_1.ATTR.ERROR_TYPE] = (0, exports.errorType)(error);
301
+ this.instruments?.stageDuration.record((performance.now() - start) / 1000, metric);
302
+ }
303
+ }
304
+ /** a constraint of the model that rejected a value (lambdaorm.constraint.violations) */
305
+ constraintViolation(entity, constraint) {
306
+ this.instruments?.constraintViolations.add(1, this.entityFiltered({ [semconv_1.ATTR.ENTITY]: entity, [semconv_1.ATTR.CONSTRAINT]: constraint }));
307
+ }
308
+ /** a schema.change (lambdaorm.schema.changes) */
309
+ schemaChanged(kind) {
310
+ this.instruments?.schemaChanges.add(1, { [semconv_1.ATTR.SCHEMA]: this.schema, [semconv_1.ATTR.CHANGE_KIND]: kind });
311
+ }
312
+ /** loading and extending the schema (lambdaorm.schema.load.duration) */
313
+ schemaLoaded(seconds) {
314
+ this.instruments?.schemaLoadDuration.record(seconds, { [semconv_1.ATTR.SCHEMA]: this.schema });
315
+ }
316
+ /** the time to get a connection of a pool (db.client.connection.wait_time) */
317
+ connectionAcquired(pool, seconds) {
318
+ this.instruments?.connectionWait.record(seconds, { [semconv_1.ATTR.POOL_NAME]: pool });
319
+ }
320
+ /** the pool is counted by db.client.connection.count while it is tracked */
321
+ trackPool(pool) {
322
+ this.pools.add(pool);
323
+ }
324
+ untrackPool(pool) {
325
+ this.pools.delete(pool);
326
+ }
327
+ createInstruments() {
328
+ const buckets = this.config?.metrics.histogramBuckets;
329
+ const histogram = (name, description, unit = 's', advice = true) => this.meter.createHistogram(name, { description, unit, advice: advice && buckets ? { explicitBucketBoundaries: buckets } : undefined });
330
+ this.instruments = {
331
+ operationDuration: histogram(semconv_1.METRIC.OPERATION_DURATION, 'Duration of database client operations'),
332
+ returnedRows: histogram(semconv_1.METRIC.RETURNED_ROWS, 'The actual number of records returned by the database operation', '{row}', false),
333
+ connectionWait: histogram(semconv_1.METRIC.CONNECTION_WAIT_TIME, 'The time it took to obtain an open connection from the pool'),
334
+ queryDuration: histogram(semconv_1.METRIC.QUERY_DURATION, 'The whole expression: compile, plan and run on all its sources'),
335
+ compileDuration: histogram(semconv_1.METRIC.COMPILE_DURATION, 'Compiling an expression to sentences'),
336
+ constraintViolations: this.meter.createCounter(semconv_1.METRIC.CONSTRAINT_VIOLATIONS, { description: 'Constraints of the model that rejected a value', unit: '{violation}' }),
337
+ transactionDuration: histogram(semconv_1.METRIC.TRANSACTION_DURATION, 'Transactions'),
338
+ stageDuration: histogram(semconv_1.METRIC.STAGE_DURATION, 'Commands of a stage'),
339
+ schemaLoadDuration: histogram(semconv_1.METRIC.SCHEMA_LOAD_DURATION, 'Loading and extending the schema'),
340
+ schemaChanges: this.meter.createCounter(semconv_1.METRIC.SCHEMA_CHANGES, { description: 'Changes of the schema (the events schema.change)', unit: '{change}' })
341
+ };
342
+ const count = this.meter.createObservableUpDownCounter(semconv_1.METRIC.CONNECTION_COUNT, { description: 'The number of connections that are currently in state described by the state attribute', unit: '{connection}' });
343
+ count.addCallback((result) => {
344
+ for (const pool of this.pools) {
345
+ result.observe(pool.used, { [semconv_1.ATTR.POOL_NAME]: pool.name, [semconv_1.ATTR.CONNECTION_STATE]: 'used' });
346
+ }
347
+ });
348
+ }
349
+ queryAttributes(query) {
350
+ return { [semconv_1.ATTR.ENTITY]: query.entity, [semconv_1.ATTR.ACTION]: query.action, [semconv_1.ATTR.CATEGORY]: query.category };
351
+ }
352
+ entityFiltered(attributes) {
353
+ if (this.config?.metrics.entityAttribute === false) {
354
+ delete attributes[semconv_1.ATTR.ENTITY];
355
+ }
356
+ return attributes;
357
+ }
358
+ expressionText(expression) {
359
+ switch (this.queryText) {
360
+ case 'full': return expression;
361
+ case 'sanitized': return (0, sanitizer_1.sanitizeExpression)(expression);
362
+ default: return undefined;
363
+ }
364
+ }
365
+ sentenceText(query) {
366
+ switch (this.queryText) {
367
+ case 'full': return query.sentence;
368
+ // without the sanitized text (compiled before tracing was on) nothing goes: never the sentence with its values
369
+ case 'sanitized': return query.sanitized;
370
+ default: return undefined;
371
+ }
372
+ }
373
+ /** the variables of the rules that the sentence gives (the ones of the condition of a source of a stage) */
374
+ sentenceVariables(query, stage) {
375
+ const read = query.category === 'select';
376
+ return {
377
+ entity: query.entity,
378
+ action: query.action,
379
+ category: query.category,
380
+ type: query.type ?? '',
381
+ read,
382
+ write: !read,
383
+ ddl: query.type === 'ddl',
384
+ dml: query.type === 'dml' || query.type === 'dql',
385
+ schema: this.schema,
386
+ stage: stage ?? ''
387
+ };
388
+ }
389
+ /** the sources the expression touches: the one of its sentence and the ones of its includes */
390
+ sources(query, found = new Set()) {
391
+ if (query.source)
392
+ found.add(query.source);
393
+ for (const include of query.includes ?? []) {
394
+ this.sources(include.query, found);
395
+ }
396
+ return [...found];
397
+ }
398
+ rows(result) {
399
+ if (Array.isArray(result))
400
+ return result.length;
401
+ if (typeof result === 'number')
402
+ return result;
403
+ return undefined;
404
+ }
405
+ }
406
+ exports.Telemetry = Telemetry;
407
+ /** a telemetry that does nothing, for the helpers built without one (tests) */
408
+ exports.DISABLED_TELEMETRY = new Telemetry();
409
+ //# sourceMappingURL=telemetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../../../../src/lib/shared/infrastructure/observability/telemetry.ts"],"names":[],"mappings":";;;AAAA,4CAG2B;AAG3B,uCAAuE;AACvE,2CAAgD;AAChD,6CAAmF;AACnF,qEAAmE;AAEnE,kFAAkF;AAClF,MAAM,SAAS,GAAG,IAAA,sBAAgB,EAAC,qBAAqB,CAAC,CAAA;AAE5C,QAAA,UAAU,GAAG,gBAAgB,CAAA;AAC1C,MAAM,aAAa,GAAuB,CAAC,GAAG,EAAE;IAC/C,IAAI,CAAC;QACJ,6GAA6G;QAC7G,OAAO,OAAO,CAAC,6BAA6B,CAAC,CAAC,OAAO,CAAA;IACtD,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAA;IACjB,CAAC;AACF,CAAC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