@itwin/core-bentley 4.0.0-dev.52 → 4.0.0-dev.55

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 (190) hide show
  1. package/lib/cjs/AccessToken.d.ts +10 -10
  2. package/lib/cjs/AccessToken.d.ts.map +1 -1
  3. package/lib/cjs/AccessToken.js +9 -9
  4. package/lib/cjs/Assert.d.ts +25 -25
  5. package/lib/cjs/Assert.js +45 -45
  6. package/lib/cjs/BeEvent.d.ts +81 -81
  7. package/lib/cjs/BeEvent.d.ts.map +1 -1
  8. package/lib/cjs/BeEvent.js +156 -156
  9. package/lib/cjs/BeSQLite.d.ts +172 -172
  10. package/lib/cjs/BeSQLite.js +185 -185
  11. package/lib/cjs/BentleyError.d.ts +378 -378
  12. package/lib/cjs/BentleyError.d.ts.map +1 -1
  13. package/lib/cjs/BentleyError.js +703 -703
  14. package/lib/cjs/BentleyLoggerCategory.d.ts +11 -11
  15. package/lib/cjs/BentleyLoggerCategory.js +19 -19
  16. package/lib/cjs/ByteStream.d.ts +110 -110
  17. package/lib/cjs/ByteStream.js +159 -159
  18. package/lib/cjs/ClassUtils.d.ts +14 -14
  19. package/lib/cjs/ClassUtils.js +27 -27
  20. package/lib/cjs/Compare.d.ts +47 -47
  21. package/lib/cjs/Compare.d.ts.map +1 -1
  22. package/lib/cjs/Compare.js +75 -75
  23. package/lib/cjs/CompressedId64Set.d.ts +134 -134
  24. package/lib/cjs/CompressedId64Set.d.ts.map +1 -1
  25. package/lib/cjs/CompressedId64Set.js +428 -428
  26. package/lib/cjs/CompressedId64Set.js.map +1 -1
  27. package/lib/cjs/Dictionary.d.ts +125 -125
  28. package/lib/cjs/Dictionary.js +203 -203
  29. package/lib/cjs/Disposable.d.ts +80 -80
  30. package/lib/cjs/Disposable.d.ts.map +1 -1
  31. package/lib/cjs/Disposable.js +120 -120
  32. package/lib/cjs/Id.d.ts +285 -285
  33. package/lib/cjs/Id.d.ts.map +1 -1
  34. package/lib/cjs/Id.js +643 -643
  35. package/lib/cjs/IndexMap.d.ts +65 -65
  36. package/lib/cjs/IndexMap.js +91 -91
  37. package/lib/cjs/JsonSchema.d.ts +77 -77
  38. package/lib/cjs/JsonSchema.d.ts.map +1 -1
  39. package/lib/cjs/JsonSchema.js +9 -9
  40. package/lib/cjs/JsonUtils.d.ts +78 -78
  41. package/lib/cjs/JsonUtils.js +151 -151
  42. package/lib/cjs/LRUMap.d.ts +129 -129
  43. package/lib/cjs/LRUMap.js +333 -333
  44. package/lib/cjs/LRUMap.js.map +1 -1
  45. package/lib/cjs/Logger.d.ts +143 -143
  46. package/lib/cjs/Logger.d.ts.map +1 -1
  47. package/lib/cjs/Logger.js +256 -256
  48. package/lib/cjs/Logger.js.map +1 -1
  49. package/lib/cjs/ObservableSet.d.ts +23 -23
  50. package/lib/cjs/ObservableSet.js +51 -51
  51. package/lib/cjs/OneAtATimeAction.d.ts +31 -31
  52. package/lib/cjs/OneAtATimeAction.js +94 -94
  53. package/lib/cjs/OrderedId64Iterable.d.ts +74 -74
  54. package/lib/cjs/OrderedId64Iterable.d.ts.map +1 -1
  55. package/lib/cjs/OrderedId64Iterable.js +235 -235
  56. package/lib/cjs/OrderedSet.d.ts +40 -40
  57. package/lib/cjs/OrderedSet.js +64 -64
  58. package/lib/cjs/PriorityQueue.d.ts +70 -70
  59. package/lib/cjs/PriorityQueue.d.ts.map +1 -1
  60. package/lib/cjs/PriorityQueue.js +140 -140
  61. package/lib/cjs/ProcessDetector.d.ts +59 -59
  62. package/lib/cjs/ProcessDetector.js +71 -71
  63. package/lib/cjs/SortedArray.d.ts +236 -236
  64. package/lib/cjs/SortedArray.d.ts.map +1 -1
  65. package/lib/cjs/SortedArray.js +315 -315
  66. package/lib/cjs/StatusCategory.d.ts +30 -30
  67. package/lib/cjs/StatusCategory.d.ts.map +1 -1
  68. package/lib/cjs/StatusCategory.js +460 -460
  69. package/lib/cjs/StatusCategory.js.map +1 -1
  70. package/lib/cjs/StringUtils.d.ts +22 -22
  71. package/lib/cjs/StringUtils.js +148 -148
  72. package/lib/cjs/Time.d.ts +122 -122
  73. package/lib/cjs/Time.js +152 -152
  74. package/lib/cjs/Time.js.map +1 -1
  75. package/lib/cjs/Tracing.d.ts +40 -40
  76. package/lib/cjs/Tracing.js +127 -127
  77. package/lib/cjs/TupleKeyedMap.d.ts +36 -36
  78. package/lib/cjs/TupleKeyedMap.js +102 -102
  79. package/lib/cjs/TypedArrayBuilder.d.ts +155 -155
  80. package/lib/cjs/TypedArrayBuilder.d.ts.map +1 -1
  81. package/lib/cjs/TypedArrayBuilder.js +206 -206
  82. package/lib/cjs/UnexpectedErrors.d.ts +43 -43
  83. package/lib/cjs/UnexpectedErrors.d.ts.map +1 -1
  84. package/lib/cjs/UnexpectedErrors.js +68 -68
  85. package/lib/cjs/UnexpectedErrors.js.map +1 -1
  86. package/lib/cjs/UtilityTypes.d.ts +112 -112
  87. package/lib/cjs/UtilityTypes.d.ts.map +1 -1
  88. package/lib/cjs/UtilityTypes.js +40 -40
  89. package/lib/cjs/YieldManager.d.ts +18 -18
  90. package/lib/cjs/YieldManager.js +34 -34
  91. package/lib/cjs/core-bentley.d.ts +74 -74
  92. package/lib/cjs/core-bentley.js +94 -90
  93. package/lib/cjs/core-bentley.js.map +1 -1
  94. package/lib/cjs/partitionArray.d.ts +21 -21
  95. package/lib/cjs/partitionArray.js +43 -43
  96. package/lib/esm/AccessToken.d.ts +10 -10
  97. package/lib/esm/AccessToken.d.ts.map +1 -1
  98. package/lib/esm/AccessToken.js +8 -8
  99. package/lib/esm/Assert.d.ts +25 -25
  100. package/lib/esm/Assert.js +41 -41
  101. package/lib/esm/BeEvent.d.ts +81 -81
  102. package/lib/esm/BeEvent.d.ts.map +1 -1
  103. package/lib/esm/BeEvent.js +150 -150
  104. package/lib/esm/BeSQLite.d.ts +172 -172
  105. package/lib/esm/BeSQLite.js +182 -182
  106. package/lib/esm/BentleyError.d.ts +378 -378
  107. package/lib/esm/BentleyError.d.ts.map +1 -1
  108. package/lib/esm/BentleyError.js +699 -699
  109. package/lib/esm/BentleyLoggerCategory.d.ts +11 -11
  110. package/lib/esm/BentleyLoggerCategory.js +16 -16
  111. package/lib/esm/ByteStream.d.ts +110 -110
  112. package/lib/esm/ByteStream.js +155 -155
  113. package/lib/esm/ClassUtils.d.ts +14 -14
  114. package/lib/esm/ClassUtils.js +22 -22
  115. package/lib/esm/Compare.d.ts +47 -47
  116. package/lib/esm/Compare.d.ts.map +1 -1
  117. package/lib/esm/Compare.js +63 -63
  118. package/lib/esm/CompressedId64Set.d.ts +134 -134
  119. package/lib/esm/CompressedId64Set.d.ts.map +1 -1
  120. package/lib/esm/CompressedId64Set.js +423 -423
  121. package/lib/esm/CompressedId64Set.js.map +1 -1
  122. package/lib/esm/Dictionary.d.ts +125 -125
  123. package/lib/esm/Dictionary.js +199 -199
  124. package/lib/esm/Disposable.d.ts +80 -80
  125. package/lib/esm/Disposable.d.ts.map +1 -1
  126. package/lib/esm/Disposable.js +112 -112
  127. package/lib/esm/Id.d.ts +285 -285
  128. package/lib/esm/Id.d.ts.map +1 -1
  129. package/lib/esm/Id.js +639 -639
  130. package/lib/esm/IndexMap.d.ts +65 -65
  131. package/lib/esm/IndexMap.js +86 -86
  132. package/lib/esm/JsonSchema.d.ts +77 -77
  133. package/lib/esm/JsonSchema.d.ts.map +1 -1
  134. package/lib/esm/JsonSchema.js +8 -8
  135. package/lib/esm/JsonUtils.d.ts +78 -78
  136. package/lib/esm/JsonUtils.js +148 -148
  137. package/lib/esm/LRUMap.d.ts +129 -129
  138. package/lib/esm/LRUMap.js +326 -326
  139. package/lib/esm/LRUMap.js.map +1 -1
  140. package/lib/esm/Logger.d.ts +143 -143
  141. package/lib/esm/Logger.d.ts.map +1 -1
  142. package/lib/esm/Logger.js +253 -251
  143. package/lib/esm/Logger.js.map +1 -1
  144. package/lib/esm/ObservableSet.d.ts +23 -23
  145. package/lib/esm/ObservableSet.js +47 -47
  146. package/lib/esm/OneAtATimeAction.d.ts +31 -31
  147. package/lib/esm/OneAtATimeAction.js +89 -89
  148. package/lib/esm/OrderedId64Iterable.d.ts +74 -74
  149. package/lib/esm/OrderedId64Iterable.d.ts.map +1 -1
  150. package/lib/esm/OrderedId64Iterable.js +232 -232
  151. package/lib/esm/OrderedSet.d.ts +40 -40
  152. package/lib/esm/OrderedSet.js +59 -59
  153. package/lib/esm/PriorityQueue.d.ts +70 -70
  154. package/lib/esm/PriorityQueue.d.ts.map +1 -1
  155. package/lib/esm/PriorityQueue.js +136 -136
  156. package/lib/esm/ProcessDetector.d.ts +59 -59
  157. package/lib/esm/ProcessDetector.js +67 -67
  158. package/lib/esm/SortedArray.d.ts +236 -236
  159. package/lib/esm/SortedArray.d.ts.map +1 -1
  160. package/lib/esm/SortedArray.js +308 -308
  161. package/lib/esm/StatusCategory.d.ts +30 -30
  162. package/lib/esm/StatusCategory.d.ts.map +1 -1
  163. package/lib/esm/StatusCategory.js +455 -454
  164. package/lib/esm/StatusCategory.js.map +1 -1
  165. package/lib/esm/StringUtils.d.ts +22 -22
  166. package/lib/esm/StringUtils.js +142 -142
  167. package/lib/esm/Time.d.ts +122 -122
  168. package/lib/esm/Time.js +146 -146
  169. package/lib/esm/Time.js.map +1 -1
  170. package/lib/esm/Tracing.d.ts +40 -40
  171. package/lib/esm/Tracing.js +123 -123
  172. package/lib/esm/TupleKeyedMap.d.ts +36 -36
  173. package/lib/esm/TupleKeyedMap.js +98 -98
  174. package/lib/esm/TypedArrayBuilder.d.ts +155 -155
  175. package/lib/esm/TypedArrayBuilder.d.ts.map +1 -1
  176. package/lib/esm/TypedArrayBuilder.js +198 -198
  177. package/lib/esm/UnexpectedErrors.d.ts +43 -43
  178. package/lib/esm/UnexpectedErrors.d.ts.map +1 -1
  179. package/lib/esm/UnexpectedErrors.js +65 -64
  180. package/lib/esm/UnexpectedErrors.js.map +1 -1
  181. package/lib/esm/UtilityTypes.d.ts +112 -112
  182. package/lib/esm/UtilityTypes.d.ts.map +1 -1
  183. package/lib/esm/UtilityTypes.js +34 -34
  184. package/lib/esm/YieldManager.d.ts +18 -18
  185. package/lib/esm/YieldManager.js +30 -30
  186. package/lib/esm/core-bentley.d.ts +74 -74
  187. package/lib/esm/core-bentley.js +78 -78
  188. package/lib/esm/partitionArray.d.ts +21 -21
  189. package/lib/esm/partitionArray.js +39 -39
  190. package/package.json +4 -4
