@burdenoff/be-sdk 2026.518.2 → 2026.518.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,852 @@
1
+ import { __name } from './chunk-XE4OXN2W.js';
2
+
3
+ // src/instrumentation/config.ts
4
+ var ENV_VARS = {
5
+ // Master switch
6
+ INSTRUMENTATION_ENABLED: "INSTRUMENTATION_ENABLED",
7
+ // Feature flags
8
+ INSTRUMENTATION_TRACING: "INSTRUMENTATION_TRACING",
9
+ INSTRUMENTATION_METRICS: "INSTRUMENTATION_METRICS",
10
+ INSTRUMENTATION_LOGGING: "INSTRUMENTATION_LOGGING",
11
+ INSTRUMENTATION_GRAPHQL: "INSTRUMENTATION_GRAPHQL",
12
+ INSTRUMENTATION_DATABASE: "INSTRUMENTATION_DATABASE",
13
+ INSTRUMENTATION_HTTP: "INSTRUMENTATION_HTTP",
14
+ INSTRUMENTATION_CACHE: "INSTRUMENTATION_CACHE",
15
+ INSTRUMENTATION_EVENT_QUEUE: "INSTRUMENTATION_EVENT_QUEUE",
16
+ // Tracing
17
+ OTEL_SERVICE_NAME: "OTEL_SERVICE_NAME",
18
+ OTEL_SERVICE_VERSION: "OTEL_SERVICE_VERSION",
19
+ OTEL_ENVIRONMENT: "OTEL_ENVIRONMENT",
20
+ OTEL_EXPORTER_OTLP_ENDPOINT: "OTEL_EXPORTER_OTLP_ENDPOINT",
21
+ OTEL_EXPORTER_TYPE: "OTEL_EXPORTER_TYPE",
22
+ OTEL_SAMPLING_RATE: "OTEL_SAMPLING_RATE",
23
+ OTEL_PROPAGATION_FORMAT: "OTEL_PROPAGATION_FORMAT",
24
+ // Metrics
25
+ METRICS_EXPORTER_TYPE: "METRICS_EXPORTER_TYPE",
26
+ METRICS_PROMETHEUS_ENDPOINT: "METRICS_PROMETHEUS_ENDPOINT",
27
+ METRICS_PROMETHEUS_PORT: "METRICS_PROMETHEUS_PORT",
28
+ METRICS_COLLECT_INTERVAL: "METRICS_COLLECT_INTERVAL",
29
+ METRICS_DEFAULT_ENABLED: "METRICS_DEFAULT_ENABLED",
30
+ METRICS_PREFIX: "METRICS_PREFIX",
31
+ // Database
32
+ DB_INSTRUMENTATION_INCLUDE_STATEMENT: "DB_INSTRUMENTATION_INCLUDE_STATEMENT",
33
+ DB_INSTRUMENTATION_SLOW_QUERY_THRESHOLD: "DB_INSTRUMENTATION_SLOW_QUERY_THRESHOLD",
34
+ // GraphQL
35
+ GRAPHQL_INSTRUMENTATION_INCLUDE_DOCUMENT: "GRAPHQL_INSTRUMENTATION_INCLUDE_DOCUMENT",
36
+ GRAPHQL_INSTRUMENTATION_INCLUDE_VARIABLES: "GRAPHQL_INSTRUMENTATION_INCLUDE_VARIABLES",
37
+ GRAPHQL_INSTRUMENTATION_INCLUDE_RESOLVERS: "GRAPHQL_INSTRUMENTATION_INCLUDE_RESOLVERS"
38
+ };
39
+ function getEnvBoolean(key, defaultValue) {
40
+ const value = process.env[key];
41
+ if (value === void 0 || value === "") return defaultValue;
42
+ return value.toLowerCase() === "true" || value === "1";
43
+ }
44
+ __name(getEnvBoolean, "getEnvBoolean");
45
+ function getEnvNumber(key, defaultValue) {
46
+ const value = process.env[key];
47
+ if (value === void 0 || value === "") return defaultValue;
48
+ const parsed = parseFloat(value);
49
+ return isNaN(parsed) ? defaultValue : parsed;
50
+ }
51
+ __name(getEnvNumber, "getEnvNumber");
52
+ function getEnvString(key, defaultValue) {
53
+ const value = process.env[key];
54
+ return value !== void 0 && value !== "" ? value : defaultValue;
55
+ }
56
+ __name(getEnvString, "getEnvString");
57
+ var DEFAULT_FEATURE_FLAGS = {
58
+ tracing: true,
59
+ metrics: true,
60
+ logging: true,
61
+ graphql: true,
62
+ database: true,
63
+ http: true,
64
+ cache: true,
65
+ eventQueue: true
66
+ };
67
+ var DEFAULT_TRACING_CONFIG = {
68
+ enabled: true,
69
+ serviceName: "unknown-service",
70
+ serviceVersion: "1.0.0",
71
+ environment: "development",
72
+ exporterType: "none",
73
+ samplingRate: 1,
74
+ propagationFormat: "w3c",
75
+ resourceAttributes: {},
76
+ ignoredRoutes: [
77
+ "/health",
78
+ "/ready",
79
+ "/live",
80
+ "/metrics"
81
+ ],
82
+ ignoredOperations: [
83
+ "IntrospectionQuery"
84
+ ]
85
+ };
86
+ var DEFAULT_METRICS_CONFIG = {
87
+ enabled: true,
88
+ serviceName: "unknown-service",
89
+ exporterType: "none",
90
+ prometheusEndpoint: "/metrics",
91
+ prometheusPort: 9090,
92
+ collectInterval: 6e4,
93
+ defaultMetrics: true,
94
+ metricPrefix: ""
95
+ };
96
+ var DEFAULT_LOGGING_CONFIG = {
97
+ enabled: true,
98
+ includeTraceId: true,
99
+ includeSpanId: true,
100
+ includeTraceFlags: false,
101
+ level: "info"
102
+ };
103
+ var DEFAULT_GRAPHQL_CONFIG = {
104
+ enabled: true,
105
+ includeDocument: false,
106
+ includeVariables: false,
107
+ includeResult: false,
108
+ documentDepth: 3,
109
+ ignoredOperations: [
110
+ "IntrospectionQuery"
111
+ ],
112
+ includeResolvers: true,
113
+ resolverSpanDepth: 3
114
+ };
115
+ var DEFAULT_DATABASE_CONFIG = {
116
+ enabled: true,
117
+ includeStatement: false,
118
+ includeParameters: false,
119
+ includeRowCount: true,
120
+ slowQueryThreshold: 1e3,
121
+ ignoredOperations: []
122
+ };
123
+ var DEFAULT_HTTP_CONFIG = {
124
+ enabled: true,
125
+ includeRequestHeaders: false,
126
+ includeResponseHeaders: false,
127
+ includeRequestBody: false,
128
+ includeResponseBody: false,
129
+ redactedHeaders: [
130
+ "authorization",
131
+ "cookie",
132
+ "set-cookie",
133
+ "x-api-key"
134
+ ],
135
+ ignoredRoutes: [
136
+ "/health",
137
+ "/ready",
138
+ "/live",
139
+ "/metrics"
140
+ ],
141
+ maxBodySize: 10240
142
+ };
143
+ var DEFAULT_CACHE_CONFIG = {
144
+ enabled: true,
145
+ includeKey: true,
146
+ includeValueSize: true,
147
+ includeTTL: true
148
+ };
149
+ var DEFAULT_EVENT_QUEUE_CONFIG = {
150
+ enabled: true,
151
+ includePayload: false,
152
+ includeHeaders: true,
153
+ maxPayloadSize: 1024
154
+ };
155
+ var globalConfig = null;
156
+ function buildFeatureFlags(overrides) {
157
+ return {
158
+ tracing: getEnvBoolean(ENV_VARS.INSTRUMENTATION_TRACING, DEFAULT_FEATURE_FLAGS.tracing),
159
+ metrics: getEnvBoolean(ENV_VARS.INSTRUMENTATION_METRICS, DEFAULT_FEATURE_FLAGS.metrics),
160
+ logging: getEnvBoolean(ENV_VARS.INSTRUMENTATION_LOGGING, DEFAULT_FEATURE_FLAGS.logging),
161
+ graphql: getEnvBoolean(ENV_VARS.INSTRUMENTATION_GRAPHQL, DEFAULT_FEATURE_FLAGS.graphql),
162
+ database: getEnvBoolean(ENV_VARS.INSTRUMENTATION_DATABASE, DEFAULT_FEATURE_FLAGS.database),
163
+ http: getEnvBoolean(ENV_VARS.INSTRUMENTATION_HTTP, DEFAULT_FEATURE_FLAGS.http),
164
+ cache: getEnvBoolean(ENV_VARS.INSTRUMENTATION_CACHE, DEFAULT_FEATURE_FLAGS.cache),
165
+ eventQueue: getEnvBoolean(ENV_VARS.INSTRUMENTATION_EVENT_QUEUE, DEFAULT_FEATURE_FLAGS.eventQueue),
166
+ ...overrides
167
+ };
168
+ }
169
+ __name(buildFeatureFlags, "buildFeatureFlags");
170
+ function buildTracingConfig(serviceName, overrides) {
171
+ return {
172
+ enabled: getEnvBoolean(ENV_VARS.INSTRUMENTATION_TRACING, DEFAULT_TRACING_CONFIG.enabled),
173
+ serviceName: getEnvString(ENV_VARS.OTEL_SERVICE_NAME, serviceName),
174
+ serviceVersion: getEnvString(ENV_VARS.OTEL_SERVICE_VERSION, DEFAULT_TRACING_CONFIG.serviceVersion),
175
+ environment: getEnvString(ENV_VARS.OTEL_ENVIRONMENT, process.env["NODE_ENV"] || "development"),
176
+ exporterEndpoint: process.env[ENV_VARS.OTEL_EXPORTER_OTLP_ENDPOINT],
177
+ exporterType: getEnvString(ENV_VARS.OTEL_EXPORTER_TYPE, DEFAULT_TRACING_CONFIG.exporterType),
178
+ samplingRate: getEnvNumber(ENV_VARS.OTEL_SAMPLING_RATE, DEFAULT_TRACING_CONFIG.samplingRate),
179
+ propagationFormat: getEnvString(ENV_VARS.OTEL_PROPAGATION_FORMAT, DEFAULT_TRACING_CONFIG.propagationFormat),
180
+ resourceAttributes: DEFAULT_TRACING_CONFIG.resourceAttributes,
181
+ ignoredRoutes: DEFAULT_TRACING_CONFIG.ignoredRoutes,
182
+ ignoredOperations: DEFAULT_TRACING_CONFIG.ignoredOperations,
183
+ ...overrides
184
+ };
185
+ }
186
+ __name(buildTracingConfig, "buildTracingConfig");
187
+ function buildMetricsConfig(serviceName, overrides) {
188
+ return {
189
+ enabled: getEnvBoolean(ENV_VARS.INSTRUMENTATION_METRICS, DEFAULT_METRICS_CONFIG.enabled),
190
+ serviceName: getEnvString(ENV_VARS.OTEL_SERVICE_NAME, serviceName),
191
+ exporterEndpoint: process.env[ENV_VARS.OTEL_EXPORTER_OTLP_ENDPOINT],
192
+ exporterType: getEnvString(ENV_VARS.METRICS_EXPORTER_TYPE, DEFAULT_METRICS_CONFIG.exporterType),
193
+ prometheusEndpoint: getEnvString(ENV_VARS.METRICS_PROMETHEUS_ENDPOINT, DEFAULT_METRICS_CONFIG.prometheusEndpoint),
194
+ prometheusPort: getEnvNumber(ENV_VARS.METRICS_PROMETHEUS_PORT, DEFAULT_METRICS_CONFIG.prometheusPort),
195
+ collectInterval: getEnvNumber(ENV_VARS.METRICS_COLLECT_INTERVAL, DEFAULT_METRICS_CONFIG.collectInterval),
196
+ defaultMetrics: getEnvBoolean(ENV_VARS.METRICS_DEFAULT_ENABLED, DEFAULT_METRICS_CONFIG.defaultMetrics),
197
+ metricPrefix: getEnvString(ENV_VARS.METRICS_PREFIX, DEFAULT_METRICS_CONFIG.metricPrefix),
198
+ ...overrides
199
+ };
200
+ }
201
+ __name(buildMetricsConfig, "buildMetricsConfig");
202
+ function buildDatabaseConfig(overrides) {
203
+ return {
204
+ enabled: getEnvBoolean(ENV_VARS.INSTRUMENTATION_DATABASE, DEFAULT_DATABASE_CONFIG.enabled),
205
+ includeStatement: getEnvBoolean(ENV_VARS.DB_INSTRUMENTATION_INCLUDE_STATEMENT, DEFAULT_DATABASE_CONFIG.includeStatement),
206
+ includeParameters: DEFAULT_DATABASE_CONFIG.includeParameters,
207
+ includeRowCount: DEFAULT_DATABASE_CONFIG.includeRowCount,
208
+ slowQueryThreshold: getEnvNumber(ENV_VARS.DB_INSTRUMENTATION_SLOW_QUERY_THRESHOLD, DEFAULT_DATABASE_CONFIG.slowQueryThreshold),
209
+ ignoredOperations: DEFAULT_DATABASE_CONFIG.ignoredOperations,
210
+ ...overrides
211
+ };
212
+ }
213
+ __name(buildDatabaseConfig, "buildDatabaseConfig");
214
+ function buildGraphQLConfig(overrides) {
215
+ return {
216
+ enabled: getEnvBoolean(ENV_VARS.INSTRUMENTATION_GRAPHQL, DEFAULT_GRAPHQL_CONFIG.enabled),
217
+ includeDocument: getEnvBoolean(ENV_VARS.GRAPHQL_INSTRUMENTATION_INCLUDE_DOCUMENT, DEFAULT_GRAPHQL_CONFIG.includeDocument),
218
+ includeVariables: getEnvBoolean(ENV_VARS.GRAPHQL_INSTRUMENTATION_INCLUDE_VARIABLES, DEFAULT_GRAPHQL_CONFIG.includeVariables),
219
+ includeResult: DEFAULT_GRAPHQL_CONFIG.includeResult,
220
+ documentDepth: DEFAULT_GRAPHQL_CONFIG.documentDepth,
221
+ ignoredOperations: DEFAULT_GRAPHQL_CONFIG.ignoredOperations,
222
+ includeResolvers: getEnvBoolean(ENV_VARS.GRAPHQL_INSTRUMENTATION_INCLUDE_RESOLVERS, DEFAULT_GRAPHQL_CONFIG.includeResolvers),
223
+ resolverSpanDepth: DEFAULT_GRAPHQL_CONFIG.resolverSpanDepth,
224
+ ...overrides
225
+ };
226
+ }
227
+ __name(buildGraphQLConfig, "buildGraphQLConfig");
228
+ function buildInstrumentationConfig(serviceName, overrides) {
229
+ const enabled = getEnvBoolean(ENV_VARS.INSTRUMENTATION_ENABLED, true);
230
+ return {
231
+ enabled,
232
+ features: buildFeatureFlags(overrides?.features),
233
+ tracing: buildTracingConfig(serviceName, overrides?.tracing),
234
+ metrics: buildMetricsConfig(serviceName, overrides?.metrics),
235
+ logging: {
236
+ ...DEFAULT_LOGGING_CONFIG,
237
+ ...overrides?.logging
238
+ },
239
+ graphql: buildGraphQLConfig(overrides?.graphql),
240
+ database: buildDatabaseConfig(overrides?.database),
241
+ http: {
242
+ ...DEFAULT_HTTP_CONFIG,
243
+ ...overrides?.http
244
+ },
245
+ cache: {
246
+ ...DEFAULT_CACHE_CONFIG,
247
+ ...overrides?.cache
248
+ },
249
+ eventQueue: {
250
+ ...DEFAULT_EVENT_QUEUE_CONFIG,
251
+ ...overrides?.eventQueue
252
+ }
253
+ };
254
+ }
255
+ __name(buildInstrumentationConfig, "buildInstrumentationConfig");
256
+ function initializeInstrumentationConfig(serviceName, overrides) {
257
+ globalConfig = buildInstrumentationConfig(serviceName, overrides);
258
+ return globalConfig;
259
+ }
260
+ __name(initializeInstrumentationConfig, "initializeInstrumentationConfig");
261
+ function getInstrumentationConfig() {
262
+ if (!globalConfig) {
263
+ throw new Error("Instrumentation config not initialized. Call initializeInstrumentationConfig() first.");
264
+ }
265
+ return globalConfig;
266
+ }
267
+ __name(getInstrumentationConfig, "getInstrumentationConfig");
268
+ function isInstrumentationConfigInitialized() {
269
+ return globalConfig !== null;
270
+ }
271
+ __name(isInstrumentationConfigInitialized, "isInstrumentationConfigInitialized");
272
+ function isFeatureEnabled(feature) {
273
+ if (!globalConfig) return false;
274
+ return globalConfig.enabled && globalConfig.features[feature];
275
+ }
276
+ __name(isFeatureEnabled, "isFeatureEnabled");
277
+ function updateInstrumentationConfig(updates) {
278
+ if (!globalConfig) {
279
+ throw new Error("Instrumentation config not initialized. Call initializeInstrumentationConfig() first.");
280
+ }
281
+ globalConfig = {
282
+ ...globalConfig,
283
+ ...updates
284
+ };
285
+ return globalConfig;
286
+ }
287
+ __name(updateInstrumentationConfig, "updateInstrumentationConfig");
288
+ function resetInstrumentationConfig() {
289
+ globalConfig = null;
290
+ }
291
+ __name(resetInstrumentationConfig, "resetInstrumentationConfig");
292
+
293
+ // src/instrumentation/metrics-collector.ts
294
+ function getLabelKey(labels) {
295
+ if (!labels || Object.keys(labels).length === 0) return "";
296
+ return Object.entries(labels).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${k}=${v}`).join(",");
297
+ }
298
+ __name(getLabelKey, "getLabelKey");
299
+ var InMemoryCounter = class InMemoryCounter2 {
300
+ static {
301
+ __name(this, "InMemoryCounter");
302
+ }
303
+ values = /* @__PURE__ */ new Map();
304
+ name;
305
+ description;
306
+ constructor(name, description) {
307
+ this.name = name;
308
+ this.description = description;
309
+ }
310
+ add(value, labels) {
311
+ const key = getLabelKey(labels);
312
+ const current = this.values.get(key) || 0;
313
+ this.values.set(key, current + value);
314
+ }
315
+ inc(labels) {
316
+ this.add(1, labels);
317
+ }
318
+ getValue(labels) {
319
+ const key = getLabelKey(labels);
320
+ return this.values.get(key) || 0;
321
+ }
322
+ getName() {
323
+ return this.name;
324
+ }
325
+ getDescription() {
326
+ return this.description;
327
+ }
328
+ getAllValues() {
329
+ return new Map(this.values);
330
+ }
331
+ reset() {
332
+ this.values.clear();
333
+ }
334
+ };
335
+ var InMemoryHistogram = class InMemoryHistogram2 {
336
+ static {
337
+ __name(this, "InMemoryHistogram");
338
+ }
339
+ values = /* @__PURE__ */ new Map();
340
+ name;
341
+ description;
342
+ boundaries;
343
+ constructor(name, description, boundaries) {
344
+ this.name = name;
345
+ this.description = description;
346
+ this.boundaries = boundaries || [
347
+ 5,
348
+ 10,
349
+ 25,
350
+ 50,
351
+ 100,
352
+ 250,
353
+ 500,
354
+ 1e3,
355
+ 2500,
356
+ 5e3,
357
+ 1e4
358
+ ];
359
+ }
360
+ record(value, labels) {
361
+ const key = getLabelKey(labels);
362
+ const existing = this.values.get(key) || [];
363
+ existing.push(value);
364
+ if (existing.length > 1e4) {
365
+ existing.shift();
366
+ }
367
+ this.values.set(key, existing);
368
+ }
369
+ getData(labels) {
370
+ const key = getLabelKey(labels);
371
+ const values = this.values.get(key) || [];
372
+ if (values.length === 0) {
373
+ return {
374
+ count: 0,
375
+ sum: 0,
376
+ min: 0,
377
+ max: 0,
378
+ avg: 0,
379
+ buckets: /* @__PURE__ */ new Map(),
380
+ percentiles: {
381
+ p50: 0,
382
+ p75: 0,
383
+ p90: 0,
384
+ p95: 0,
385
+ p99: 0
386
+ }
387
+ };
388
+ }
389
+ const sorted = [
390
+ ...values
391
+ ].sort((a, b) => a - b);
392
+ const sum = values.reduce((a, b) => a + b, 0);
393
+ const buckets = /* @__PURE__ */ new Map();
394
+ for (const boundary of this.boundaries) {
395
+ buckets.set(boundary, values.filter((v) => v <= boundary).length);
396
+ }
397
+ buckets.set(Infinity, values.length);
398
+ const percentile = /* @__PURE__ */ __name((p) => {
399
+ const index = Math.ceil(p / 100 * sorted.length) - 1;
400
+ return sorted[Math.max(0, index)] || 0;
401
+ }, "percentile");
402
+ return {
403
+ count: values.length,
404
+ sum,
405
+ min: sorted[0] || 0,
406
+ max: sorted[sorted.length - 1] || 0,
407
+ avg: sum / values.length,
408
+ buckets,
409
+ percentiles: {
410
+ p50: percentile(50),
411
+ p75: percentile(75),
412
+ p90: percentile(90),
413
+ p95: percentile(95),
414
+ p99: percentile(99)
415
+ }
416
+ };
417
+ }
418
+ getName() {
419
+ return this.name;
420
+ }
421
+ getDescription() {
422
+ return this.description;
423
+ }
424
+ getAllData() {
425
+ const result = /* @__PURE__ */ new Map();
426
+ for (const [key] of this.values) {
427
+ result.set(key, this.getData(key ? this.parseLabels(key) : void 0));
428
+ }
429
+ return result;
430
+ }
431
+ parseLabels(key) {
432
+ const labels = {};
433
+ for (const part of key.split(",")) {
434
+ const [k, v] = part.split("=");
435
+ if (k && v) labels[k] = v;
436
+ }
437
+ return labels;
438
+ }
439
+ reset() {
440
+ this.values.clear();
441
+ }
442
+ };
443
+ var InMemoryGauge = class InMemoryGauge2 {
444
+ static {
445
+ __name(this, "InMemoryGauge");
446
+ }
447
+ values = /* @__PURE__ */ new Map();
448
+ name;
449
+ description;
450
+ constructor(name, description) {
451
+ this.name = name;
452
+ this.description = description;
453
+ }
454
+ set(value, labels) {
455
+ const key = getLabelKey(labels);
456
+ this.values.set(key, value);
457
+ }
458
+ // eslint-disable-next-line sonarjs/no-identical-functions -- Shared implementation across metric types by design
459
+ add(value, labels) {
460
+ const key = getLabelKey(labels);
461
+ const current = this.values.get(key) || 0;
462
+ this.values.set(key, current + value);
463
+ }
464
+ sub(value, labels) {
465
+ this.add(-value, labels);
466
+ }
467
+ getValue(labels) {
468
+ const key = getLabelKey(labels);
469
+ return this.values.get(key) || 0;
470
+ }
471
+ getName() {
472
+ return this.name;
473
+ }
474
+ getDescription() {
475
+ return this.description;
476
+ }
477
+ getAllValues() {
478
+ return new Map(this.values);
479
+ }
480
+ reset() {
481
+ this.values.clear();
482
+ }
483
+ };
484
+ var InMemoryUpDownCounter = class InMemoryUpDownCounter2 {
485
+ static {
486
+ __name(this, "InMemoryUpDownCounter");
487
+ }
488
+ values = /* @__PURE__ */ new Map();
489
+ name;
490
+ description;
491
+ constructor(name, description) {
492
+ this.name = name;
493
+ this.description = description;
494
+ }
495
+ // eslint-disable-next-line sonarjs/no-identical-functions -- Shared implementation across metric types by design
496
+ add(value, labels) {
497
+ const key = getLabelKey(labels);
498
+ const current = this.values.get(key) || 0;
499
+ this.values.set(key, current + value);
500
+ }
501
+ getValue(labels) {
502
+ const key = getLabelKey(labels);
503
+ return this.values.get(key) || 0;
504
+ }
505
+ getName() {
506
+ return this.name;
507
+ }
508
+ getDescription() {
509
+ return this.description;
510
+ }
511
+ getAllValues() {
512
+ return new Map(this.values);
513
+ }
514
+ reset() {
515
+ this.values.clear();
516
+ }
517
+ };
518
+ var NoOpCounter = class NoOpCounter2 {
519
+ static {
520
+ __name(this, "NoOpCounter");
521
+ }
522
+ add() {
523
+ }
524
+ inc() {
525
+ }
526
+ getValue() {
527
+ return 0;
528
+ }
529
+ };
530
+ var NoOpHistogram = class NoOpHistogram2 {
531
+ static {
532
+ __name(this, "NoOpHistogram");
533
+ }
534
+ record() {
535
+ }
536
+ getData() {
537
+ return {
538
+ count: 0,
539
+ sum: 0,
540
+ min: 0,
541
+ max: 0,
542
+ avg: 0,
543
+ buckets: /* @__PURE__ */ new Map(),
544
+ percentiles: {
545
+ p50: 0,
546
+ p75: 0,
547
+ p90: 0,
548
+ p95: 0,
549
+ p99: 0
550
+ }
551
+ };
552
+ }
553
+ };
554
+ var NoOpGauge = class NoOpGauge2 {
555
+ static {
556
+ __name(this, "NoOpGauge");
557
+ }
558
+ set() {
559
+ }
560
+ add() {
561
+ }
562
+ sub() {
563
+ }
564
+ getValue() {
565
+ return 0;
566
+ }
567
+ };
568
+ var NoOpUpDownCounter = class NoOpUpDownCounter2 {
569
+ static {
570
+ __name(this, "NoOpUpDownCounter");
571
+ }
572
+ add() {
573
+ }
574
+ getValue() {
575
+ return 0;
576
+ }
577
+ };
578
+ var MetricsRegistry = class {
579
+ static {
580
+ __name(this, "MetricsRegistry");
581
+ }
582
+ counters = /* @__PURE__ */ new Map();
583
+ histograms = /* @__PURE__ */ new Map();
584
+ gauges = /* @__PURE__ */ new Map();
585
+ upDownCounters = /* @__PURE__ */ new Map();
586
+ serviceName;
587
+ metricPrefix;
588
+ constructor(serviceName, metricPrefix = "") {
589
+ this.serviceName = serviceName;
590
+ this.metricPrefix = metricPrefix;
591
+ }
592
+ /**
593
+ * Get service name
594
+ */
595
+ getServiceName() {
596
+ return this.serviceName;
597
+ }
598
+ /**
599
+ * Check if metrics are enabled
600
+ */
601
+ isEnabled() {
602
+ return isInstrumentationConfigInitialized() && isFeatureEnabled("metrics");
603
+ }
604
+ /**
605
+ * Get prefixed metric name
606
+ */
607
+ getPrefixedName(name) {
608
+ return this.metricPrefix ? `${this.metricPrefix}_${name}` : name;
609
+ }
610
+ /**
611
+ * Create or get a counter
612
+ */
613
+ createCounter(name, description) {
614
+ if (!this.isEnabled()) {
615
+ return new NoOpCounter();
616
+ }
617
+ const prefixedName = this.getPrefixedName(name);
618
+ let counter = this.counters.get(prefixedName);
619
+ if (!counter) {
620
+ counter = new InMemoryCounter(prefixedName, description);
621
+ this.counters.set(prefixedName, counter);
622
+ }
623
+ return counter;
624
+ }
625
+ /**
626
+ * Create or get a histogram
627
+ */
628
+ createHistogram(name, description, boundaries) {
629
+ if (!this.isEnabled()) {
630
+ return new NoOpHistogram();
631
+ }
632
+ const prefixedName = this.getPrefixedName(name);
633
+ let histogram = this.histograms.get(prefixedName);
634
+ if (!histogram) {
635
+ histogram = new InMemoryHistogram(prefixedName, description, boundaries);
636
+ this.histograms.set(prefixedName, histogram);
637
+ }
638
+ return histogram;
639
+ }
640
+ /**
641
+ * Create or get a gauge
642
+ */
643
+ createGauge(name, description) {
644
+ if (!this.isEnabled()) {
645
+ return new NoOpGauge();
646
+ }
647
+ const prefixedName = this.getPrefixedName(name);
648
+ let gauge = this.gauges.get(prefixedName);
649
+ if (!gauge) {
650
+ gauge = new InMemoryGauge(prefixedName, description);
651
+ this.gauges.set(prefixedName, gauge);
652
+ }
653
+ return gauge;
654
+ }
655
+ /**
656
+ * Create or get an up-down counter
657
+ */
658
+ createUpDownCounter(name, description) {
659
+ if (!this.isEnabled()) {
660
+ return new NoOpUpDownCounter();
661
+ }
662
+ const prefixedName = this.getPrefixedName(name);
663
+ let counter = this.upDownCounters.get(prefixedName);
664
+ if (!counter) {
665
+ counter = new InMemoryUpDownCounter(prefixedName, description);
666
+ this.upDownCounters.set(prefixedName, counter);
667
+ }
668
+ return counter;
669
+ }
670
+ /**
671
+ * Create metric from definition
672
+ */
673
+ createFromDefinition(definition) {
674
+ switch (definition.type) {
675
+ case "counter":
676
+ return this.createCounter(definition.name, definition.description);
677
+ case "histogram":
678
+ return this.createHistogram(definition.name, definition.description, definition.boundaries);
679
+ case "gauge":
680
+ return this.createGauge(definition.name, definition.description);
681
+ case "upDownCounter":
682
+ return this.createUpDownCounter(definition.name, definition.description);
683
+ default:
684
+ throw new Error(`Unknown metric type: ${definition.type}`);
685
+ }
686
+ }
687
+ /**
688
+ * Get all metrics data
689
+ */
690
+ getAllMetrics() {
691
+ return {
692
+ counters: Array.from(this.counters.values()).map((c) => ({
693
+ name: c.getName(),
694
+ description: c.getDescription(),
695
+ values: c.getAllValues()
696
+ })),
697
+ histograms: Array.from(this.histograms.values()).map((h) => ({
698
+ name: h.getName(),
699
+ description: h.getDescription(),
700
+ data: h.getAllData()
701
+ })),
702
+ gauges: Array.from(this.gauges.values()).map((g) => ({
703
+ name: g.getName(),
704
+ description: g.getDescription(),
705
+ values: g.getAllValues()
706
+ })),
707
+ upDownCounters: Array.from(this.upDownCounters.values()).map((c) => ({
708
+ name: c.getName(),
709
+ description: c.getDescription(),
710
+ values: c.getAllValues()
711
+ }))
712
+ };
713
+ }
714
+ /**
715
+ * Export counter metrics to Prometheus format
716
+ */
717
+ exportCountersToPrometheus(lines) {
718
+ for (const counter of this.counters.values()) {
719
+ lines.push(`# HELP ${counter.getName()} ${counter.getDescription()}`);
720
+ lines.push(`# TYPE ${counter.getName()} counter`);
721
+ for (const [labels, value] of counter.getAllValues()) {
722
+ const labelStr = labels ? `{${labels}}` : "";
723
+ lines.push(`${counter.getName()}${labelStr} ${value}`);
724
+ }
725
+ }
726
+ }
727
+ /**
728
+ * Export histogram metrics to Prometheus format
729
+ */
730
+ exportHistogramsToPrometheus(lines) {
731
+ for (const histogram of this.histograms.values()) {
732
+ lines.push(`# HELP ${histogram.getName()} ${histogram.getDescription()}`);
733
+ lines.push(`# TYPE ${histogram.getName()} histogram`);
734
+ for (const [labels, data] of histogram.getAllData()) {
735
+ const labelStr = labels ? `,${labels}` : "";
736
+ for (const [le, count] of data.buckets) {
737
+ const leStr = le === Infinity ? "+Inf" : le.toString();
738
+ lines.push(`${histogram.getName()}_bucket{le="${leStr}"${labelStr}} ${count}`);
739
+ }
740
+ lines.push(`${histogram.getName()}_sum{${labels || ""}} ${data.sum}`);
741
+ lines.push(`${histogram.getName()}_count{${labels || ""}} ${data.count}`);
742
+ }
743
+ }
744
+ }
745
+ /**
746
+ * Export gauge metrics to Prometheus format
747
+ */
748
+ exportGaugesToPrometheus(lines) {
749
+ for (const gauge of this.gauges.values()) {
750
+ lines.push(`# HELP ${gauge.getName()} ${gauge.getDescription()}`);
751
+ lines.push(`# TYPE ${gauge.getName()} gauge`);
752
+ for (const [labels, value] of gauge.getAllValues()) {
753
+ const labelStr = labels ? `{${labels}}` : "";
754
+ lines.push(`${gauge.getName()}${labelStr} ${value}`);
755
+ }
756
+ }
757
+ }
758
+ /**
759
+ * Export up-down counter metrics to Prometheus format (as gauges)
760
+ */
761
+ exportUpDownCountersToPrometheus(lines) {
762
+ for (const counter of this.upDownCounters.values()) {
763
+ lines.push(`# HELP ${counter.getName()} ${counter.getDescription()}`);
764
+ lines.push(`# TYPE ${counter.getName()} gauge`);
765
+ for (const [labels, value] of counter.getAllValues()) {
766
+ const labelStr = labels ? `{${labels}}` : "";
767
+ lines.push(`${counter.getName()}${labelStr} ${value}`);
768
+ }
769
+ }
770
+ }
771
+ /**
772
+ * Export metrics in Prometheus format
773
+ */
774
+ toPrometheusFormat() {
775
+ const lines = [];
776
+ this.exportCountersToPrometheus(lines);
777
+ this.exportHistogramsToPrometheus(lines);
778
+ this.exportGaugesToPrometheus(lines);
779
+ this.exportUpDownCountersToPrometheus(lines);
780
+ return lines.join("\n");
781
+ }
782
+ /**
783
+ * Reset all metrics
784
+ */
785
+ reset() {
786
+ for (const counter of this.counters.values()) {
787
+ counter.reset();
788
+ }
789
+ for (const histogram of this.histograms.values()) {
790
+ histogram.reset();
791
+ }
792
+ for (const gauge of this.gauges.values()) {
793
+ gauge.reset();
794
+ }
795
+ for (const counter of this.upDownCounters.values()) {
796
+ counter.reset();
797
+ }
798
+ }
799
+ /**
800
+ * Clear all metrics (remove registrations)
801
+ */
802
+ clear() {
803
+ this.counters.clear();
804
+ this.histograms.clear();
805
+ this.gauges.clear();
806
+ this.upDownCounters.clear();
807
+ }
808
+ };
809
+ var globalRegistry = null;
810
+ function initializeMetricsRegistry(serviceName, metricPrefix = "") {
811
+ globalRegistry = new MetricsRegistry(serviceName, metricPrefix);
812
+ return globalRegistry;
813
+ }
814
+ __name(initializeMetricsRegistry, "initializeMetricsRegistry");
815
+ function getMetricsRegistry() {
816
+ if (!globalRegistry) {
817
+ globalRegistry = new MetricsRegistry("unknown-service");
818
+ }
819
+ return globalRegistry;
820
+ }
821
+ __name(getMetricsRegistry, "getMetricsRegistry");
822
+ function isMetricsRegistryInitialized() {
823
+ return globalRegistry !== null;
824
+ }
825
+ __name(isMetricsRegistryInitialized, "isMetricsRegistryInitialized");
826
+ function resetMetricsRegistry() {
827
+ if (globalRegistry) {
828
+ globalRegistry.clear();
829
+ }
830
+ globalRegistry = null;
831
+ }
832
+ __name(resetMetricsRegistry, "resetMetricsRegistry");
833
+ function createCounter(name, description) {
834
+ return getMetricsRegistry().createCounter(name, description);
835
+ }
836
+ __name(createCounter, "createCounter");
837
+ function createHistogram(name, description, boundaries) {
838
+ return getMetricsRegistry().createHistogram(name, description, boundaries);
839
+ }
840
+ __name(createHistogram, "createHistogram");
841
+ function createGauge(name, description) {
842
+ return getMetricsRegistry().createGauge(name, description);
843
+ }
844
+ __name(createGauge, "createGauge");
845
+ function createUpDownCounter(name, description) {
846
+ return getMetricsRegistry().createUpDownCounter(name, description);
847
+ }
848
+ __name(createUpDownCounter, "createUpDownCounter");
849
+
850
+ export { DEFAULT_CACHE_CONFIG, DEFAULT_DATABASE_CONFIG, DEFAULT_EVENT_QUEUE_CONFIG, DEFAULT_FEATURE_FLAGS, DEFAULT_GRAPHQL_CONFIG, DEFAULT_HTTP_CONFIG, DEFAULT_LOGGING_CONFIG, DEFAULT_METRICS_CONFIG, DEFAULT_TRACING_CONFIG, ENV_VARS, MetricsRegistry, buildDatabaseConfig, buildFeatureFlags, buildGraphQLConfig, buildInstrumentationConfig, buildMetricsConfig, buildTracingConfig, createCounter, createGauge, createHistogram, createUpDownCounter, getInstrumentationConfig, getMetricsRegistry, initializeInstrumentationConfig, initializeMetricsRegistry, isFeatureEnabled, isInstrumentationConfigInitialized, isMetricsRegistryInitialized, resetInstrumentationConfig, resetMetricsRegistry, updateInstrumentationConfig };
851
+ //# sourceMappingURL=chunk-REF7PANB.js.map
852
+ //# sourceMappingURL=chunk-REF7PANB.js.map