@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/README.md +11 -0
- package/dist/index.d.mts +75 -3
- package/dist/index.d.ts +75 -3
- package/dist/index.js +229 -83
- package/dist/index.mjs +229 -86
- package/package.json +14 -4
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Monitoring
|
|
2
|
+
|
|
3
|
+
## Bounded error aggregation
|
|
4
|
+
|
|
5
|
+
Configure `ErrorTracker` with `retentionMs` for a fixed window starting at first occurrence, optional fingerprint/redaction functions, `logEntries: false` for silent aggregation, and `onNewError` for host alert policy. Expiry is applied on reads and writes; no recurring timer or lifecycle provider is needed. `errorFingerprint` hashes the error name/message/first stack location and endpoint. Default consumers retain the original category/message aggregation and unlimited retention. External reporting remains behind `ErrorReporter`; product classifications, critical keywords and tracking enablement stay in the host.
|
|
6
|
+
|
|
7
|
+
## Optional Sentry adapter and selected health probes
|
|
8
|
+
|
|
9
|
+
`SentryErrorReporter` receives explicit SDK initialization options, selected redaction fields/sections and a context mapper. It loads `@sentry/node` only when configured and initializes once. The application owns its enablement decision, DSN, sampling, tags and sensitive field list. `ERROR_REPORTER` can still use `NoopErrorReporter`.
|
|
10
|
+
|
|
11
|
+
`HealthCheckService.checkAll(names?)` reuses the existing status aggregation for readiness or diagnostics subsets. A requested but unregistered probe is DOWN. HTTP paths, status field naming and business metric queries stay with the application. `MetricsRegistry` plus `renderPrometheusMetrics` provide serialization without a second text renderer.
|
package/dist/index.d.mts
CHANGED
|
@@ -11,10 +11,25 @@ interface TrackedError {
|
|
|
11
11
|
lastOccurrence: Date;
|
|
12
12
|
metadata?: Record<string, unknown>;
|
|
13
13
|
}
|
|
14
|
+
interface ErrorTrackerOptions {
|
|
15
|
+
/** Fixed aggregation window from the first occurrence; omitted retains existing unbounded history. */
|
|
16
|
+
retentionMs?: number;
|
|
17
|
+
logEntries?: boolean;
|
|
18
|
+
fingerprint?: (error: Error, category: string, metadata?: Record<string, unknown>) => string;
|
|
19
|
+
sanitizeText?: (value: string) => string;
|
|
20
|
+
sanitizeMetadata?: (value: Record<string, unknown>) => Record<string, unknown>;
|
|
21
|
+
onNewError?: (error: Error, record: TrackedError) => void;
|
|
22
|
+
}
|
|
23
|
+
declare const ERROR_TRACKER_OPTIONS: unique symbol;
|
|
24
|
+
/** Fingerprint without retaining raw stack locations or request paths as cache keys. */
|
|
25
|
+
declare function errorFingerprint(error: Error, endpoint?: string): string;
|
|
14
26
|
declare class ErrorTracker {
|
|
27
|
+
private readonly options;
|
|
15
28
|
private readonly logger;
|
|
16
29
|
private errors;
|
|
17
30
|
private counter;
|
|
31
|
+
constructor(options?: ErrorTrackerOptions);
|
|
32
|
+
private prune;
|
|
18
33
|
track(error: Error, category?: string, metadata?: Record<string, unknown>): void;
|
|
19
34
|
getErrors(): TrackedError[];
|
|
20
35
|
getErrorsByCategory(category: string): TrackedError[];
|
|
@@ -46,7 +61,7 @@ declare const ERROR_REPORTER: unique symbol;
|
|
|
46
61
|
* Provider-neutral error reporting port.
|
|
47
62
|
*
|
|
48
63
|
* Sentry, Datadog, Rollbar, or an internal collector belongs behind this port;
|
|
49
|
-
*
|
|
64
|
+
* provider adapters may load an explicitly configured optional vendor SDK.
|
|
50
65
|
*/
|
|
51
66
|
interface ErrorReporter {
|
|
52
67
|
captureException(error: unknown, context?: ErrorContext): void;
|
|
@@ -80,7 +95,8 @@ declare class HealthCheckService {
|
|
|
80
95
|
private indicators;
|
|
81
96
|
registerIndicator(indicator: HealthIndicator): void;
|
|
82
97
|
unregisterIndicator(name: string): void;
|
|
83
|
-
|
|
98
|
+
/** Select a declared subset for readiness vs. diagnostics; absent indicators fail closed. */
|
|
99
|
+
checkAll(names?: readonly string[]): Promise<{
|
|
84
100
|
status: HealthStatus;
|
|
85
101
|
checks: HealthCheck[];
|
|
86
102
|
timestamp: Date;
|
|
@@ -499,4 +515,60 @@ declare class UsageTracker {
|
|
|
499
515
|
getSummary(): UsageSummary | undefined;
|
|
500
516
|
}
|
|
501
517
|
|
|
502
|
-
|
|
518
|
+
type SentryEvent = Record<string, unknown>;
|
|
519
|
+
interface SentryScopeContext {
|
|
520
|
+
tags?: Record<string, string>;
|
|
521
|
+
user?: ErrorReporterUser | null;
|
|
522
|
+
extra?: Record<string, unknown>;
|
|
523
|
+
}
|
|
524
|
+
interface SentryScopePort {
|
|
525
|
+
setTag(key: string, value: string): unknown;
|
|
526
|
+
setUser(user: ErrorReporterUser | null): unknown;
|
|
527
|
+
setExtra(key: string, value: unknown): unknown;
|
|
528
|
+
}
|
|
529
|
+
/** The adapter only relies on this subset of the optional Node SDK. */
|
|
530
|
+
interface SentrySdkPort {
|
|
531
|
+
init(options: {
|
|
532
|
+
dsn: string;
|
|
533
|
+
environment?: string;
|
|
534
|
+
release?: string;
|
|
535
|
+
tracesSampleRate?: number;
|
|
536
|
+
beforeSend(event: SentryEvent): SentryEvent | null;
|
|
537
|
+
}): unknown;
|
|
538
|
+
withScope(callback: (scope: SentryScopePort) => void): unknown;
|
|
539
|
+
captureException(error: unknown): unknown;
|
|
540
|
+
captureMessage(message: string): unknown;
|
|
541
|
+
setUser(user: ErrorReporterUser | null): unknown;
|
|
542
|
+
}
|
|
543
|
+
interface SentryErrorReporterOptions {
|
|
544
|
+
dsn?: string;
|
|
545
|
+
environment?: string;
|
|
546
|
+
release?: string;
|
|
547
|
+
tracesSampleRate?: number;
|
|
548
|
+
/** Application field/section selection; traversal never changes the source event. */
|
|
549
|
+
redaction?: {
|
|
550
|
+
fields: readonly string[];
|
|
551
|
+
sections: readonly string[];
|
|
552
|
+
replacement?: string;
|
|
553
|
+
};
|
|
554
|
+
beforeSend?: (event: SentryEvent) => SentryEvent | null;
|
|
555
|
+
mapContext?: (context: ErrorContext, kind: 'exception' | 'message') => SentryScopeContext;
|
|
556
|
+
loadSdk?: () => Promise<SentrySdkPort>;
|
|
557
|
+
onUnavailable?: () => void;
|
|
558
|
+
onInitialized?: () => void;
|
|
559
|
+
}
|
|
560
|
+
/** Configured once by the application. Importing monitoring does not load Sentry. */
|
|
561
|
+
declare class SentryErrorReporter implements ErrorReporter {
|
|
562
|
+
private readonly options;
|
|
563
|
+
private sdk?;
|
|
564
|
+
private initializing?;
|
|
565
|
+
constructor(options: SentryErrorReporterOptions);
|
|
566
|
+
onModuleInit(): Promise<void>;
|
|
567
|
+
private initialize;
|
|
568
|
+
captureException(error: unknown, context?: ErrorContext): void;
|
|
569
|
+
captureMessage(message: string, context?: ErrorContext): void;
|
|
570
|
+
setUser(user: ErrorReporterUser | null): void;
|
|
571
|
+
private applyContext;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
export { AlertController, AlertManagerService, type AlertRecord, type AlertRule, type AlertSeverity, type AlertStatus, Counter, ERROR_REPORTER, ERROR_TRACKER_OPTIONS, type ErrorContext, type ErrorReporter, type ErrorReporterUser, ErrorTracker, type ErrorTrackerOptions, Gauge, HEALTH_OPTIONS, type HealthCheck, HealthCheckService, HealthController, type HealthIndicator, type HealthOptions, HealthStatus, Histogram, InMemoryMetricsCollector, METRICS_COLLECTOR, type MeasurementDefinition, type MeasurementProvider, type MetricLabels, type MetricPoint, Metrics, type MetricsCollector, type MetricsOptions, MetricsRegistry, NoopErrorReporter, type ProcessUptimeSnapshot, PrometheusExporter, SentryErrorReporter, type SentryErrorReporterOptions, type SentryEvent, type SentryScopeContext, type SentryScopePort, type SentrySdkPort, Summary, SystemMetricsCollector, type SystemMetricsOptions, Timer, type TrackedError, type UsageMetrics, type UsageSummary, UsageTracker, ZuckerMonitoringModule, errorFingerprint, getProcessUptime, renderPrometheusMetrics };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,10 +11,25 @@ interface TrackedError {
|
|
|
11
11
|
lastOccurrence: Date;
|
|
12
12
|
metadata?: Record<string, unknown>;
|
|
13
13
|
}
|
|
14
|
+
interface ErrorTrackerOptions {
|
|
15
|
+
/** Fixed aggregation window from the first occurrence; omitted retains existing unbounded history. */
|
|
16
|
+
retentionMs?: number;
|
|
17
|
+
logEntries?: boolean;
|
|
18
|
+
fingerprint?: (error: Error, category: string, metadata?: Record<string, unknown>) => string;
|
|
19
|
+
sanitizeText?: (value: string) => string;
|
|
20
|
+
sanitizeMetadata?: (value: Record<string, unknown>) => Record<string, unknown>;
|
|
21
|
+
onNewError?: (error: Error, record: TrackedError) => void;
|
|
22
|
+
}
|
|
23
|
+
declare const ERROR_TRACKER_OPTIONS: unique symbol;
|
|
24
|
+
/** Fingerprint without retaining raw stack locations or request paths as cache keys. */
|
|
25
|
+
declare function errorFingerprint(error: Error, endpoint?: string): string;
|
|
14
26
|
declare class ErrorTracker {
|
|
27
|
+
private readonly options;
|
|
15
28
|
private readonly logger;
|
|
16
29
|
private errors;
|
|
17
30
|
private counter;
|
|
31
|
+
constructor(options?: ErrorTrackerOptions);
|
|
32
|
+
private prune;
|
|
18
33
|
track(error: Error, category?: string, metadata?: Record<string, unknown>): void;
|
|
19
34
|
getErrors(): TrackedError[];
|
|
20
35
|
getErrorsByCategory(category: string): TrackedError[];
|
|
@@ -46,7 +61,7 @@ declare const ERROR_REPORTER: unique symbol;
|
|
|
46
61
|
* Provider-neutral error reporting port.
|
|
47
62
|
*
|
|
48
63
|
* Sentry, Datadog, Rollbar, or an internal collector belongs behind this port;
|
|
49
|
-
*
|
|
64
|
+
* provider adapters may load an explicitly configured optional vendor SDK.
|
|
50
65
|
*/
|
|
51
66
|
interface ErrorReporter {
|
|
52
67
|
captureException(error: unknown, context?: ErrorContext): void;
|
|
@@ -80,7 +95,8 @@ declare class HealthCheckService {
|
|
|
80
95
|
private indicators;
|
|
81
96
|
registerIndicator(indicator: HealthIndicator): void;
|
|
82
97
|
unregisterIndicator(name: string): void;
|
|
83
|
-
|
|
98
|
+
/** Select a declared subset for readiness vs. diagnostics; absent indicators fail closed. */
|
|
99
|
+
checkAll(names?: readonly string[]): Promise<{
|
|
84
100
|
status: HealthStatus;
|
|
85
101
|
checks: HealthCheck[];
|
|
86
102
|
timestamp: Date;
|
|
@@ -499,4 +515,60 @@ declare class UsageTracker {
|
|
|
499
515
|
getSummary(): UsageSummary | undefined;
|
|
500
516
|
}
|
|
501
517
|
|
|
502
|
-
|
|
518
|
+
type SentryEvent = Record<string, unknown>;
|
|
519
|
+
interface SentryScopeContext {
|
|
520
|
+
tags?: Record<string, string>;
|
|
521
|
+
user?: ErrorReporterUser | null;
|
|
522
|
+
extra?: Record<string, unknown>;
|
|
523
|
+
}
|
|
524
|
+
interface SentryScopePort {
|
|
525
|
+
setTag(key: string, value: string): unknown;
|
|
526
|
+
setUser(user: ErrorReporterUser | null): unknown;
|
|
527
|
+
setExtra(key: string, value: unknown): unknown;
|
|
528
|
+
}
|
|
529
|
+
/** The adapter only relies on this subset of the optional Node SDK. */
|
|
530
|
+
interface SentrySdkPort {
|
|
531
|
+
init(options: {
|
|
532
|
+
dsn: string;
|
|
533
|
+
environment?: string;
|
|
534
|
+
release?: string;
|
|
535
|
+
tracesSampleRate?: number;
|
|
536
|
+
beforeSend(event: SentryEvent): SentryEvent | null;
|
|
537
|
+
}): unknown;
|
|
538
|
+
withScope(callback: (scope: SentryScopePort) => void): unknown;
|
|
539
|
+
captureException(error: unknown): unknown;
|
|
540
|
+
captureMessage(message: string): unknown;
|
|
541
|
+
setUser(user: ErrorReporterUser | null): unknown;
|
|
542
|
+
}
|
|
543
|
+
interface SentryErrorReporterOptions {
|
|
544
|
+
dsn?: string;
|
|
545
|
+
environment?: string;
|
|
546
|
+
release?: string;
|
|
547
|
+
tracesSampleRate?: number;
|
|
548
|
+
/** Application field/section selection; traversal never changes the source event. */
|
|
549
|
+
redaction?: {
|
|
550
|
+
fields: readonly string[];
|
|
551
|
+
sections: readonly string[];
|
|
552
|
+
replacement?: string;
|
|
553
|
+
};
|
|
554
|
+
beforeSend?: (event: SentryEvent) => SentryEvent | null;
|
|
555
|
+
mapContext?: (context: ErrorContext, kind: 'exception' | 'message') => SentryScopeContext;
|
|
556
|
+
loadSdk?: () => Promise<SentrySdkPort>;
|
|
557
|
+
onUnavailable?: () => void;
|
|
558
|
+
onInitialized?: () => void;
|
|
559
|
+
}
|
|
560
|
+
/** Configured once by the application. Importing monitoring does not load Sentry. */
|
|
561
|
+
declare class SentryErrorReporter implements ErrorReporter {
|
|
562
|
+
private readonly options;
|
|
563
|
+
private sdk?;
|
|
564
|
+
private initializing?;
|
|
565
|
+
constructor(options: SentryErrorReporterOptions);
|
|
566
|
+
onModuleInit(): Promise<void>;
|
|
567
|
+
private initialize;
|
|
568
|
+
captureException(error: unknown, context?: ErrorContext): void;
|
|
569
|
+
captureMessage(message: string, context?: ErrorContext): void;
|
|
570
|
+
setUser(user: ErrorReporterUser | null): void;
|
|
571
|
+
private applyContext;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
export { AlertController, AlertManagerService, type AlertRecord, type AlertRule, type AlertSeverity, type AlertStatus, Counter, ERROR_REPORTER, ERROR_TRACKER_OPTIONS, type ErrorContext, type ErrorReporter, type ErrorReporterUser, ErrorTracker, type ErrorTrackerOptions, Gauge, HEALTH_OPTIONS, type HealthCheck, HealthCheckService, HealthController, type HealthIndicator, type HealthOptions, HealthStatus, Histogram, InMemoryMetricsCollector, METRICS_COLLECTOR, type MeasurementDefinition, type MeasurementProvider, type MetricLabels, type MetricPoint, Metrics, type MetricsCollector, type MetricsOptions, MetricsRegistry, NoopErrorReporter, type ProcessUptimeSnapshot, PrometheusExporter, SentryErrorReporter, type SentryErrorReporterOptions, type SentryEvent, type SentryScopeContext, type SentryScopePort, type SentrySdkPort, Summary, SystemMetricsCollector, type SystemMetricsOptions, Timer, type TrackedError, type UsageMetrics, type UsageSummary, UsageTracker, ZuckerMonitoringModule, errorFingerprint, getProcessUptime, renderPrometheusMetrics };
|