@@ -1,41 +1,41 @@
1
- import type { SpanAttributes, SpanContext, SpanOptions, Tracer } from "@opentelemetry/api";
2
- /**
3
- * Mirrors the SpanKind enum from [@opentelemetry/api](https://open-telemetry.github.io/opentelemetry-js-api/enums/spankind)
4
- * @alpha
5
- */
6
- export declare enum SpanKind {
7
- INTERNAL = 0,
8
- SERVER = 1,
9
- CLIENT = 2,
10
- PRODUCER = 3,
11
- CONSUMER = 4
12
- }
13
- /**
14
- * Enables OpenTelemetry tracing in addition to traditional logging.
15
- * @alpha
16
- */
17
- export declare class Tracing {
18
- private static _tracer?;
19
- private static _openTelemetry?;
20
- /**
21
- * If OpenTelemetry tracing is enabled, creates a new span and runs the provided function in it.
22
- * If OpenTelemetry tracing is _not_ enabled, runs the provided function.
23
- * @param name name of the new span
24
- * @param fn function to run inside the new span
25
- * @param options span options
26
- * @param parentContext optional context used to retrieve parent span id
27
- */
28
- static withSpan<T>(name: string, fn: () => Promise<T>, options?: SpanOptions, parentContext?: SpanContext): Promise<T>;
29
- /**
30
- * Enable logging to OpenTelemetry. [[Tracing.withSpan]] will be enabled, all log entries will be attached to active span as span events.
31
- * [[IModelHost.startup]] will call this automatically if it succeeds in requiring `@opentelemetry/api`.
32
- * @note Node.js OpenTelemetry SDK should be initialized by the user.
33
- */
34
- static enableOpenTelemetry(tracer: Tracer, api: typeof Tracing._openTelemetry): void;
35
- private static withOpenTelemetry;
36
- /** Set attributes on currently active openTelemetry span. Doesn't do anything if openTelemetry logging is not initialized.
37
- * @param attributes The attributes to set
38
- */
39
- static setAttributes(attributes: SpanAttributes): void;
40
- }
1
+ import type { SpanAttributes, SpanContext, SpanOptions, Tracer } from "@opentelemetry/api";
2
+ /**
3
+ * Mirrors the SpanKind enum from [@opentelemetry/api](https://open-telemetry.github.io/opentelemetry-js-api/enums/spankind)
4
+ * @alpha
5
+ */
6
+ export declare enum SpanKind {
7
+ INTERNAL = 0,
8
+ SERVER = 1,
9
+ CLIENT = 2,
10
+ PRODUCER = 3,
11
+ CONSUMER = 4
12
+ }
13
+ /**
14
+ * Enables OpenTelemetry tracing in addition to traditional logging.
15
+ * @alpha
16
+ */
17
+ export declare class Tracing {
18
+ private static _tracer?;
19
+ private static _openTelemetry?;
20
+ /**
21
+ * If OpenTelemetry tracing is enabled, creates a new span and runs the provided function in it.
22
+ * If OpenTelemetry tracing is _not_ enabled, runs the provided function.
23
+ * @param name name of the new span
24
+ * @param fn function to run inside the new span
25
+ * @param options span options
26
+ * @param parentContext optional context used to retrieve parent span id
27
+ */
28
+ static withSpan<T>(name: string, fn: () => Promise<T>, options?: SpanOptions, parentContext?: SpanContext): Promise<T>;
29
+ /**
30
+ * Enable logging to OpenTelemetry. [[Tracing.withSpan]] will be enabled, all log entries will be attached to active span as span events.
31
+ * [[IModelHost.startup]] will call this automatically if it succeeds in requiring `@opentelemetry/api`.
32
+ * @note Node.js OpenTelemetry SDK should be initialized by the user.
33
+ */
34
+ static enableOpenTelemetry(tracer: Tracer, api: typeof Tracing._openTelemetry): void;
35
+ private static withOpenTelemetry;
36
+ /** Set attributes on currently active openTelemetry span. Doesn't do anything if openTelemetry logging is not initialized.
37
+ * @param attributes The attributes to set
38
+ */
39
+ static setAttributes(attributes: SpanAttributes): void;
40
+ }
41
41
  //# sourceMappingURL=Tracing.d.ts.map
