@zucker-framework/monitoring 1.0.0 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2,7 +2,8 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/error-tracker.ts
5
- import { Injectable, Logger } from "@nestjs/common";
5
+ import { createHash } from "crypto";
6
+ import { Injectable, Logger, Inject, Optional } from "@nestjs/common";
6
7
  function _ts_decorate(decorators, target, key, desc) {
7
8
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
8
9
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -17,40 +18,80 @@ function _ts_decorate(decorators, target, key, desc) {
17
18
  return c > 3 && r && Object.defineProperty(target, key, r), r;
18
19
  }
19
20
  __name(_ts_decorate, "_ts_decorate");
21
+ function _ts_metadata(metadataKey, metadataValue) {
22
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
23
+ return Reflect.metadata(metadataKey, metadataValue);
24
+ }
25
+ }
26
+ __name(_ts_metadata, "_ts_metadata");
27
+ function _ts_param(paramIndex, decorator) {
28
+ return function(target, key) {
29
+ decorator(target, key, paramIndex);
30
+ };
31
+ }
32
+ __name(_ts_param, "_ts_param");
33
+ var ERROR_TRACKER_OPTIONS = /* @__PURE__ */ Symbol("ERROR_TRACKER_OPTIONS");
34
+ function errorFingerprint(error, endpoint = "") {
35
+ return createHash("sha256").update([
36
+ error.name,
37
+ error.message,
38
+ error.stack?.split("\n")[1]?.trim() ?? "",
39
+ endpoint
40
+ ].join("::")).digest("hex");
41
+ }
42
+ __name(errorFingerprint, "errorFingerprint");
20
43
  var ErrorTracker = class _ErrorTracker {
21
44
  static {
22
45
  __name(this, "ErrorTracker");
23
46
  }
47
+ options;
24
48
  logger = new Logger(_ErrorTracker.name);
25
49
  errors = /* @__PURE__ */ new Map();
26
50
  counter = 0;
51
+ constructor(options = {}) {
52
+ this.options = options;
53
+ if (options.retentionMs !== void 0 && (!Number.isFinite(options.retentionMs) || options.retentionMs <= 0)) throw new Error("Invalid error retention window");
54
+ }
55
+ prune() {
56
+ if (this.options.retentionMs === void 0) return;
57
+ const cutoff = Date.now() - this.options.retentionMs;
58
+ for (const [key, record] of this.errors) if (record.firstOccurrence.getTime() <= cutoff) this.errors.delete(key);
59
+ }
27
60
  track(error, category = "unknown", metadata) {
28
- const key = `${category}:${error.message}`;
61
+ this.prune();
62
+ const key = this.options.fingerprint?.(error, category, metadata) ?? `${category}:${error.message}`;
63
+ const safeMetadata = metadata ? this.options.sanitizeMetadata?.(metadata) ?? metadata : void 0;
29
64
  const existing = this.errors.get(key);
30
65
  if (existing) {
31
66
  existing.count++;
32
67
  existing.lastOccurrence = /* @__PURE__ */ new Date();
33
- if (metadata) {
68
+ if (safeMetadata) {
34
69
  existing.metadata = {
35
70
  ...existing.metadata,
36
- ...metadata
71
+ ...safeMetadata
37
72
  };
38
73
  }
39
74
  } else {
40
- this.errors.set(key, {
75
+ const record = {
41
76
  id: `err_${++this.counter}`,
42
- message: error.message,
43
- stack: error.stack,
77
+ message: this.options.sanitizeText?.(error.message) ?? error.message,
78
+ stack: error.stack ? this.options.sanitizeText?.(error.stack) ?? error.stack : void 0,
44
79
  category,
45
80
  count: 1,
46
81
  firstOccurrence: /* @__PURE__ */ new Date(),
47
82
  lastOccurrence: /* @__PURE__ */ new Date(),
48
- metadata
49
- });
83
+ metadata: safeMetadata
84
+ };
85
+ this.errors.set(key, record);
86
+ this.options.onNewError?.(error, record);
87
+ }
88
+ if (this.options.logEntries !== false) {
89
+ const record = this.errors.get(key);
90
+ this.logger.warn(`[${category}] ${record.message} (count: ${record.count})`);
50
91
  }
51
- this.logger.warn(`[${category}] ${error.message} (count: ${this.errors.get(key).count})`);
52
92
  }
53
93
  getErrors() {
94
+ this.prune();
54
95
  return Array.from(this.errors.values());
55
96
  }
56
97
  getErrorsByCategory(category) {
@@ -71,7 +112,13 @@ var ErrorTracker = class _ErrorTracker {
71
112
  }
72
113
  };
73
114
  ErrorTracker = _ts_decorate([
74
- Injectable()
115
+ Injectable(),
116
+ _ts_param(0, Optional()),
117
+ _ts_param(0, Inject(ERROR_TRACKER_OPTIONS)),
118
+ _ts_metadata("design:type", Function),
119
+ _ts_metadata("design:paramtypes", [
120
+ typeof ErrorTrackerOptions === "undefined" ? Object : ErrorTrackerOptions
121
+ ])
75
122
  ], ErrorTracker);
76
123
 
77
124
  // src/error-reporter.ts
@@ -123,10 +170,22 @@ var HealthCheckService = class _HealthCheckService {
123
170
  unregisterIndicator(name) {
124
171
  this.indicators = this.indicators.filter((i) => i.name !== name);
125
172
  }
126
- async checkAll() {
173
+ /** Select a declared subset for readiness vs. diagnostics; absent indicators fail closed. */
174
+ async checkAll(names) {
127
175
  const checks = [];
128
176
  let overallStatus = "UP";
129
- for (const indicator of this.indicators) {
177
+ const indicators = names === void 0 ? this.indicators : names.map((name) => this.indicators.find((indicator) => indicator.name === name) ?? {
178
+ name,
179
+ check: /* @__PURE__ */ __name(async () => ({
180
+ name,
181
+ status: "DOWN",
182
+ details: {
183
+ error: "Health indicator not registered"
184
+ },
185
+ timestamp: /* @__PURE__ */ new Date()
186
+ }), "check")
187
+ });
188
+ for (const indicator of indicators) {
130
189
  try {
131
190
  const result = await indicator.check();
132
191
  checks.push(result);
@@ -700,12 +759,12 @@ function _ts_decorate4(decorators, target, key, desc) {
700
759
  return c > 3 && r && Object.defineProperty(target, key, r), r;
701
760
  }
702
761
  __name(_ts_decorate4, "_ts_decorate");
703
- function _ts_metadata(metadataKey, metadataValue) {
762
+ function _ts_metadata2(metadataKey, metadataValue) {
704
763
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
705
764
  return Reflect.metadata(metadataKey, metadataValue);
706
765
  }
707
766
  }
708
- __name(_ts_metadata, "_ts_metadata");
767
+ __name(_ts_metadata2, "_ts_metadata");
709
768
  var SystemMetricsCollector = class {
710
769
  static {
711
770
  __name(this, "SystemMetricsCollector");
@@ -828,14 +887,14 @@ var SystemMetricsCollector = class {
828
887
  };
829
888
  SystemMetricsCollector = _ts_decorate4([
830
889
  Injectable4(),
831
- _ts_metadata("design:type", Function),
832
- _ts_metadata("design:paramtypes", [
890
+ _ts_metadata2("design:type", Function),
891
+ _ts_metadata2("design:paramtypes", [
833
892
  typeof MetricsRegistry === "undefined" ? Object : MetricsRegistry
834
893
  ])
835
894
  ], SystemMetricsCollector);
836
895
 
837
896
  // src/metrics/prometheus-exporter.ts
838
- import { Controller, Get, Header, Inject } from "@nestjs/common";
897
+ import { Controller, Get, Header, Inject as Inject2 } from "@nestjs/common";
839
898
  function _ts_decorate5(decorators, target, key, desc) {
840
899
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
841
900
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -850,18 +909,18 @@ function _ts_decorate5(decorators, target, key, desc) {
850
909
  return c > 3 && r && Object.defineProperty(target, key, r), r;
851
910
  }
852
911
  __name(_ts_decorate5, "_ts_decorate");
853
- function _ts_metadata2(metadataKey, metadataValue) {
912
+ function _ts_metadata3(metadataKey, metadataValue) {
854
913
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
855
914
  return Reflect.metadata(metadataKey, metadataValue);
856
915
  }
857
916
  }
858
- __name(_ts_metadata2, "_ts_metadata");
859
- function _ts_param(paramIndex, decorator) {
917
+ __name(_ts_metadata3, "_ts_metadata");
918
+ function _ts_param2(paramIndex, decorator) {
860
919
  return function(target, key) {
861
920
  decorator(target, key, paramIndex);
862
921
  };
863
922
  }
864
- __name(_ts_param, "_ts_param");
923
+ __name(_ts_param2, "_ts_param");
865
924
  function formatLabels(labels) {
866
925
  const entries = Object.entries(labels);
867
926
  if (entries.length === 0) return "";
@@ -955,15 +1014,15 @@ var PrometheusExporter = class {
955
1014
  _ts_decorate5([
956
1015
  Get(),
957
1016
  Header("Content-Type", "text/plain; version=0.0.4; charset=utf-8"),
958
- _ts_metadata2("design:type", Function),
959
- _ts_metadata2("design:paramtypes", []),
960
- _ts_metadata2("design:returntype", String)
1017
+ _ts_metadata3("design:type", Function),
1018
+ _ts_metadata3("design:paramtypes", []),
1019
+ _ts_metadata3("design:returntype", String)
961
1020
  ], PrometheusExporter.prototype, "getMetrics", null);
962
1021
  PrometheusExporter = _ts_decorate5([
963
1022
  Controller("metrics"),
964
- _ts_param(0, Inject(MetricsRegistry)),
965
- _ts_metadata2("design:type", Function),
966
- _ts_metadata2("design:paramtypes", [
1023
+ _ts_param2(0, Inject2(MetricsRegistry)),
1024
+ _ts_metadata3("design:type", Function),
1025
+ _ts_metadata3("design:paramtypes", [
967
1026
  typeof MetricsRegistry === "undefined" ? Object : MetricsRegistry
968
1027
  ])
969
1028
  ], PrometheusExporter);
@@ -999,18 +1058,18 @@ function _ts_decorate6(decorators, target, key, desc) {
999
1058
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1000
1059
  }
1001
1060
  __name(_ts_decorate6, "_ts_decorate");
1002
- function _ts_metadata3(metadataKey, metadataValue) {
1061
+ function _ts_metadata4(metadataKey, metadataValue) {
1003
1062
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1004
1063
  return Reflect.metadata(metadataKey, metadataValue);
1005
1064
  }
1006
1065
  }
1007
- __name(_ts_metadata3, "_ts_metadata");
1008
- function _ts_param2(paramIndex, decorator) {
1066
+ __name(_ts_metadata4, "_ts_metadata");
1067
+ function _ts_param3(paramIndex, decorator) {
1009
1068
  return function(target, key) {
1010
1069
  decorator(target, key, paramIndex);
1011
1070
  };
1012
1071
  }
1013
- __name(_ts_param2, "_ts_param");
1072
+ __name(_ts_param3, "_ts_param");
1014
1073
  var Public = /* @__PURE__ */ __name(() => SetMetadata("zucker:auth:isPublic", true), "Public");
1015
1074
  var HEALTH_OPTIONS = /* @__PURE__ */ Symbol("HEALTH_OPTIONS");
1016
1075
  var HealthController = class {
@@ -1069,42 +1128,42 @@ var HealthController = class {
1069
1128
  };
1070
1129
  _ts_decorate6([
1071
1130
  Get2(),
1072
- _ts_param2(0, Res()),
1073
- _ts_metadata3("design:type", Function),
1074
- _ts_metadata3("design:paramtypes", [
1131
+ _ts_param3(0, Res()),
1132
+ _ts_metadata4("design:type", Function),
1133
+ _ts_metadata4("design:paramtypes", [
1075
1134
  Object
1076
1135
  ]),
1077
- _ts_metadata3("design:returntype", Promise)
1136
+ _ts_metadata4("design:returntype", Promise)
1078
1137
  ], HealthController.prototype, "check", null);
1079
1138
  _ts_decorate6([
1080
1139
  Get2("live"),
1081
- _ts_param2(0, Res()),
1082
- _ts_metadata3("design:type", Function),
1083
- _ts_metadata3("design:paramtypes", [
1140
+ _ts_param3(0, Res()),
1141
+ _ts_metadata4("design:type", Function),
1142
+ _ts_metadata4("design:paramtypes", [
1084
1143
  Object
1085
1144
  ]),
1086
- _ts_metadata3("design:returntype", void 0)
1145
+ _ts_metadata4("design:returntype", void 0)
1087
1146
  ], HealthController.prototype, "live", null);
1088
1147
  _ts_decorate6([
1089
1148
  Get2("ready"),
1090
- _ts_param2(0, Res()),
1091
- _ts_metadata3("design:type", Function),
1092
- _ts_metadata3("design:paramtypes", [
1149
+ _ts_param3(0, Res()),
1150
+ _ts_metadata4("design:type", Function),
1151
+ _ts_metadata4("design:paramtypes", [
1093
1152
  Object
1094
1153
  ]),
1095
- _ts_metadata3("design:returntype", Promise)
1154
+ _ts_metadata4("design:returntype", Promise)
1096
1155
  ], HealthController.prototype, "ready", null);
1097
1156
  HealthController = _ts_decorate6([
1098
1157
  Controller2("health"),
1099
1158
  Public(),
1100
- _ts_metadata3("design:type", Function),
1101
- _ts_metadata3("design:paramtypes", [
1159
+ _ts_metadata4("design:type", Function),
1160
+ _ts_metadata4("design:paramtypes", [
1102
1161
  typeof HealthCheckService === "undefined" ? Object : HealthCheckService
1103
1162
  ])
1104
1163
  ], HealthController);
1105
1164
 
1106
1165
  // src/alert/alert-manager.service.ts
1107
- import { Injectable as Injectable5, Logger as Logger3, Optional, Inject as Inject2 } from "@nestjs/common";
1166
+ import { Injectable as Injectable5, Logger as Logger3, Optional as Optional2, Inject as Inject3 } from "@nestjs/common";
1108
1167
  import { randomUUID } from "crypto";
1109
1168
  import { EventEmitter2 } from "@nestjs/event-emitter";
1110
1169
  function _ts_decorate7(decorators, target, key, desc) {
@@ -1121,18 +1180,18 @@ function _ts_decorate7(decorators, target, key, desc) {
1121
1180
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1122
1181
  }
1123
1182
  __name(_ts_decorate7, "_ts_decorate");
1124
- function _ts_metadata4(metadataKey, metadataValue) {
1183
+ function _ts_metadata5(metadataKey, metadataValue) {
1125
1184
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1126
1185
  return Reflect.metadata(metadataKey, metadataValue);
1127
1186
  }
1128
1187
  }
1129
- __name(_ts_metadata4, "_ts_metadata");
1130
- function _ts_param3(paramIndex, decorator) {
1188
+ __name(_ts_metadata5, "_ts_metadata");
1189
+ function _ts_param4(paramIndex, decorator) {
1131
1190
  return function(target, key) {
1132
1191
  decorator(target, key, paramIndex);
1133
1192
  };
1134
1193
  }
1135
- __name(_ts_param3, "_ts_param");
1194
+ __name(_ts_param4, "_ts_param");
1136
1195
  function nextAlertId() {
1137
1196
  return `alert-${Date.now()}-${randomUUID().slice(0, 8)}`;
1138
1197
  }
@@ -1353,11 +1412,11 @@ var AlertManagerService = class _AlertManagerService {
1353
1412
  };
1354
1413
  AlertManagerService = _ts_decorate7([
1355
1414
  Injectable5(),
1356
- _ts_param3(0, Optional()),
1357
- _ts_param3(1, Optional()),
1358
- _ts_param3(1, Inject2("DATABASE_ADAPTER")),
1359
- _ts_metadata4("design:type", Function),
1360
- _ts_metadata4("design:paramtypes", [
1415
+ _ts_param4(0, Optional2()),
1416
+ _ts_param4(1, Optional2()),
1417
+ _ts_param4(1, Inject3("DATABASE_ADAPTER")),
1418
+ _ts_metadata5("design:type", Function),
1419
+ _ts_metadata5("design:paramtypes", [
1361
1420
  typeof EventEmitter2 === "undefined" ? Object : EventEmitter2,
1362
1421
  Object
1363
1422
  ])
@@ -1379,18 +1438,18 @@ function _ts_decorate8(decorators, target, key, desc) {
1379
1438
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1380
1439
  }
1381
1440
  __name(_ts_decorate8, "_ts_decorate");
1382
- function _ts_metadata5(metadataKey, metadataValue) {
1441
+ function _ts_metadata6(metadataKey, metadataValue) {
1383
1442
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1384
1443
  return Reflect.metadata(metadataKey, metadataValue);
1385
1444
  }
1386
1445
  }
1387
- __name(_ts_metadata5, "_ts_metadata");
1388
- function _ts_param4(paramIndex, decorator) {
1446
+ __name(_ts_metadata6, "_ts_metadata");
1447
+ function _ts_param5(paramIndex, decorator) {
1389
1448
  return function(target, key) {
1390
1449
  decorator(target, key, paramIndex);
1391
1450
  };
1392
1451
  }
1393
- __name(_ts_param4, "_ts_param");
1452
+ __name(_ts_param5, "_ts_param");
1394
1453
  var Permissions = /* @__PURE__ */ __name(() => SetMetadata2("zucker:auth:permissions", []), "Permissions");
1395
1454
  var AlertController = class {
1396
1455
  static {
@@ -1456,63 +1515,63 @@ var AlertController = class {
1456
1515
  };
1457
1516
  _ts_decorate8([
1458
1517
  Get3(),
1459
- _ts_metadata5("design:type", Function),
1460
- _ts_metadata5("design:paramtypes", []),
1461
- _ts_metadata5("design:returntype", void 0)
1518
+ _ts_metadata6("design:type", Function),
1519
+ _ts_metadata6("design:paramtypes", []),
1520
+ _ts_metadata6("design:returntype", void 0)
1462
1521
  ], AlertController.prototype, "getAlerts", null);
1463
1522
  _ts_decorate8([
1464
1523
  Get3("rules"),
1465
- _ts_metadata5("design:type", Function),
1466
- _ts_metadata5("design:paramtypes", []),
1467
- _ts_metadata5("design:returntype", void 0)
1524
+ _ts_metadata6("design:type", Function),
1525
+ _ts_metadata6("design:paramtypes", []),
1526
+ _ts_metadata6("design:returntype", void 0)
1468
1527
  ], AlertController.prototype, "getRules", null);
1469
1528
  _ts_decorate8([
1470
1529
  Post("rules"),
1471
1530
  HttpCode(HttpStatus.CREATED),
1472
- _ts_param4(0, Body()),
1473
- _ts_metadata5("design:type", Function),
1474
- _ts_metadata5("design:paramtypes", [
1531
+ _ts_param5(0, Body()),
1532
+ _ts_metadata6("design:type", Function),
1533
+ _ts_metadata6("design:paramtypes", [
1475
1534
  typeof AlertRule === "undefined" ? Object : AlertRule
1476
1535
  ]),
1477
- _ts_metadata5("design:returntype", void 0)
1536
+ _ts_metadata6("design:returntype", void 0)
1478
1537
  ], AlertController.prototype, "createRule", null);
1479
1538
  _ts_decorate8([
1480
1539
  Delete("rules/:id"),
1481
1540
  HttpCode(HttpStatus.NO_CONTENT),
1482
- _ts_param4(0, Param("id")),
1483
- _ts_metadata5("design:type", Function),
1484
- _ts_metadata5("design:paramtypes", [
1541
+ _ts_param5(0, Param("id")),
1542
+ _ts_metadata6("design:type", Function),
1543
+ _ts_metadata6("design:paramtypes", [
1485
1544
  String
1486
1545
  ]),
1487
- _ts_metadata5("design:returntype", void 0)
1546
+ _ts_metadata6("design:returntype", void 0)
1488
1547
  ], AlertController.prototype, "deleteRule", null);
1489
1548
  _ts_decorate8([
1490
1549
  Put(":id/acknowledge"),
1491
- _ts_param4(0, Param("id")),
1492
- _ts_param4(1, Body("userId")),
1493
- _ts_metadata5("design:type", Function),
1494
- _ts_metadata5("design:paramtypes", [
1550
+ _ts_param5(0, Param("id")),
1551
+ _ts_param5(1, Body("userId")),
1552
+ _ts_metadata6("design:type", Function),
1553
+ _ts_metadata6("design:paramtypes", [
1495
1554
  String,
1496
1555
  String
1497
1556
  ]),
1498
- _ts_metadata5("design:returntype", void 0)
1557
+ _ts_metadata6("design:returntype", void 0)
1499
1558
  ], AlertController.prototype, "acknowledgeAlert", null);
1500
1559
  _ts_decorate8([
1501
1560
  Put(":id/resolve"),
1502
- _ts_param4(0, Param("id")),
1503
- _ts_param4(1, Body("userId")),
1504
- _ts_metadata5("design:type", Function),
1505
- _ts_metadata5("design:paramtypes", [
1561
+ _ts_param5(0, Param("id")),
1562
+ _ts_param5(1, Body("userId")),
1563
+ _ts_metadata6("design:type", Function),
1564
+ _ts_metadata6("design:paramtypes", [
1506
1565
  String,
1507
1566
  String
1508
1567
  ]),
1509
- _ts_metadata5("design:returntype", void 0)
1568
+ _ts_metadata6("design:returntype", void 0)
1510
1569
  ], AlertController.prototype, "resolveAlert", null);
1511
1570
  AlertController = _ts_decorate8([
1512
1571
  Controller3("monitoring/alerts"),
1513
1572
  Permissions(),
1514
- _ts_metadata5("design:type", Function),
1515
- _ts_metadata5("design:paramtypes", [
1573
+ _ts_metadata6("design:type", Function),
1574
+ _ts_metadata6("design:paramtypes", [
1516
1575
  typeof AlertManagerService === "undefined" ? Object : AlertManagerService
1517
1576
  ])
1518
1577
  ], AlertController);
@@ -1662,11 +1721,93 @@ var UsageTracker = class _UsageTracker {
1662
1721
  UsageTracker = _ts_decorate10([
1663
1722
  Injectable6()
1664
1723
  ], UsageTracker);
1724
+
1725
+ // src/sentry-error-reporter.ts
1726
+ import { redactFields } from "@zucker-framework/core/privacy";
1727
+ var SentryErrorReporter = class {
1728
+ static {
1729
+ __name(this, "SentryErrorReporter");
1730
+ }
1731
+ options;
1732
+ sdk;
1733
+ initializing;
1734
+ constructor(options) {
1735
+ this.options = options;
1736
+ }
1737
+ onModuleInit() {
1738
+ return this.initializing ??= this.initialize();
1739
+ }
1740
+ async initialize() {
1741
+ if (!this.options.dsn) {
1742
+ this.options.onUnavailable?.();
1743
+ return;
1744
+ }
1745
+ const sdk = await (this.options.loadSdk?.() ?? import("@sentry/node").then((module) => module));
1746
+ sdk.init({
1747
+ dsn: this.options.dsn,
1748
+ environment: this.options.environment,
1749
+ release: this.options.release,
1750
+ tracesSampleRate: this.options.tracesSampleRate,
1751
+ beforeSend: /* @__PURE__ */ __name((event) => {
1752
+ const redaction = this.options.redaction;
1753
+ let safe = event;
1754
+ if (redaction) {
1755
+ safe = {
1756
+ ...event
1757
+ };
1758
+ for (const section of redaction.sections) {
1759
+ const value = event[section];
1760
+ if (value !== null && typeof value === "object") {
1761
+ safe[section] = redactFields(value, redaction.fields, redaction.replacement);
1762
+ }
1763
+ }
1764
+ }
1765
+ return this.options.beforeSend ? this.options.beforeSend(safe) : safe;
1766
+ }, "beforeSend")
1767
+ });
1768
+ this.sdk = sdk;
1769
+ this.options.onInitialized?.();
1770
+ }
1771
+ captureException(error, context) {
1772
+ const sdk = this.sdk;
1773
+ if (!sdk) return;
1774
+ sdk.withScope((scope) => {
1775
+ this.applyContext(scope, context, "exception");
1776
+ sdk.captureException(error);
1777
+ });
1778
+ }
1779
+ captureMessage(message, context) {
1780
+ const sdk = this.sdk;
1781
+ if (!sdk) return;
1782
+ sdk.withScope((scope) => {
1783
+ this.applyContext(scope, context, "message");
1784
+ sdk.captureMessage(message);
1785
+ });
1786
+ }
1787
+ setUser(user) {
1788
+ this.sdk?.setUser(user);
1789
+ }
1790
+ applyContext(scope, context, kind) {
1791
+ if (!context) return;
1792
+ const mapped = this.options.mapContext?.(context, kind) ?? {
1793
+ tags: context.requestId ? {
1794
+ requestId: context.requestId
1795
+ } : void 0,
1796
+ user: context.userId ? {
1797
+ id: context.userId
1798
+ } : void 0
1799
+ };
1800
+ for (const [key, value] of Object.entries(mapped.tags ?? {})) scope.setTag(key, value);
1801
+ if (mapped.user !== void 0) scope.setUser(mapped.user);
1802
+ for (const [key, value] of Object.entries(mapped.extra ?? {})) scope.setExtra(key, value);
1803
+ }
1804
+ };
1665
1805
  export {
1666
1806
  AlertController,
1667
1807
  AlertManagerService,
1668
1808
  Counter,
1669
1809
  ERROR_REPORTER,
1810
+ ERROR_TRACKER_OPTIONS,
1670
1811
  ErrorTracker,
1671
1812
  Gauge,
1672
1813
  HEALTH_OPTIONS,
@@ -1680,11 +1821,13 @@ export {
1680
1821
  MetricsRegistry,
1681
1822
  NoopErrorReporter,
1682
1823
  PrometheusExporter,
1824
+ SentryErrorReporter,
1683
1825
  Summary,
1684
1826
  SystemMetricsCollector,
1685
1827
  Timer,
1686
1828
  UsageTracker,
1687
1829
  ZuckerMonitoringModule,
1830
+ errorFingerprint,
1688
1831
  getProcessUptime,
1689
1832
  renderPrometheusMetrics
1690
1833
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zucker-framework/monitoring",
3
- "version": "1.0.0",
3
+ "version": "1.0.5",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -12,12 +12,14 @@
12
12
  ],
13
13
  "devDependencies": {
14
14
  "@nestjs/event-emitter": "^12.0.0",
15
- "@types/node": "^20.19.43"
15
+ "@types/node": "^20.19.43",
16
+ "@sentry/node": "^10.73.0"
16
17
  },
17
18
  "peerDependencies": {
18
19
  "@nestjs/common": "^12.0.0",
19
20
  "@nestjs/core": "^12.0.0",
20
- "@nestjs/event-emitter": "^12.0.0"
21
+ "@nestjs/event-emitter": "^12.0.0",
22
+ "@sentry/node": "^10.73.0"
21
23
  },
22
24
  "license": "Apache-2.0",
23
25
  "author": "Lind",
@@ -30,8 +32,16 @@
30
32
  "access": "public",
31
33
  "registry": "https://registry.npmjs.org/"
32
34
  },
35
+ "dependencies": {
36
+ "@zucker-framework/core": "1.0.5"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "@sentry/node": {
40
+ "optional": true
41
+ }
42
+ },
33
43
  "scripts": {
34
- "build": "tsup src/index.ts --format cjs,esm --dts",
44
+ "build": "tsup src/index.ts --format cjs,esm --dts --external @sentry/node --external @zucker-framework/core",
35
45
  "clean": "rm -rf dist",
36
46
  "lint": "eslint src/"
37
47
  }