@synnaxlabs/alamos 0.1.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.
@@ -0,0 +1,946 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ const _Meta = class _Meta {
8
+ constructor(key, path, serviceName = "", noop = false) {
9
+ __publicField(this, "_noop", false);
10
+ __publicField(this, "key");
11
+ __publicField(this, "path");
12
+ __publicField(this, "serviceName");
13
+ this.key = key;
14
+ this.path = path;
15
+ this.serviceName = serviceName;
16
+ this._noop = noop;
17
+ }
18
+ child(key) {
19
+ return new _Meta(key, this.extendPath(key), this.serviceName);
20
+ }
21
+ extendPath(key) {
22
+ return `${this.path}.${key}`;
23
+ }
24
+ get noop() {
25
+ return this._noop;
26
+ }
27
+ };
28
+ __publicField(_Meta, "NOOP", new _Meta("", "", ""));
29
+ let Meta = _Meta;
30
+ const LOG_LEVELS = ["debug", "info", "warn", "error"];
31
+ const logThresholdFilter = (thresh) => {
32
+ const threshIdx = LOG_LEVELS.indexOf(thresh);
33
+ return ({ level }) => LOG_LEVELS.indexOf(level) >= threshIdx;
34
+ };
35
+ const logLevelKeyFiler = (props) => {
36
+ const { include, exclude } = props;
37
+ return ({ key }) => {
38
+ if (include != null && !include.includes(key))
39
+ return false;
40
+ if (exclude != null && exclude.includes(key))
41
+ return false;
42
+ return true;
43
+ };
44
+ };
45
+ const _Logger = class _Logger {
46
+ constructor(p = {}) {
47
+ __publicField(this, "meta", Meta.NOOP);
48
+ __publicField(this, "filters");
49
+ const { filters = [] } = p;
50
+ this.filters = filters;
51
+ }
52
+ filter(level) {
53
+ return !this.meta.noop && this.filters.every(
54
+ (f) => f({
55
+ key: this.meta.key,
56
+ path: this.meta.path,
57
+ level
58
+ })
59
+ );
60
+ }
61
+ child(meta) {
62
+ const l = new _Logger({ filters: this.filters });
63
+ l.meta = meta;
64
+ return l;
65
+ }
66
+ debug(msg, kv) {
67
+ if (!this.filter("debug"))
68
+ return;
69
+ if (kv == null)
70
+ console.log("%cDEBUG", "color: #8c00f0;", this.meta.path, msg);
71
+ else
72
+ console.log("%cDEBUG", "color: #8c00f0;", this.meta.path, msg, kv);
73
+ }
74
+ info(msg, kv) {
75
+ if (!this.filter("info"))
76
+ return;
77
+ if (kv == null)
78
+ console.log("%cINFO", "color: #005eff;", this.meta.path, msg);
79
+ else
80
+ console.log("%cINFO", "color: #005eff;", this.meta.path, msg, kv);
81
+ }
82
+ warn(msg, kv) {
83
+ if (!this.filter("warn"))
84
+ return;
85
+ if (kv == null)
86
+ console.warn("WARN", this.meta.path, msg);
87
+ else
88
+ console.warn("WARN", this.meta.path, msg, kv);
89
+ }
90
+ error(msg, kv) {
91
+ if (!this.filter("error"))
92
+ return;
93
+ if (kv == null)
94
+ console.error("ERROR", this.meta.path, msg);
95
+ else
96
+ console.error("ERROR", this.meta.path, msg, kv);
97
+ }
98
+ };
99
+ __publicField(_Logger, "NOOP", new _Logger());
100
+ let Logger = _Logger;
101
+ var _globalThis = typeof globalThis === "object" ? globalThis : typeof self === "object" ? self : typeof window === "object" ? window : typeof global === "object" ? global : {};
102
+ var VERSION = "1.6.0";
103
+ var re = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
104
+ function _makeCompatibilityCheck(ownVersion) {
105
+ var acceptedVersions = /* @__PURE__ */ new Set([ownVersion]);
106
+ var rejectedVersions = /* @__PURE__ */ new Set();
107
+ var myVersionMatch = ownVersion.match(re);
108
+ if (!myVersionMatch) {
109
+ return function() {
110
+ return false;
111
+ };
112
+ }
113
+ var ownVersionParsed = {
114
+ major: +myVersionMatch[1],
115
+ minor: +myVersionMatch[2],
116
+ patch: +myVersionMatch[3],
117
+ prerelease: myVersionMatch[4]
118
+ };
119
+ if (ownVersionParsed.prerelease != null) {
120
+ return function isExactmatch(globalVersion) {
121
+ return globalVersion === ownVersion;
122
+ };
123
+ }
124
+ function _reject(v) {
125
+ rejectedVersions.add(v);
126
+ return false;
127
+ }
128
+ function _accept(v) {
129
+ acceptedVersions.add(v);
130
+ return true;
131
+ }
132
+ return function isCompatible2(globalVersion) {
133
+ if (acceptedVersions.has(globalVersion)) {
134
+ return true;
135
+ }
136
+ if (rejectedVersions.has(globalVersion)) {
137
+ return false;
138
+ }
139
+ var globalVersionMatch = globalVersion.match(re);
140
+ if (!globalVersionMatch) {
141
+ return _reject(globalVersion);
142
+ }
143
+ var globalVersionParsed = {
144
+ major: +globalVersionMatch[1],
145
+ minor: +globalVersionMatch[2],
146
+ patch: +globalVersionMatch[3],
147
+ prerelease: globalVersionMatch[4]
148
+ };
149
+ if (globalVersionParsed.prerelease != null) {
150
+ return _reject(globalVersion);
151
+ }
152
+ if (ownVersionParsed.major !== globalVersionParsed.major) {
153
+ return _reject(globalVersion);
154
+ }
155
+ if (ownVersionParsed.major === 0) {
156
+ if (ownVersionParsed.minor === globalVersionParsed.minor && ownVersionParsed.patch <= globalVersionParsed.patch) {
157
+ return _accept(globalVersion);
158
+ }
159
+ return _reject(globalVersion);
160
+ }
161
+ if (ownVersionParsed.minor <= globalVersionParsed.minor) {
162
+ return _accept(globalVersion);
163
+ }
164
+ return _reject(globalVersion);
165
+ };
166
+ }
167
+ var isCompatible = _makeCompatibilityCheck(VERSION);
168
+ var major = VERSION.split(".")[0];
169
+ var GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for("opentelemetry.js.api." + major);
170
+ var _global = _globalThis;
171
+ function registerGlobal(type, instance, diag, allowOverride) {
172
+ var _a;
173
+ if (allowOverride === void 0) {
174
+ allowOverride = false;
175
+ }
176
+ var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a !== void 0 ? _a : {
177
+ version: VERSION
178
+ };
179
+ if (!allowOverride && api[type]) {
180
+ var err = new Error("@opentelemetry/api: Attempted duplicate registration of API: " + type);
181
+ diag.error(err.stack || err.message);
182
+ return false;
183
+ }
184
+ if (api.version !== VERSION) {
185
+ var err = new Error("@opentelemetry/api: Registration of version v" + api.version + " for " + type + " does not match previously registered API v" + VERSION);
186
+ diag.error(err.stack || err.message);
187
+ return false;
188
+ }
189
+ api[type] = instance;
190
+ diag.debug("@opentelemetry/api: Registered a global for " + type + " v" + VERSION + ".");
191
+ return true;
192
+ }
193
+ function getGlobal(type) {
194
+ var _a, _b;
195
+ var globalVersion = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a === void 0 ? void 0 : _a.version;
196
+ if (!globalVersion || !isCompatible(globalVersion)) {
197
+ return;
198
+ }
199
+ return (_b = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b === void 0 ? void 0 : _b[type];
200
+ }
201
+ function unregisterGlobal(type, diag) {
202
+ diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION + ".");
203
+ var api = _global[GLOBAL_OPENTELEMETRY_API_KEY];
204
+ if (api) {
205
+ delete api[type];
206
+ }
207
+ }
208
+ var __read$4 = globalThis && globalThis.__read || function(o, n) {
209
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
210
+ if (!m)
211
+ return o;
212
+ var i = m.call(o), r, ar = [], e;
213
+ try {
214
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
215
+ ar.push(r.value);
216
+ } catch (error) {
217
+ e = { error };
218
+ } finally {
219
+ try {
220
+ if (r && !r.done && (m = i["return"]))
221
+ m.call(i);
222
+ } finally {
223
+ if (e)
224
+ throw e.error;
225
+ }
226
+ }
227
+ return ar;
228
+ };
229
+ var __spreadArray$3 = globalThis && globalThis.__spreadArray || function(to, from, pack) {
230
+ if (pack || arguments.length === 2)
231
+ for (var i = 0, l = from.length, ar; i < l; i++) {
232
+ if (ar || !(i in from)) {
233
+ if (!ar)
234
+ ar = Array.prototype.slice.call(from, 0, i);
235
+ ar[i] = from[i];
236
+ }
237
+ }
238
+ return to.concat(ar || Array.prototype.slice.call(from));
239
+ };
240
+ var DiagComponentLogger = (
241
+ /** @class */
242
+ function() {
243
+ function DiagComponentLogger2(props) {
244
+ this._namespace = props.namespace || "DiagComponentLogger";
245
+ }
246
+ DiagComponentLogger2.prototype.debug = function() {
247
+ var args = [];
248
+ for (var _i = 0; _i < arguments.length; _i++) {
249
+ args[_i] = arguments[_i];
250
+ }
251
+ return logProxy("debug", this._namespace, args);
252
+ };
253
+ DiagComponentLogger2.prototype.error = function() {
254
+ var args = [];
255
+ for (var _i = 0; _i < arguments.length; _i++) {
256
+ args[_i] = arguments[_i];
257
+ }
258
+ return logProxy("error", this._namespace, args);
259
+ };
260
+ DiagComponentLogger2.prototype.info = function() {
261
+ var args = [];
262
+ for (var _i = 0; _i < arguments.length; _i++) {
263
+ args[_i] = arguments[_i];
264
+ }
265
+ return logProxy("info", this._namespace, args);
266
+ };
267
+ DiagComponentLogger2.prototype.warn = function() {
268
+ var args = [];
269
+ for (var _i = 0; _i < arguments.length; _i++) {
270
+ args[_i] = arguments[_i];
271
+ }
272
+ return logProxy("warn", this._namespace, args);
273
+ };
274
+ DiagComponentLogger2.prototype.verbose = function() {
275
+ var args = [];
276
+ for (var _i = 0; _i < arguments.length; _i++) {
277
+ args[_i] = arguments[_i];
278
+ }
279
+ return logProxy("verbose", this._namespace, args);
280
+ };
281
+ return DiagComponentLogger2;
282
+ }()
283
+ );
284
+ function logProxy(funcName, namespace, args) {
285
+ var logger = getGlobal("diag");
286
+ if (!logger) {
287
+ return;
288
+ }
289
+ args.unshift(namespace);
290
+ return logger[funcName].apply(logger, __spreadArray$3([], __read$4(args), false));
291
+ }
292
+ var DiagLogLevel;
293
+ (function(DiagLogLevel2) {
294
+ DiagLogLevel2[DiagLogLevel2["NONE"] = 0] = "NONE";
295
+ DiagLogLevel2[DiagLogLevel2["ERROR"] = 30] = "ERROR";
296
+ DiagLogLevel2[DiagLogLevel2["WARN"] = 50] = "WARN";
297
+ DiagLogLevel2[DiagLogLevel2["INFO"] = 60] = "INFO";
298
+ DiagLogLevel2[DiagLogLevel2["DEBUG"] = 70] = "DEBUG";
299
+ DiagLogLevel2[DiagLogLevel2["VERBOSE"] = 80] = "VERBOSE";
300
+ DiagLogLevel2[DiagLogLevel2["ALL"] = 9999] = "ALL";
301
+ })(DiagLogLevel || (DiagLogLevel = {}));
302
+ function createLogLevelDiagLogger(maxLevel, logger) {
303
+ if (maxLevel < DiagLogLevel.NONE) {
304
+ maxLevel = DiagLogLevel.NONE;
305
+ } else if (maxLevel > DiagLogLevel.ALL) {
306
+ maxLevel = DiagLogLevel.ALL;
307
+ }
308
+ logger = logger || {};
309
+ function _filterFunc(funcName, theLevel) {
310
+ var theFunc = logger[funcName];
311
+ if (typeof theFunc === "function" && maxLevel >= theLevel) {
312
+ return theFunc.bind(logger);
313
+ }
314
+ return function() {
315
+ };
316
+ }
317
+ return {
318
+ error: _filterFunc("error", DiagLogLevel.ERROR),
319
+ warn: _filterFunc("warn", DiagLogLevel.WARN),
320
+ info: _filterFunc("info", DiagLogLevel.INFO),
321
+ debug: _filterFunc("debug", DiagLogLevel.DEBUG),
322
+ verbose: _filterFunc("verbose", DiagLogLevel.VERBOSE)
323
+ };
324
+ }
325
+ var __read$3 = globalThis && globalThis.__read || function(o, n) {
326
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
327
+ if (!m)
328
+ return o;
329
+ var i = m.call(o), r, ar = [], e;
330
+ try {
331
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
332
+ ar.push(r.value);
333
+ } catch (error) {
334
+ e = { error };
335
+ } finally {
336
+ try {
337
+ if (r && !r.done && (m = i["return"]))
338
+ m.call(i);
339
+ } finally {
340
+ if (e)
341
+ throw e.error;
342
+ }
343
+ }
344
+ return ar;
345
+ };
346
+ var __spreadArray$2 = globalThis && globalThis.__spreadArray || function(to, from, pack) {
347
+ if (pack || arguments.length === 2)
348
+ for (var i = 0, l = from.length, ar; i < l; i++) {
349
+ if (ar || !(i in from)) {
350
+ if (!ar)
351
+ ar = Array.prototype.slice.call(from, 0, i);
352
+ ar[i] = from[i];
353
+ }
354
+ }
355
+ return to.concat(ar || Array.prototype.slice.call(from));
356
+ };
357
+ var API_NAME$2 = "diag";
358
+ var DiagAPI = (
359
+ /** @class */
360
+ function() {
361
+ function DiagAPI2() {
362
+ function _logProxy(funcName) {
363
+ return function() {
364
+ var args = [];
365
+ for (var _i = 0; _i < arguments.length; _i++) {
366
+ args[_i] = arguments[_i];
367
+ }
368
+ var logger = getGlobal("diag");
369
+ if (!logger)
370
+ return;
371
+ return logger[funcName].apply(logger, __spreadArray$2([], __read$3(args), false));
372
+ };
373
+ }
374
+ var self2 = this;
375
+ var setLogger = function(logger, optionsOrLogLevel) {
376
+ var _a, _b, _c;
377
+ if (optionsOrLogLevel === void 0) {
378
+ optionsOrLogLevel = { logLevel: DiagLogLevel.INFO };
379
+ }
380
+ if (logger === self2) {
381
+ var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
382
+ self2.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
383
+ return false;
384
+ }
385
+ if (typeof optionsOrLogLevel === "number") {
386
+ optionsOrLogLevel = {
387
+ logLevel: optionsOrLogLevel
388
+ };
389
+ }
390
+ var oldLogger = getGlobal("diag");
391
+ var newLogger = createLogLevelDiagLogger((_b = optionsOrLogLevel.logLevel) !== null && _b !== void 0 ? _b : DiagLogLevel.INFO, logger);
392
+ if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
393
+ var stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : "<failed to generate stacktrace>";
394
+ oldLogger.warn("Current logger will be overwritten from " + stack);
395
+ newLogger.warn("Current logger will overwrite one already registered from " + stack);
396
+ }
397
+ return registerGlobal("diag", newLogger, self2, true);
398
+ };
399
+ self2.setLogger = setLogger;
400
+ self2.disable = function() {
401
+ unregisterGlobal(API_NAME$2, self2);
402
+ };
403
+ self2.createComponentLogger = function(options) {
404
+ return new DiagComponentLogger(options);
405
+ };
406
+ self2.verbose = _logProxy("verbose");
407
+ self2.debug = _logProxy("debug");
408
+ self2.info = _logProxy("info");
409
+ self2.warn = _logProxy("warn");
410
+ self2.error = _logProxy("error");
411
+ }
412
+ DiagAPI2.instance = function() {
413
+ if (!this._instance) {
414
+ this._instance = new DiagAPI2();
415
+ }
416
+ return this._instance;
417
+ };
418
+ return DiagAPI2;
419
+ }()
420
+ );
421
+ var __read$2 = globalThis && globalThis.__read || function(o, n) {
422
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
423
+ if (!m)
424
+ return o;
425
+ var i = m.call(o), r, ar = [], e;
426
+ try {
427
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
428
+ ar.push(r.value);
429
+ } catch (error) {
430
+ e = { error };
431
+ } finally {
432
+ try {
433
+ if (r && !r.done && (m = i["return"]))
434
+ m.call(i);
435
+ } finally {
436
+ if (e)
437
+ throw e.error;
438
+ }
439
+ }
440
+ return ar;
441
+ };
442
+ var __values = globalThis && globalThis.__values || function(o) {
443
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
444
+ if (m)
445
+ return m.call(o);
446
+ if (o && typeof o.length === "number")
447
+ return {
448
+ next: function() {
449
+ if (o && i >= o.length)
450
+ o = void 0;
451
+ return { value: o && o[i++], done: !o };
452
+ }
453
+ };
454
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
455
+ };
456
+ var BaggageImpl = (
457
+ /** @class */
458
+ function() {
459
+ function BaggageImpl2(entries) {
460
+ this._entries = entries ? new Map(entries) : /* @__PURE__ */ new Map();
461
+ }
462
+ BaggageImpl2.prototype.getEntry = function(key) {
463
+ var entry = this._entries.get(key);
464
+ if (!entry) {
465
+ return void 0;
466
+ }
467
+ return Object.assign({}, entry);
468
+ };
469
+ BaggageImpl2.prototype.getAllEntries = function() {
470
+ return Array.from(this._entries.entries()).map(function(_a) {
471
+ var _b = __read$2(_a, 2), k = _b[0], v = _b[1];
472
+ return [k, v];
473
+ });
474
+ };
475
+ BaggageImpl2.prototype.setEntry = function(key, entry) {
476
+ var newBaggage = new BaggageImpl2(this._entries);
477
+ newBaggage._entries.set(key, entry);
478
+ return newBaggage;
479
+ };
480
+ BaggageImpl2.prototype.removeEntry = function(key) {
481
+ var newBaggage = new BaggageImpl2(this._entries);
482
+ newBaggage._entries.delete(key);
483
+ return newBaggage;
484
+ };
485
+ BaggageImpl2.prototype.removeEntries = function() {
486
+ var e_1, _a;
487
+ var keys = [];
488
+ for (var _i = 0; _i < arguments.length; _i++) {
489
+ keys[_i] = arguments[_i];
490
+ }
491
+ var newBaggage = new BaggageImpl2(this._entries);
492
+ try {
493
+ for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
494
+ var key = keys_1_1.value;
495
+ newBaggage._entries.delete(key);
496
+ }
497
+ } catch (e_1_1) {
498
+ e_1 = { error: e_1_1 };
499
+ } finally {
500
+ try {
501
+ if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return))
502
+ _a.call(keys_1);
503
+ } finally {
504
+ if (e_1)
505
+ throw e_1.error;
506
+ }
507
+ }
508
+ return newBaggage;
509
+ };
510
+ BaggageImpl2.prototype.clear = function() {
511
+ return new BaggageImpl2();
512
+ };
513
+ return BaggageImpl2;
514
+ }()
515
+ );
516
+ DiagAPI.instance();
517
+ function createBaggage(entries) {
518
+ if (entries === void 0) {
519
+ entries = {};
520
+ }
521
+ return new BaggageImpl(new Map(Object.entries(entries)));
522
+ }
523
+ function createContextKey(description) {
524
+ return Symbol.for(description);
525
+ }
526
+ var BaseContext = (
527
+ /** @class */
528
+ function() {
529
+ function BaseContext2(parentContext) {
530
+ var self2 = this;
531
+ self2._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
532
+ self2.getValue = function(key) {
533
+ return self2._currentContext.get(key);
534
+ };
535
+ self2.setValue = function(key, value) {
536
+ var context2 = new BaseContext2(self2._currentContext);
537
+ context2._currentContext.set(key, value);
538
+ return context2;
539
+ };
540
+ self2.deleteValue = function(key) {
541
+ var context2 = new BaseContext2(self2._currentContext);
542
+ context2._currentContext.delete(key);
543
+ return context2;
544
+ };
545
+ }
546
+ return BaseContext2;
547
+ }()
548
+ );
549
+ var ROOT_CONTEXT = new BaseContext();
550
+ var defaultTextMapGetter = {
551
+ get: function(carrier, key) {
552
+ if (carrier == null) {
553
+ return void 0;
554
+ }
555
+ return carrier[key];
556
+ },
557
+ keys: function(carrier) {
558
+ if (carrier == null) {
559
+ return [];
560
+ }
561
+ return Object.keys(carrier);
562
+ }
563
+ };
564
+ var defaultTextMapSetter = {
565
+ set: function(carrier, key, value) {
566
+ if (carrier == null) {
567
+ return;
568
+ }
569
+ carrier[key] = value;
570
+ }
571
+ };
572
+ var __read$1 = globalThis && globalThis.__read || function(o, n) {
573
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
574
+ if (!m)
575
+ return o;
576
+ var i = m.call(o), r, ar = [], e;
577
+ try {
578
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
579
+ ar.push(r.value);
580
+ } catch (error) {
581
+ e = { error };
582
+ } finally {
583
+ try {
584
+ if (r && !r.done && (m = i["return"]))
585
+ m.call(i);
586
+ } finally {
587
+ if (e)
588
+ throw e.error;
589
+ }
590
+ }
591
+ return ar;
592
+ };
593
+ var __spreadArray$1 = globalThis && globalThis.__spreadArray || function(to, from, pack) {
594
+ if (pack || arguments.length === 2)
595
+ for (var i = 0, l = from.length, ar; i < l; i++) {
596
+ if (ar || !(i in from)) {
597
+ if (!ar)
598
+ ar = Array.prototype.slice.call(from, 0, i);
599
+ ar[i] = from[i];
600
+ }
601
+ }
602
+ return to.concat(ar || Array.prototype.slice.call(from));
603
+ };
604
+ var NoopContextManager = (
605
+ /** @class */
606
+ function() {
607
+ function NoopContextManager2() {
608
+ }
609
+ NoopContextManager2.prototype.active = function() {
610
+ return ROOT_CONTEXT;
611
+ };
612
+ NoopContextManager2.prototype.with = function(_context, fn, thisArg) {
613
+ var args = [];
614
+ for (var _i = 3; _i < arguments.length; _i++) {
615
+ args[_i - 3] = arguments[_i];
616
+ }
617
+ return fn.call.apply(fn, __spreadArray$1([thisArg], __read$1(args), false));
618
+ };
619
+ NoopContextManager2.prototype.bind = function(_context, target) {
620
+ return target;
621
+ };
622
+ NoopContextManager2.prototype.enable = function() {
623
+ return this;
624
+ };
625
+ NoopContextManager2.prototype.disable = function() {
626
+ return this;
627
+ };
628
+ return NoopContextManager2;
629
+ }()
630
+ );
631
+ var __read = globalThis && globalThis.__read || function(o, n) {
632
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
633
+ if (!m)
634
+ return o;
635
+ var i = m.call(o), r, ar = [], e;
636
+ try {
637
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
638
+ ar.push(r.value);
639
+ } catch (error) {
640
+ e = { error };
641
+ } finally {
642
+ try {
643
+ if (r && !r.done && (m = i["return"]))
644
+ m.call(i);
645
+ } finally {
646
+ if (e)
647
+ throw e.error;
648
+ }
649
+ }
650
+ return ar;
651
+ };
652
+ var __spreadArray = globalThis && globalThis.__spreadArray || function(to, from, pack) {
653
+ if (pack || arguments.length === 2)
654
+ for (var i = 0, l = from.length, ar; i < l; i++) {
655
+ if (ar || !(i in from)) {
656
+ if (!ar)
657
+ ar = Array.prototype.slice.call(from, 0, i);
658
+ ar[i] = from[i];
659
+ }
660
+ }
661
+ return to.concat(ar || Array.prototype.slice.call(from));
662
+ };
663
+ var API_NAME$1 = "context";
664
+ var NOOP_CONTEXT_MANAGER = new NoopContextManager();
665
+ var ContextAPI = (
666
+ /** @class */
667
+ function() {
668
+ function ContextAPI2() {
669
+ }
670
+ ContextAPI2.getInstance = function() {
671
+ if (!this._instance) {
672
+ this._instance = new ContextAPI2();
673
+ }
674
+ return this._instance;
675
+ };
676
+ ContextAPI2.prototype.setGlobalContextManager = function(contextManager) {
677
+ return registerGlobal(API_NAME$1, contextManager, DiagAPI.instance());
678
+ };
679
+ ContextAPI2.prototype.active = function() {
680
+ return this._getContextManager().active();
681
+ };
682
+ ContextAPI2.prototype.with = function(context2, fn, thisArg) {
683
+ var _a;
684
+ var args = [];
685
+ for (var _i = 3; _i < arguments.length; _i++) {
686
+ args[_i - 3] = arguments[_i];
687
+ }
688
+ return (_a = this._getContextManager()).with.apply(_a, __spreadArray([context2, fn, thisArg], __read(args), false));
689
+ };
690
+ ContextAPI2.prototype.bind = function(context2, target) {
691
+ return this._getContextManager().bind(context2, target);
692
+ };
693
+ ContextAPI2.prototype._getContextManager = function() {
694
+ return getGlobal(API_NAME$1) || NOOP_CONTEXT_MANAGER;
695
+ };
696
+ ContextAPI2.prototype.disable = function() {
697
+ this._getContextManager().disable();
698
+ unregisterGlobal(API_NAME$1, DiagAPI.instance());
699
+ };
700
+ return ContextAPI2;
701
+ }()
702
+ );
703
+ var SpanStatusCode;
704
+ (function(SpanStatusCode2) {
705
+ SpanStatusCode2[SpanStatusCode2["UNSET"] = 0] = "UNSET";
706
+ SpanStatusCode2[SpanStatusCode2["OK"] = 1] = "OK";
707
+ SpanStatusCode2[SpanStatusCode2["ERROR"] = 2] = "ERROR";
708
+ })(SpanStatusCode || (SpanStatusCode = {}));
709
+ var context = ContextAPI.getInstance();
710
+ var NoopTextMapPropagator = (
711
+ /** @class */
712
+ function() {
713
+ function NoopTextMapPropagator2() {
714
+ }
715
+ NoopTextMapPropagator2.prototype.inject = function(_context, _carrier) {
716
+ };
717
+ NoopTextMapPropagator2.prototype.extract = function(context2, _carrier) {
718
+ return context2;
719
+ };
720
+ NoopTextMapPropagator2.prototype.fields = function() {
721
+ return [];
722
+ };
723
+ return NoopTextMapPropagator2;
724
+ }()
725
+ );
726
+ var BAGGAGE_KEY = createContextKey("OpenTelemetry Baggage Key");
727
+ function getBaggage(context2) {
728
+ return context2.getValue(BAGGAGE_KEY) || void 0;
729
+ }
730
+ function getActiveBaggage() {
731
+ return getBaggage(ContextAPI.getInstance().active());
732
+ }
733
+ function setBaggage(context2, baggage) {
734
+ return context2.setValue(BAGGAGE_KEY, baggage);
735
+ }
736
+ function deleteBaggage(context2) {
737
+ return context2.deleteValue(BAGGAGE_KEY);
738
+ }
739
+ var API_NAME = "propagation";
740
+ var NOOP_TEXT_MAP_PROPAGATOR = new NoopTextMapPropagator();
741
+ var PropagationAPI = (
742
+ /** @class */
743
+ function() {
744
+ function PropagationAPI2() {
745
+ this.createBaggage = createBaggage;
746
+ this.getBaggage = getBaggage;
747
+ this.getActiveBaggage = getActiveBaggage;
748
+ this.setBaggage = setBaggage;
749
+ this.deleteBaggage = deleteBaggage;
750
+ }
751
+ PropagationAPI2.getInstance = function() {
752
+ if (!this._instance) {
753
+ this._instance = new PropagationAPI2();
754
+ }
755
+ return this._instance;
756
+ };
757
+ PropagationAPI2.prototype.setGlobalPropagator = function(propagator) {
758
+ return registerGlobal(API_NAME, propagator, DiagAPI.instance());
759
+ };
760
+ PropagationAPI2.prototype.inject = function(context2, carrier, setter) {
761
+ if (setter === void 0) {
762
+ setter = defaultTextMapSetter;
763
+ }
764
+ return this._getGlobalPropagator().inject(context2, carrier, setter);
765
+ };
766
+ PropagationAPI2.prototype.extract = function(context2, carrier, getter) {
767
+ if (getter === void 0) {
768
+ getter = defaultTextMapGetter;
769
+ }
770
+ return this._getGlobalPropagator().extract(context2, carrier, getter);
771
+ };
772
+ PropagationAPI2.prototype.fields = function() {
773
+ return this._getGlobalPropagator().fields();
774
+ };
775
+ PropagationAPI2.prototype.disable = function() {
776
+ unregisterGlobal(API_NAME, DiagAPI.instance());
777
+ };
778
+ PropagationAPI2.prototype._getGlobalPropagator = function() {
779
+ return getGlobal(API_NAME) || NOOP_TEXT_MAP_PROPAGATOR;
780
+ };
781
+ return PropagationAPI2;
782
+ }()
783
+ );
784
+ var propagation = PropagationAPI.getInstance();
785
+ const ENVIRONMENTS = ["bench", "debug", "prod"];
786
+ const envThresholdFilter = (treshold) => (env) => ENVIRONMENTS.indexOf(env) >= ENVIRONMENTS.indexOf(treshold);
787
+ const _Tracer = class _Tracer {
788
+ constructor(tracer, filter = envThresholdFilter("debug")) {
789
+ __publicField(this, "meta", Meta.NOOP);
790
+ __publicField(this, "tracer");
791
+ __publicField(this, "filter");
792
+ this.tracer = tracer;
793
+ this.filter = filter;
794
+ }
795
+ child(meta) {
796
+ const t = new _Tracer(this.tracer, this.filter);
797
+ t.meta = meta;
798
+ return t;
799
+ }
800
+ /**
801
+ * Starts a new span in the debug environment. If a span already exists in the
802
+ * current context, it will be used as the parent span.
803
+ *
804
+ * @param key - The name of the span.
805
+ * @param f - The function to run under the span.
806
+ * @returns A span that tracks program execution. If the Tracer's environment
807
+ * rejects the 'debug' environment or the Tracer is noop, a NoopSpan is returned.
808
+ */
809
+ debug(key, f) {
810
+ return this.trace(key, "debug", f);
811
+ }
812
+ /**
813
+ * Starts a new span in the bench environment. If a span already exists in the
814
+ * current context, it will be used as the parent span.
815
+ *
816
+ * @param key - The name of the span.
817
+ * @param f - The function to run under the span.
818
+ * @returns A span that tracks program execution. If the Tracer's environment
819
+ * rejects the 'bench' environment or the Tracer is noop, a NoopSpan is returned.
820
+ */
821
+ bench(key, f) {
822
+ return this.trace(key, "bench", f);
823
+ }
824
+ /**
825
+ * Starts a new span in the prod environment. If a span already exists in the
826
+ * current context, it will be used as the parent span.
827
+ *
828
+ * @param key - The name of the span.
829
+ * @param f - The function to run under the span.
830
+ * @returns A span that tracks program execution. If the Tracer's environment
831
+ * rejects the 'prod' environment or the Tracer is noop, a NoopSpan is returned.
832
+ */
833
+ prod(key, f) {
834
+ return this.trace(key, "prod", f);
835
+ }
836
+ /**
837
+ * Stars a new span with the given key and environment. If a span already
838
+ * exists in the current context, it will be used as the parent span.
839
+ *
840
+ * @param key - The name of the span.
841
+ * @param env - The environment to run the span under.
842
+ * @param f - The function to run under the span.
843
+ * @returns A span that tracks program execution. If the Tracer's environment
844
+ * rejects the provided span or the Tracer is noop, a NoopSpan is returned.
845
+ */
846
+ trace(key, env, f) {
847
+ if (this.meta.noop || !this.filter(env))
848
+ return f(new NoopSpan(key));
849
+ return this.tracer.startActiveSpan(key, (otelSpan) => {
850
+ const span = new _Span(key, otelSpan);
851
+ const result = f(span);
852
+ otelSpan.end();
853
+ return result;
854
+ });
855
+ }
856
+ /**
857
+ * Injects metadata about the current trace into the provided carrier. This
858
+ * metadata can be paresed on teh other side of a network or IPC request to
859
+ * allow the trace to proapgate across services.
860
+ *
861
+ * @param carrier - The carrier to inject the metadata into.
862
+ */
863
+ propagate(carrier) {
864
+ if (this.meta.noop)
865
+ return;
866
+ const ctx = context.active();
867
+ propagation.inject(ctx, carrier, {
868
+ set: (carrier2, key, value) => {
869
+ carrier2[key] = value;
870
+ }
871
+ });
872
+ }
873
+ };
874
+ /** Tracer implementation that does nothing */
875
+ __publicField(_Tracer, "NOOP", new _Tracer());
876
+ let Tracer = _Tracer;
877
+ class _Span {
878
+ constructor(key, span) {
879
+ __publicField(this, "key");
880
+ __publicField(this, "otel");
881
+ this.key = key;
882
+ this.otel = span;
883
+ }
884
+ set(key, value) {
885
+ this.otel.setAttribute(key, value);
886
+ }
887
+ recordError(error) {
888
+ if (error == null)
889
+ return;
890
+ this.otel.recordException(error);
891
+ this.otel.setStatus({ code: SpanStatusCode.ERROR });
892
+ }
893
+ }
894
+ class NoopSpan {
895
+ constructor(key) {
896
+ __publicField(this, "key");
897
+ this.key = key;
898
+ }
899
+ set(key, value) {
900
+ }
901
+ recordError(_) {
902
+ }
903
+ }
904
+ const _Instrumentation = class _Instrumentation {
905
+ constructor({
906
+ key = "",
907
+ serviceName = "",
908
+ logger = Logger.NOOP,
909
+ tracer = Tracer.NOOP,
910
+ noop = false,
911
+ // eslint-disable-next-line @typescript-eslint/naming-convention
912
+ __meta
913
+ }) {
914
+ __publicField(this, "meta");
915
+ __publicField(this, "T");
916
+ __publicField(this, "L");
917
+ this.meta = __meta ?? new Meta(key, key, serviceName, noop);
918
+ this.T = tracer.child(this.meta);
919
+ this.L = logger.child(this.meta);
920
+ }
921
+ child(key) {
922
+ const __meta = this.meta.child(key);
923
+ return new _Instrumentation({ __meta, tracer: this.T, logger: this.L });
924
+ }
925
+ };
926
+ __publicField(_Instrumentation, "NOOP", new _Instrumentation({ noop: true }));
927
+ let Instrumentation = _Instrumentation;
928
+ const NOOP = Instrumentation.NOOP;
929
+ export {
930
+ ContextAPI as C,
931
+ DiagAPI as D,
932
+ Instrumentation as I,
933
+ LOG_LEVELS as L,
934
+ NOOP as N,
935
+ Tracer as T,
936
+ _Span as _,
937
+ Logger as a,
938
+ NoopSpan as b,
939
+ logThresholdFilter as c,
940
+ createContextKey as d,
941
+ getGlobal as g,
942
+ logLevelKeyFiler as l,
943
+ registerGlobal as r,
944
+ unregisterGlobal as u
945
+ };
946
+ //# sourceMappingURL=instrumentation-2edee102.js.map