@@ -1,128 +1,128 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Tracing = exports.SpanKind = void 0;
4
- const Logger_1 = require("./Logger");
5
- // re-export so that consumers can construct full SpanOptions object without external dependencies
6
- /**
7
- * Mirrors the SpanKind enum from [@opentelemetry/api](https://open-telemetry.github.io/opentelemetry-js-api/enums/spankind)
8
- * @alpha
9
- */
10
- var SpanKind;
11
- (function (SpanKind) {
12
- SpanKind[SpanKind["INTERNAL"] = 0] = "INTERNAL";
13
- SpanKind[SpanKind["SERVER"] = 1] = "SERVER";
14
- SpanKind[SpanKind["CLIENT"] = 2] = "CLIENT";
15
- SpanKind[SpanKind["PRODUCER"] = 3] = "PRODUCER";
16
- SpanKind[SpanKind["CONSUMER"] = 4] = "CONSUMER";
17
- })(SpanKind = exports.SpanKind || (exports.SpanKind = {}));
18
- function isValidPrimitive(val) {
19
- return typeof val === "string" || typeof val === "number" || typeof val === "boolean";
20
- }
21
- // Only _homogenous_ arrays of strings, numbers, or booleans are supported as OpenTelemetry Attribute values.
22
- // Per the spec (https://opentelemetry.io/docs/reference/specification/common/common/#attribute), empty arrays and null values are supported too.
23
- function isValidPrimitiveArray(val) {
24
- if (!Array.isArray(val))
25
- return false;
26
- let itemType;
27
- for (const x of val) {
28
- if (x === undefined || x === null)
29
- continue;
30
- if (!itemType) {
31
- itemType = typeof x;
32
- if (!isValidPrimitive(x))
33
- return false;
34
- }
35
- if (typeof x !== itemType)
36
- return false;
37
- }
38
- return true;
39
- }
40
- function isPlainObject(obj) {
41
- return typeof obj === "object" && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;
42
- }
43
- function* getFlatEntries(obj, path = "") {
44
- if (isValidPrimitiveArray(obj)) {
45
- yield [path, obj];
46
- return;
47
- }
48
- // Prefer JSON serialization over flattening for any non-POJO types.
49
- // There's just too many ways trying to flatten those can go wrong (Dates, Buffers, TypedArrays, etc.)
50
- if (!isPlainObject(obj) && !Array.isArray(obj)) {
51
- yield [path, isValidPrimitive(obj) ? obj : JSON.stringify(obj)];
52
- return;
53
- }
54
- // Always serialize empty objects/arrays as empty array values
55
- const entries = Object.entries(obj);
56
- if (entries.length === 0)
57
- yield [path, []];
58
- for (const [key, val] of entries)
59
- yield* getFlatEntries(val, (path === "") ? key : `${path}.${key}`);
60
- }
61
- function flattenObject(obj) {
62
- return Object.fromEntries(getFlatEntries(obj));
63
- }
64
- /**
65
- * Enables OpenTelemetry tracing in addition to traditional logging.
66
- * @alpha
67
- */
68
- class Tracing {
69
- /**
70
- * If OpenTelemetry tracing is enabled, creates a new span and runs the provided function in it.
71
- * If OpenTelemetry tracing is _not_ enabled, runs the provided function.
72
- * @param name name of the new span
73
- * @param fn function to run inside the new span
74
- * @param options span options
75
- * @param parentContext optional context used to retrieve parent span id
76
- */
77
- static async withSpan(name, fn, options, parentContext) {
78
- if (Tracing._tracer === undefined || Tracing._openTelemetry === undefined)
79
- return fn();
80
- // this case is for context propagation - parentContext is typically constructed from HTTP headers
81
- const parent = parentContext === undefined
82
- ? Tracing._openTelemetry.context.active()
83
- : Tracing._openTelemetry.trace.setSpanContext(Tracing._openTelemetry.context.active(), parentContext);
84
- return Tracing._openTelemetry.context.with(Tracing._openTelemetry.trace.setSpan(parent, Tracing._tracer.startSpan(name, options, Tracing._openTelemetry.context.active())), async () => {
85
- try {
86
- return await fn();
87
- }
88
- catch (err) {
89
- if (err instanceof Error) // ignore non-Error throws, such as RpcControlResponse
90
- Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttribute("error", true);
91
- throw err;
92
- }
93
- finally {
94
- Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.end();
95
- }
96
- });
97
- }
98
- /**
99
- * Enable logging to OpenTelemetry. [[Tracing.withSpan]] will be enabled, all log entries will be attached to active span as span events.
100
- * [[IModelHost.startup]] will call this automatically if it succeeds in requiring `@opentelemetry/api`.
101
- * @note Node.js OpenTelemetry SDK should be initialized by the user.
102
- */
103
- static enableOpenTelemetry(tracer, api) {
104
- Tracing._tracer = tracer;
105
- Tracing._openTelemetry = api;
106
- Logger_1.Logger.logTrace = Tracing.withOpenTelemetry(Logger_1.Logger.logTrace);
107
- Logger_1.Logger.logInfo = Tracing.withOpenTelemetry(Logger_1.Logger.logInfo);
108
- Logger_1.Logger.logWarning = Tracing.withOpenTelemetry(Logger_1.Logger.logWarning);
109
- Logger_1.Logger.logError = Tracing.withOpenTelemetry(Logger_1.Logger.logError);
110
- }
111
- static withOpenTelemetry(base, isError = false) {
112
- return (category, message, metaData) => {
113
- try {
114
- Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.addEvent(message, { ...flattenObject(Logger_1.Logger.getMetaData(metaData)), error: isError });
115
- }
116
- catch (_e) { } // avoid throwing random errors (with stack trace mangled by async hooks) when openTelemetry collector doesn't work
117
- base(category, message, metaData);
118
- };
119
- }
120
- /** Set attributes on currently active openTelemetry span. Doesn't do anything if openTelemetry logging is not initialized.
121
- * @param attributes The attributes to set
122
- */
123
- static setAttributes(attributes) {
124
- Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttributes(attributes);
125
- }
126
- }
127
- exports.Tracing = Tracing;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tracing = exports.SpanKind = void 0;
4
+ const Logger_1 = require("./Logger");
5
+ // re-export so that consumers can construct full SpanOptions object without external dependencies
6
+ /**
7
+ * Mirrors the SpanKind enum from [@opentelemetry/api](https://open-telemetry.github.io/opentelemetry-js-api/enums/spankind)
8
+ * @alpha
9
+ */
10
+ var SpanKind;
11
+ (function (SpanKind) {
12
+ SpanKind[SpanKind["INTERNAL"] = 0] = "INTERNAL";
13
+ SpanKind[SpanKind["SERVER"] = 1] = "SERVER";
14
+ SpanKind[SpanKind["CLIENT"] = 2] = "CLIENT";
15
+ SpanKind[SpanKind["PRODUCER"] = 3] = "PRODUCER";
16
+ SpanKind[SpanKind["CONSUMER"] = 4] = "CONSUMER";
17
+ })(SpanKind = exports.SpanKind || (exports.SpanKind = {}));
18
+ function isValidPrimitive(val) {
19
+ return typeof val === "string" || typeof val === "number" || typeof val === "boolean";
20
+ }
21
+ // Only _homogenous_ arrays of strings, numbers, or booleans are supported as OpenTelemetry Attribute values.
22
+ // Per the spec (https://opentelemetry.io/docs/reference/specification/common/common/#attribute), empty arrays and null values are supported too.
23
+ function isValidPrimitiveArray(val) {
24
+ if (!Array.isArray(val))
25
+ return false;
26
+ let itemType;
27
+ for (const x of val) {
28
+ if (x === undefined || x === null)
29
+ continue;
30
+ if (!itemType) {
31
+ itemType = typeof x;
32
+ if (!isValidPrimitive(x))
33
+ return false;
34
+ }
35
+ if (typeof x !== itemType)
36
+ return false;
37
+ }
38
+ return true;
39
+ }
40
+ function isPlainObject(obj) {
41
+ return typeof obj === "object" && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;
42
+ }
43
+ function* getFlatEntries(obj, path = "") {
44
+ if (isValidPrimitiveArray(obj)) {
45
+ yield [path, obj];
46
+ return;
47
+ }
48
+ // Prefer JSON serialization over flattening for any non-POJO types.
49
+ // There's just too many ways trying to flatten those can go wrong (Dates, Buffers, TypedArrays, etc.)
50
+ if (!isPlainObject(obj) && !Array.isArray(obj)) {
51
+ yield [path, isValidPrimitive(obj) ? obj : JSON.stringify(obj)];
52
+ return;
53
+ }
54
+ // Always serialize empty objects/arrays as empty array values
55
+ const entries = Object.entries(obj);
56
+ if (entries.length === 0)
57
+ yield [path, []];
58
+ for (const [key, val] of entries)
59
+ yield* getFlatEntries(val, (path === "") ? key : `${path}.${key}`);
60
+ }
61
+ function flattenObject(obj) {
62
+ return Object.fromEntries(getFlatEntries(obj));
63
+ }
64
+ /**
65
+ * Enables OpenTelemetry tracing in addition to traditional logging.
66
+ * @alpha
67
+ */
68
+ class Tracing {
69
+ /**
70
+ * If OpenTelemetry tracing is enabled, creates a new span and runs the provided function in it.
71
+ * If OpenTelemetry tracing is _not_ enabled, runs the provided function.
72
+ * @param name name of the new span
73
+ * @param fn function to run inside the new span
74
+ * @param options span options
75
+ * @param parentContext optional context used to retrieve parent span id
76
+ */
77
+ static async withSpan(name, fn, options, parentContext) {
78
+ if (Tracing._tracer === undefined || Tracing._openTelemetry === undefined)
79
+ return fn();
80
+ // this case is for context propagation - parentContext is typically constructed from HTTP headers
81
+ const parent = parentContext === undefined
82
+ ? Tracing._openTelemetry.context.active()
83
+ : Tracing._openTelemetry.trace.setSpanContext(Tracing._openTelemetry.context.active(), parentContext);
84
+ return Tracing._openTelemetry.context.with(Tracing._openTelemetry.trace.setSpan(parent, Tracing._tracer.startSpan(name, options, Tracing._openTelemetry.context.active())), async () => {
85
+ try {
86
+ return await fn();
87
+ }
88
+ catch (err) {
89
+ if (err instanceof Error) // ignore non-Error throws, such as RpcControlResponse
90
+ Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttribute("error", true);
91
+ throw err;
92
+ }
93
+ finally {
94
+ Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.end();
95
+ }
96
+ });
97
+ }
98
+ /**
99
+ * Enable logging to OpenTelemetry. [[Tracing.withSpan]] will be enabled, all log entries will be attached to active span as span events.
100
+ * [[IModelHost.startup]] will call this automatically if it succeeds in requiring `@opentelemetry/api`.
101
+ * @note Node.js OpenTelemetry SDK should be initialized by the user.
102
+ */
103
+ static enableOpenTelemetry(tracer, api) {
104
+ Tracing._tracer = tracer;
105
+ Tracing._openTelemetry = api;
106
+ Logger_1.Logger.logTrace = Tracing.withOpenTelemetry(Logger_1.Logger.logTrace);
107
+ Logger_1.Logger.logInfo = Tracing.withOpenTelemetry(Logger_1.Logger.logInfo);
108
+ Logger_1.Logger.logWarning = Tracing.withOpenTelemetry(Logger_1.Logger.logWarning);
109
+ Logger_1.Logger.logError = Tracing.withOpenTelemetry(Logger_1.Logger.logError);
110
+ }
111
+ static withOpenTelemetry(base, isError = false) {
112
+ return (category, message, metaData) => {
113
+ try {
114
+ Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.addEvent(message, { ...flattenObject(Logger_1.Logger.getMetaData(metaData)), error: isError });
115
+ }
116
+ catch (_e) { } // avoid throwing random errors (with stack trace mangled by async hooks) when openTelemetry collector doesn't work
117
+ base(category, message, metaData);
118
+ };
119
+ }
120
+ /** Set attributes on currently active openTelemetry span. Doesn't do anything if openTelemetry logging is not initialized.
121
+ * @param attributes The attributes to set
122
+ */
123
+ static setAttributes(attributes) {
124
+ Tracing._openTelemetry?.trace.getSpan(Tracing._openTelemetry.context.active())?.setAttributes(attributes);
125
+ }
126
+ }
127
+ exports.Tracing = Tracing;
128
128
  //# sourceMappingURL=Tracing.js.map
@@ -1,37 +1,37 @@
1
- /** @packageDocumentation
2
- * @module Collections
3
- */
4
- /** A map similar to the standard JavaScript Map collection except that the keys must be a tuple
5
- * (javascript array), and two keys are considered equal if their elements in order are strict-equal,
6
- * and the tuples have the same amount of elements
7
- *
8
- * This means you can use array literals to key data in Maps that would otherwise be reference-compared
9
- * if using JavaScript's built in Map
10
- *
11
- * Note that JavaScript's Map type, unlike this one that uses strict equality, uses instead
12
- * SameValueZero equality comparison
13
- * @see https://262.ecma-international.org/6.0/#sec-samevaluezero
14
- *
15
- * ```js
16
- * const map = new TupleKeyedMap([[1,"y"], "value"]);
17
- * const value = map.get([1, "y"]); // a normal map would identify these keys as different because they are independent objects
18
- * ```
19
- *
20
- * It is implemented by each index of the tuple key being used as a singular key into a submap
21
- * @note this only implements a subset of the Map interface
22
- * @public
23
- */
24
- export declare class TupleKeyedMap<K extends readonly any[], V> {
25
- private _map;
26
- constructor(entries?: readonly (readonly [K, V])[] | null);
27
- clear(): void;
28
- private makeKeyError;
29
- get(key: K): V | undefined;
30
- has(key: K): boolean;
31
- set(key: K, value: V): this;
32
- [Symbol.iterator](): IterableIterator<[K, V]>;
33
- private _size;
34
- get size(): number;
35
- get [Symbol.toStringTag](): string;
36
- }
1
+ /** @packageDocumentation
2
+ * @module Collections
3
+ */
4
+ /** A map similar to the standard JavaScript Map collection except that the keys must be a tuple
5
+ * (javascript array), and two keys are considered equal if their elements in order are strict-equal,
6
+ * and the tuples have the same amount of elements
7
+ *
8
+ * This means you can use array literals to key data in Maps that would otherwise be reference-compared
9
+ * if using JavaScript's built in Map
10
+ *
11
+ * Note that JavaScript's Map type, unlike this one that uses strict equality, uses instead
12
+ * SameValueZero equality comparison
13
+ * @see https://262.ecma-international.org/6.0/#sec-samevaluezero
14
+ *
15
+ * ```js
16
+ * const map = new TupleKeyedMap([[1,"y"], "value"]);
17
+ * const value = map.get([1, "y"]); // a normal map would identify these keys as different because they are independent objects
18
+ * ```
19
+ *
20
+ * It is implemented by each index of the tuple key being used as a singular key into a submap
21
+ * @note this only implements a subset of the Map interface
22
+ * @public
23
+ */
24
+ export declare class TupleKeyedMap<K extends readonly any[], V> {
25
+ private _map;
26
+ constructor(entries?: readonly (readonly [K, V])[] | null);
27
+ clear(): void;
28
+ private makeKeyError;
29
+ get(key: K): V | undefined;
30
+ has(key: K): boolean;
31
+ set(key: K, value: V): this;
32
+ [Symbol.iterator](): IterableIterator<[K, V]>;
33
+ private _size;
34
+ get size(): number;
35
+ get [Symbol.toStringTag](): string;
36
+ }
37
37
  //# sourceMappingURL=TupleKeyedMap.d.ts.map
@@ -1,103 +1,103 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module Collections
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.TupleKeyedMap = void 0;
11
- /** A map similar to the standard JavaScript Map collection except that the keys must be a tuple
12
- * (javascript array), and two keys are considered equal if their elements in order are strict-equal,
13
- * and the tuples have the same amount of elements
14
- *
15
- * This means you can use array literals to key data in Maps that would otherwise be reference-compared
16
- * if using JavaScript's built in Map
17
- *
18
- * Note that JavaScript's Map type, unlike this one that uses strict equality, uses instead
19
- * SameValueZero equality comparison
20
- * @see https://262.ecma-international.org/6.0/#sec-samevaluezero
21
- *
22
- * ```js
23
- * const map = new TupleKeyedMap([[1,"y"], "value"]);
24
- * const value = map.get([1, "y"]); // a normal map would identify these keys as different because they are independent objects
25
- * ```
26
- *
27
- * It is implemented by each index of the tuple key being used as a singular key into a submap
28
- * @note this only implements a subset of the Map interface
29
- * @public
30
- */
31
- class TupleKeyedMap {
32
- // argument types match those of Map
33
- constructor(entries) {
34
- this._map = new Map();
35
- this._size = 0;
36
- if (entries)
37
- for (const [k, v] of entries) {
38
- this.set(k, v);
39
- }
40
- }
41
- clear() {
42
- return this._map.clear();
43
- }
44
- makeKeyError() {
45
- return Error("A Bad key was used, it didn't match the key type of the the map.");
46
- }
47
- get(key) {
48
- let cursor = this._map;
49
- for (const subkey of key) {
50
- if (!(cursor instanceof Map))
51
- throw this.makeKeyError();
52
- cursor = cursor.get(subkey);
53
- if (cursor === undefined)
54
- return undefined;
55
- }
56
- if (cursor instanceof Map)
57
- throw this.makeKeyError();
58
- return cursor;
59
- }
60
- has(key) {
61
- return this.get(key) !== undefined;
62
- }
63
- set(key, value) {
64
- let cursor = this._map;
65
- for (let i = 0; i < key.length - 1; ++i) {
66
- const subkey = key[i];
67
- let next = cursor.get(subkey);
68
- if (next === undefined) {
69
- next = new Map();
70
- cursor.set(subkey, next);
71
- }
72
- cursor = next;
73
- }
74
- const finalSubkey = key[key.length - 1];
75
- if (!(cursor instanceof Map))
76
- throw this.makeKeyError();
77
- cursor.set(finalSubkey, value);
78
- this._size++;
79
- return this;
80
- }
81
- *[Symbol.iterator]() {
82
- function* impl(map, keyPrefix) {
83
- for (const [k, v] of map) {
84
- const nextKey = [...keyPrefix, k];
85
- if (v instanceof Map) {
86
- yield* impl(v, nextKey);
87
- }
88
- else {
89
- yield [nextKey, v];
90
- }
91
- }
92
- }
93
- yield* impl(this._map, []);
94
- }
95
- get size() {
96
- return this._size;
97
- }
98
- get [Symbol.toStringTag]() {
99
- return this.constructor.name;
100
- }
101
- }
102
- exports.TupleKeyedMap = TupleKeyedMap;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Collections
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.TupleKeyedMap = void 0;
11
+ /** A map similar to the standard JavaScript Map collection except that the keys must be a tuple
12
+ * (javascript array), and two keys are considered equal if their elements in order are strict-equal,
13
+ * and the tuples have the same amount of elements
14
+ *
15
+ * This means you can use array literals to key data in Maps that would otherwise be reference-compared
16
+ * if using JavaScript's built in Map
17
+ *
18
+ * Note that JavaScript's Map type, unlike this one that uses strict equality, uses instead
19
+ * SameValueZero equality comparison
20
+ * @see https://262.ecma-international.org/6.0/#sec-samevaluezero
21
+ *
22
+ * ```js
23
+ * const map = new TupleKeyedMap([[1,"y"], "value"]);
24
+ * const value = map.get([1, "y"]); // a normal map would identify these keys as different because they are independent objects
25
+ * ```
26
+ *
27
+ * It is implemented by each index of the tuple key being used as a singular key into a submap
28
+ * @note this only implements a subset of the Map interface
29
+ * @public
30
+ */
31
+ class TupleKeyedMap {
32
+ // argument types match those of Map
33
+ constructor(entries) {
34
+ this._map = new Map();
35
+ this._size = 0;
36
+ if (entries)
37
+ for (const [k, v] of entries) {
38
+ this.set(k, v);
39
+ }
40
+ }
41
+ clear() {
42
+ return this._map.clear();
43
+ }
44
+ makeKeyError() {
45
+ return Error("A Bad key was used, it didn't match the key type of the the map.");
46
+ }
47
+ get(key) {
48
+ let cursor = this._map;
49
+ for (const subkey of key) {
50
+ if (!(cursor instanceof Map))
51
+ throw this.makeKeyError();
52
+ cursor = cursor.get(subkey);
53
+ if (cursor === undefined)
54
+ return undefined;
55
+ }
56
+ if (cursor instanceof Map)
57
+ throw this.makeKeyError();
58
+ return cursor;
59
+ }
60
+ has(key) {
61
+ return this.get(key) !== undefined;
62
+ }
63
+ set(key, value) {
64
+ let cursor = this._map;
65
+ for (let i = 0; i < key.length - 1; ++i) {
66
+ const subkey = key[i];
67
+ let next = cursor.get(subkey);
68
+ if (next === undefined) {
69
+ next = new Map();
70
+ cursor.set(subkey, next);
71
+ }
72
+ cursor = next;
73
+ }
74
+ const finalSubkey = key[key.length - 1];
75
+ if (!(cursor instanceof Map))
76
+ throw this.makeKeyError();
77
+ cursor.set(finalSubkey, value);
78
+ this._size++;
79
+ return this;
80
+ }
81
+ *[Symbol.iterator]() {
82
+ function* impl(map, keyPrefix) {
83
+ for (const [k, v] of map) {
84
+ const nextKey = [...keyPrefix, k];
85
+ if (v instanceof Map) {
86
+ yield* impl(v, nextKey);
87
+ }
88
+ else {
89
+ yield [nextKey, v];
90
+ }
91
+ }
92
+ }
93
+ yield* impl(this._map, []);
94
+ }
95
+ get size() {
96
+ return this._size;
97
+ }
98
+ get [Symbol.toStringTag]() {
99
+ return this.constructor.name;
100
+ }
101
+ }
102
+ exports.TupleKeyedMap = TupleKeyedMap;
103
103
  //# sourceMappingURL=TupleKeyedMap.js.map