@gravito/core 1.6.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/README.md +100 -6
  2. package/README.zh-TW.md +101 -6
  3. package/dist/Application.d.ts +256 -0
  4. package/dist/CommandKernel.d.ts +33 -0
  5. package/dist/ConfigManager.d.ts +65 -0
  6. package/dist/Container/RequestScopeManager.d.ts +62 -0
  7. package/dist/Container/RequestScopeMetrics.d.ts +144 -0
  8. package/dist/Container.d.ts +153 -0
  9. package/dist/ErrorHandler.d.ts +66 -0
  10. package/dist/Event.d.ts +5 -0
  11. package/dist/EventManager.d.ts +123 -0
  12. package/dist/GlobalErrorHandlers.d.ts +47 -0
  13. package/dist/GravitoServer.d.ts +28 -0
  14. package/dist/HookManager.d.ts +435 -0
  15. package/dist/Listener.d.ts +4 -0
  16. package/dist/Logger.d.ts +20 -0
  17. package/dist/PlanetCore.d.ts +402 -0
  18. package/dist/RequestContext.d.ts +97 -0
  19. package/dist/Route.d.ts +36 -0
  20. package/dist/Router.d.ts +270 -0
  21. package/dist/ServiceProvider.d.ts +178 -0
  22. package/dist/adapters/GravitoEngineAdapter.d.ts +27 -0
  23. package/dist/adapters/bun/AdaptiveAdapter.d.ts +99 -0
  24. package/dist/adapters/bun/BunContext.d.ts +54 -0
  25. package/dist/adapters/bun/BunNativeAdapter.d.ts +66 -0
  26. package/dist/adapters/bun/BunRequest.d.ts +31 -0
  27. package/dist/adapters/bun/BunWebSocketHandler.d.ts +48 -0
  28. package/dist/adapters/bun/RadixNode.d.ts +19 -0
  29. package/dist/adapters/bun/RadixRouter.d.ts +32 -0
  30. package/dist/adapters/bun/index.d.ts +7 -0
  31. package/dist/adapters/bun/types.d.ts +20 -0
  32. package/dist/adapters/index.d.ts +12 -0
  33. package/dist/adapters/types.d.ts +235 -0
  34. package/dist/binary/BinaryUtils.d.ts +105 -0
  35. package/dist/binary/index.d.ts +5 -0
  36. package/dist/cli/queue-commands.d.ts +6 -0
  37. package/dist/compat/async-local-storage.browser.d.ts +9 -0
  38. package/dist/compat/async-local-storage.d.ts +7 -0
  39. package/dist/compat/crypto.browser.d.ts +5 -0
  40. package/dist/compat/crypto.d.ts +6 -0
  41. package/dist/compat.d.ts +23 -1
  42. package/dist/compat.js +3 -0
  43. package/dist/compat.js.map +9 -0
  44. package/dist/engine/AOTRouter.d.ts +139 -0
  45. package/dist/engine/FastContext.d.ts +141 -0
  46. package/dist/engine/Gravito.d.ts +131 -0
  47. package/dist/engine/MinimalContext.d.ts +102 -0
  48. package/dist/engine/analyzer.d.ts +113 -0
  49. package/dist/engine/constants.d.ts +23 -0
  50. package/dist/engine/index.d.ts +14 -910
  51. package/dist/engine/index.js +623 -622
  52. package/dist/engine/index.js.map +23 -0
  53. package/dist/engine/path.d.ts +26 -0
  54. package/dist/engine/pool.d.ts +83 -0
  55. package/dist/engine/types.d.ts +149 -0
  56. package/dist/error-handling/RequestScopeErrorContext.d.ts +126 -0
  57. package/dist/events/BackpressureManager.d.ts +215 -0
  58. package/dist/events/CircuitBreaker.d.ts +229 -0
  59. package/dist/events/DeadLetterQueue.d.ts +219 -0
  60. package/dist/events/EventBackend.d.ts +12 -0
  61. package/dist/events/EventOptions.d.ts +204 -0
  62. package/dist/events/EventPriorityQueue.d.ts +63 -0
  63. package/dist/events/FlowControlStrategy.d.ts +109 -0
  64. package/dist/events/IdempotencyCache.d.ts +60 -0
  65. package/dist/events/MessageQueueBridge.d.ts +184 -0
  66. package/dist/events/PriorityEscalationManager.d.ts +82 -0
  67. package/dist/events/RetryScheduler.d.ts +104 -0
  68. package/dist/events/WorkerPool.d.ts +98 -0
  69. package/dist/events/WorkerPoolConfig.d.ts +153 -0
  70. package/dist/events/WorkerPoolMetrics.d.ts +65 -0
  71. package/dist/events/aggregation/AggregationWindow.d.ts +77 -0
  72. package/dist/events/aggregation/DeduplicationManager.d.ts +135 -0
  73. package/dist/events/aggregation/EventAggregationManager.d.ts +108 -0
  74. package/dist/events/aggregation/EventBatcher.d.ts +99 -0
  75. package/dist/events/aggregation/index.d.ts +10 -0
  76. package/dist/events/aggregation/types.d.ts +117 -0
  77. package/dist/events/index.d.ts +26 -0
  78. package/dist/events/observability/EventMetrics.d.ts +132 -0
  79. package/dist/events/observability/EventTracer.d.ts +68 -0
  80. package/dist/events/observability/EventTracing.d.ts +161 -0
  81. package/dist/events/observability/OTelEventMetrics.d.ts +332 -0
  82. package/dist/events/observability/ObservableHookManager.d.ts +108 -0
  83. package/dist/events/observability/StreamWorkerMetrics.d.ts +76 -0
  84. package/dist/events/observability/index.d.ts +24 -0
  85. package/dist/events/observability/metrics-types.d.ts +16 -0
  86. package/dist/events/queue-core.d.ts +77 -0
  87. package/dist/events/task-executor.d.ts +51 -0
  88. package/dist/events/types.d.ts +134 -0
  89. package/dist/exceptions/AuthenticationException.d.ts +8 -0
  90. package/dist/exceptions/AuthorizationException.d.ts +8 -0
  91. package/dist/exceptions/CircularDependencyException.d.ts +9 -0
  92. package/dist/exceptions/GravitoException.d.ts +23 -0
  93. package/dist/exceptions/HttpException.d.ts +9 -0
  94. package/dist/exceptions/ModelNotFoundException.d.ts +10 -0
  95. package/dist/exceptions/ValidationException.d.ts +22 -0
  96. package/dist/exceptions/index.d.ts +7 -0
  97. package/dist/ffi/NativeAccelerator.d.ts +69 -0
  98. package/dist/ffi/NativeHasher.d.ts +139 -0
  99. package/dist/ffi/cbor-fallback.d.ts +96 -0
  100. package/dist/ffi/hash-fallback.d.ts +33 -0
  101. package/dist/ffi/index.d.ts +10 -0
  102. package/dist/ffi/index.js +131 -0
  103. package/dist/ffi/index.js.map +11 -0
  104. package/dist/ffi/types.d.ts +135 -0
  105. package/dist/health/HealthProvider.d.ts +67 -0
  106. package/dist/helpers/Arr.d.ts +19 -0
  107. package/dist/helpers/Str.d.ts +38 -0
  108. package/dist/helpers/data.d.ts +25 -0
  109. package/dist/helpers/errors.d.ts +34 -0
  110. package/dist/helpers/response.d.ts +41 -0
  111. package/dist/helpers.d.ts +338 -0
  112. package/dist/hooks/ActionManager.d.ts +132 -0
  113. package/dist/hooks/AsyncDetector.d.ts +84 -0
  114. package/dist/hooks/FilterManager.d.ts +71 -0
  115. package/dist/hooks/MigrationWarner.d.ts +24 -0
  116. package/dist/hooks/dlq-operations.d.ts +60 -0
  117. package/dist/hooks/index.d.ts +11 -0
  118. package/dist/hooks/types.d.ts +107 -0
  119. package/dist/http/CookieJar.d.ts +51 -0
  120. package/dist/http/cookie.d.ts +29 -0
  121. package/dist/http/index.d.ts +12 -0
  122. package/dist/{compat-CI8hiulX.d.cts → http/types.d.ts} +35 -16
  123. package/dist/index.browser.d.ts +34 -0
  124. package/dist/index.d.ts +60 -10981
  125. package/dist/index.js +10808 -11273
  126. package/dist/index.js.map +166 -0
  127. package/dist/observability/QueueDashboard.d.ts +136 -0
  128. package/dist/observability/contracts.d.ts +137 -0
  129. package/dist/observability/index.d.ts +13 -0
  130. package/dist/reliability/DeadLetterQueueManager.d.ts +349 -0
  131. package/dist/reliability/RetryPolicy.d.ts +217 -0
  132. package/dist/reliability/index.d.ts +6 -0
  133. package/dist/router/ControllerDispatcher.d.ts +12 -0
  134. package/dist/router/RequestValidator.d.ts +20 -0
  135. package/dist/runtime/adapter-bun.d.ts +12 -0
  136. package/dist/runtime/adapter-deno.d.ts +12 -0
  137. package/dist/runtime/adapter-node.d.ts +12 -0
  138. package/dist/runtime/adapter-unknown.d.ts +13 -0
  139. package/dist/runtime/archive.d.ts +17 -0
  140. package/dist/runtime/compression.d.ts +21 -0
  141. package/dist/runtime/deep-equals.d.ts +56 -0
  142. package/dist/runtime/detection.d.ts +22 -0
  143. package/dist/runtime/escape.d.ts +34 -0
  144. package/dist/runtime/index.browser.d.ts +20 -0
  145. package/dist/runtime/index.d.ts +44 -0
  146. package/dist/runtime/markdown.d.ts +44 -0
  147. package/dist/runtime/types.d.ts +436 -0
  148. package/dist/runtime-helpers.d.ts +67 -0
  149. package/dist/runtime.d.ts +11 -0
  150. package/dist/security/Encrypter.d.ts +33 -0
  151. package/dist/security/Hasher.d.ts +29 -0
  152. package/dist/testing/HttpTester.d.ts +39 -0
  153. package/dist/testing/TestResponse.d.ts +78 -0
  154. package/dist/testing/index.d.ts +2 -0
  155. package/dist/transpiler-utils.d.ts +170 -0
  156. package/dist/types/events.d.ts +94 -0
  157. package/dist/types.d.ts +13 -0
  158. package/package.json +25 -56
  159. package/src/ffi/native/cbor.c +1148 -0
  160. package/dist/Metrics-VOWWRNNR.js +0 -219
  161. package/dist/chunk-R5U7XKVJ.js +0 -16
  162. package/dist/compat-CI8hiulX.d.ts +0 -376
  163. package/dist/compat.cjs +0 -18
  164. package/dist/compat.d.cts +0 -1
  165. package/dist/engine/index.cjs +0 -1764
  166. package/dist/engine/index.d.cts +0 -922
  167. package/dist/index.cjs +0 -14906
  168. package/dist/index.d.cts +0 -11008
@@ -0,0 +1,332 @@
1
+ /**
2
+ * @gravito/core - OpenTelemetry Event Metrics
3
+ *
4
+ * Provides event system metrics using OpenTelemetry API directly.
5
+ * This enables Prometheus export without requiring @gravito/monitor dependency.
6
+ *
7
+ * Metrics:
8
+ * - gravito_event_dispatch_duration_seconds (Histogram)
9
+ * - gravito_event_listener_duration_seconds (Histogram)
10
+ * - gravito_event_queue_depth (Observable Gauge)
11
+ *
12
+ * @packageDocumentation
13
+ */
14
+ import type { Meter } from '@opentelemetry/api';
15
+ import type { CircuitBreakerMetricsRecorder } from '../CircuitBreaker';
16
+ /**
17
+ * Queue depth callback type.
18
+ * Returns the current queue depths for each priority level.
19
+ */
20
+ export type QueueDepthCallback = () => {
21
+ critical: number;
22
+ high: number;
23
+ normal: number;
24
+ low: number;
25
+ };
26
+ /**
27
+ * Circuit breaker state callback type.
28
+ * Returns the current state of a circuit breaker.
29
+ */
30
+ export type CircuitBreakerStateCallback = () => {
31
+ eventName: string;
32
+ listenerIndex: number;
33
+ state: 0 | 1 | 2;
34
+ };
35
+ /**
36
+ * OpenTelemetry-based Event Metrics collector.
37
+ *
38
+ * Uses OpenTelemetry API directly for metrics collection, enabling
39
+ * Prometheus export through the OpenTelemetry SDK.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * import { metrics } from '@opentelemetry/api'
44
+ * import { OTelEventMetrics } from '@gravito/core'
45
+ *
46
+ * const meter = metrics.getMeter('@gravito/core', '1.0.0')
47
+ * const eventMetrics = new OTelEventMetrics(meter)
48
+ *
49
+ * // Record dispatch duration
50
+ * eventMetrics.recordDispatchDuration('order:created', 'high', 0.123)
51
+ *
52
+ * // Record listener duration
53
+ * eventMetrics.recordListenerDuration('order:created', 0, 0.456)
54
+ *
55
+ * // Set queue depth callback
56
+ * eventMetrics.setQueueDepthCallback(() => ({
57
+ * high: 10,
58
+ * normal: 50,
59
+ * low: 100
60
+ * }))
61
+ * ```
62
+ *
63
+ * @public
64
+ */
65
+ export declare class OTelEventMetrics implements CircuitBreakerMetricsRecorder {
66
+ private readonly meter;
67
+ private readonly prefix;
68
+ private readonly dispatchDurationHistogram;
69
+ private readonly listenerDurationHistogram;
70
+ private readonly queueDepthGauge;
71
+ private readonly cbStateGauge;
72
+ private readonly cbFailuresCounter;
73
+ private readonly cbSuccessesCounter;
74
+ private readonly cbTransitionsCounter;
75
+ private readonly cbOpenDurationHistogram;
76
+ private readonly backpressureRejectionsCounter;
77
+ private readonly backpressureStateGauge;
78
+ private readonly backpressureDegradationsCounter;
79
+ private backpressureStateValue;
80
+ private readonly dlqEntriesCounter;
81
+ private readonly dlqDepthGauge;
82
+ private readonly dlqRequeueCounter;
83
+ private readonly retryAttemptsCounter;
84
+ private dlqDepthCallback?;
85
+ private readonly priorityEscalationCounter;
86
+ private queueDepthCallback?;
87
+ private circuitBreakerStateCallbacks;
88
+ private recordedCircuitBreakerStates;
89
+ /**
90
+ * Bucket boundaries for dispatch duration histogram.
91
+ */
92
+ private readonly dispatchDurationBuckets;
93
+ /**
94
+ * Bucket boundaries for listener duration histogram.
95
+ */
96
+ private readonly listenerDurationBuckets;
97
+ /**
98
+ * Bucket boundaries for circuit breaker open duration histogram.
99
+ */
100
+ private readonly cbOpenDurationBuckets;
101
+ /**
102
+ * Create a new OTelEventMetrics instance.
103
+ *
104
+ * @param meter - OpenTelemetry Meter instance
105
+ * @param prefix - Metric name prefix (default: 'gravito_event_')
106
+ */
107
+ constructor(meter: Meter, prefix?: string);
108
+ /**
109
+ * Record event dispatch duration.
110
+ *
111
+ * @param eventName - Name of the event
112
+ * @param priority - Priority level (high, normal, low)
113
+ * @param durationSeconds - Duration in seconds
114
+ */
115
+ recordDispatchDuration(eventName: string, priority: string, durationSeconds: number): void;
116
+ /**
117
+ * Record listener execution duration.
118
+ *
119
+ * @param eventName - Name of the event
120
+ * @param listenerIndex - Index of the listener in the callback list
121
+ * @param durationSeconds - Duration in seconds
122
+ */
123
+ recordListenerDuration(eventName: string, listenerIndex: number, durationSeconds: number): void;
124
+ /**
125
+ * Set the callback for queue depth observable gauge.
126
+ *
127
+ * The callback will be invoked when metrics are collected,
128
+ * allowing real-time reporting of queue depths.
129
+ *
130
+ * @param callback - Function returning current queue depths
131
+ */
132
+ setQueueDepthCallback(callback: QueueDepthCallback): void;
133
+ /**
134
+ * Register a circuit breaker state callback for monitoring.
135
+ *
136
+ * @param key - Unique identifier for the circuit breaker (e.g., "order:created-0")
137
+ * @param callback - Function returning current circuit breaker state
138
+ */
139
+ registerCircuitBreakerStateCallback(key: string, callback: CircuitBreakerStateCallback): void;
140
+ /**
141
+ * Unregister a circuit breaker state callback.
142
+ *
143
+ * @param key - Unique identifier for the circuit breaker
144
+ */
145
+ unregisterCircuitBreakerStateCallback(key: string): void;
146
+ /**
147
+ * Record circuit breaker state change.
148
+ *
149
+ * @param name - Name of the circuit breaker (usually event name)
150
+ * @param state - State as number (0=CLOSED, 1=HALF_OPEN, 2=OPEN)
151
+ */
152
+ recordState(name: string, state: number): void;
153
+ /**
154
+ * Record circuit breaker state transition.
155
+ *
156
+ * @param name - Name of the circuit breaker
157
+ * @param fromState - Previous state
158
+ * @param toState - New state
159
+ */
160
+ recordTransition(name: string, fromState: string, toState: string): void;
161
+ /**
162
+ * Record circuit breaker failure.
163
+ *
164
+ * @param name - Name of the circuit breaker
165
+ */
166
+ recordFailure(name: string): void;
167
+ /**
168
+ * Record circuit breaker success.
169
+ *
170
+ * @param name - Name of the circuit breaker
171
+ */
172
+ recordSuccess(name: string): void;
173
+ /**
174
+ * Record circuit breaker open duration.
175
+ *
176
+ * @param name - Name of the circuit breaker
177
+ * @param seconds - Duration in seconds
178
+ */
179
+ recordOpenDuration(name: string, seconds: number): void;
180
+ /**
181
+ * Record circuit breaker failure.
182
+ *
183
+ * @param eventName - Name of the event
184
+ * @param listenerIndex - Index of the listener
185
+ */
186
+ recordCircuitBreakerFailure(eventName: string, listenerIndex: number): void;
187
+ /**
188
+ * Record circuit breaker success.
189
+ *
190
+ * @param eventName - Name of the event
191
+ * @param listenerIndex - Index of the listener
192
+ */
193
+ recordCircuitBreakerSuccess(eventName: string, listenerIndex: number): void;
194
+ /**
195
+ * Record circuit breaker state transition.
196
+ *
197
+ * @param eventName - Name of the event
198
+ * @param listenerIndex - Index of the listener
199
+ * @param fromState - Previous state (CLOSED, HALF_OPEN, OPEN)
200
+ * @param toState - New state (CLOSED, HALF_OPEN, OPEN)
201
+ */
202
+ recordCircuitBreakerTransition(eventName: string, listenerIndex: number, fromState: string, toState: string): void;
203
+ /**
204
+ * Record circuit breaker open duration.
205
+ *
206
+ * @param eventName - Name of the event
207
+ * @param listenerIndex - Index of the listener
208
+ * @param durationSeconds - Duration in seconds
209
+ */
210
+ recordCircuitBreakerOpenDuration(eventName: string, listenerIndex: number, durationSeconds: number): void;
211
+ /**
212
+ * Get the bucket boundaries for dispatch duration histogram.
213
+ *
214
+ * @returns Array of bucket boundaries in seconds
215
+ */
216
+ getDispatchDurationBuckets(): number[];
217
+ /**
218
+ * Get the bucket boundaries for listener duration histogram.
219
+ *
220
+ * @returns Array of bucket boundaries in seconds
221
+ */
222
+ getListenerDurationBuckets(): number[];
223
+ /**
224
+ * Get the OpenTelemetry Meter instance.
225
+ *
226
+ * @returns Meter instance
227
+ */
228
+ getMeter(): Meter;
229
+ /**
230
+ * Get the metric name prefix.
231
+ *
232
+ * @returns Metric name prefix
233
+ */
234
+ getPrefix(): string;
235
+ /**
236
+ * Get the bucket boundaries for circuit breaker open duration histogram.
237
+ *
238
+ * @returns Array of bucket boundaries in seconds
239
+ */
240
+ getCircuitBreakerOpenDurationBuckets(): number[];
241
+ /**
242
+ * Get all registered circuit breaker state callback keys.
243
+ *
244
+ * @returns Array of registered keys
245
+ */
246
+ getRegisteredCircuitBreakers(): string[];
247
+ /**
248
+ * Clear all circuit breaker state callbacks.
249
+ */
250
+ clearCircuitBreakerCallbacks(): void;
251
+ /**
252
+ * Record a backpressure rejection event.
253
+ *
254
+ * @param eventName - Event name
255
+ * @param priority - Event priority
256
+ * @param reason - Rejection reason
257
+ */
258
+ recordBackpressureRejection(eventName: string, priority: string, reason: string): void;
259
+ /**
260
+ * Record a backpressure state change event.
261
+ *
262
+ * @param state - New backpressure state (NORMAL, WARNING, CRITICAL, OVERFLOW)
263
+ */
264
+ recordBackpressureState(state: string): void;
265
+ /**
266
+ * Record a backpressure degradation event.
267
+ *
268
+ * @param eventName - Event name
269
+ * @param fromPriority - Original priority
270
+ * @param toPriority - Degraded priority
271
+ */
272
+ recordBackpressureDegradation(eventName: string, fromPriority: string, toPriority: string): void;
273
+ /**
274
+ * Record an event added to Dead Letter Queue.
275
+ *
276
+ * @param eventName - Event name
277
+ * @param source - Source of DLQ entry (retry_exhausted, circuit_breaker, backpressure_overflow)
278
+ */
279
+ recordDLQEntry(eventName: string, source: string): void;
280
+ /**
281
+ * Set the callback for DLQ depth observable gauge.
282
+ *
283
+ * @param callback - Function returning current DLQ depth
284
+ */
285
+ setDLQDepthCallback(callback: () => number): void;
286
+ /**
287
+ * Record a DLQ requeue attempt.
288
+ *
289
+ * @param eventName - Event name
290
+ * @param result - Result of requeue (success or failure)
291
+ */
292
+ recordDLQRequeue(eventName: string, result: 'success' | 'failure'): void;
293
+ /**
294
+ * Record an event retry attempt.
295
+ *
296
+ * @param eventName - Event name
297
+ * @param attemptNumber - Attempt number
298
+ */
299
+ recordRetryAttempt(eventName: string, attemptNumber: number): void;
300
+ /**
301
+ * Record a priority escalation event.
302
+ *
303
+ * @param eventName - Event name
304
+ * @param fromPriority - Original priority
305
+ * @param toPriority - Escalated priority
306
+ */
307
+ recordPriorityEscalation(eventName: string, fromPriority: string, toPriority: string): void;
308
+ /**
309
+ * Record event deduplication (FS-102).
310
+ *
311
+ * @param eventName - Event name
312
+ * @param deduplicatedCount - Number of events after deduplication
313
+ * @param totalCount - Total number of events before deduplication
314
+ */
315
+ recordDeduplication(eventName: string, deduplicatedCount: number, totalCount: number): void;
316
+ /**
317
+ * Record batch submission (FS-102).
318
+ *
319
+ * @param eventName - Event name
320
+ * @param batchSize - Size of submitted batch
321
+ * @param windowMs - Aggregation window size
322
+ */
323
+ recordBatch(eventName: string, batchSize: number, windowMs: number): void;
324
+ /**
325
+ * Record window adjustment (FS-102).
326
+ *
327
+ * @param oldWindowMs - Previous window size
328
+ * @param newWindowMs - New window size
329
+ * @param reason - Adjustment reason
330
+ */
331
+ recordWindowAdjustment(oldWindowMs: number, newWindowMs: number, reason: string): void;
332
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * @gravito/core - Observable Hook Manager
3
+ *
4
+ * Wraps HookManager with observability support (metrics and tracing).
5
+ */
6
+ import { HookManager, type HookManagerConfig } from '../../HookManager';
7
+ import type { EventOptions } from '../EventOptions';
8
+ import { EventMetrics } from './EventMetrics';
9
+ import { EventTracer } from './EventTracer';
10
+ import { EventTracing } from './EventTracing';
11
+ /**
12
+ * Configuration for observability features.
13
+ * @public
14
+ */
15
+ export interface ObservabilityConfig {
16
+ /**
17
+ * Enable observability features.
18
+ * @default false
19
+ */
20
+ enabled?: boolean;
21
+ /**
22
+ * MetricsRegistry instance from @gravito/monitor.
23
+ * Required if metrics collection is enabled.
24
+ */
25
+ metrics?: any;
26
+ /**
27
+ * Enable OpenTelemetry distributed tracing.
28
+ * @default false
29
+ */
30
+ tracing?: boolean;
31
+ /**
32
+ * Prefix for metric names.
33
+ * @default 'gravito_event_'
34
+ */
35
+ metricsPrefix?: string;
36
+ }
37
+ /**
38
+ * Observable Hook Manager - extends HookManager with observability.
39
+ *
40
+ * Provides metrics and distributed tracing for event dispatch and listener execution.
41
+ * Maintains 100% backward compatibility with HookManager.
42
+ *
43
+ * @public
44
+ */
45
+ export declare class ObservableHookManager extends HookManager {
46
+ private eventMetrics?;
47
+ private eventTracer?;
48
+ private eventTracing?;
49
+ private obsConfig;
50
+ /**
51
+ * Create a new ObservableHookManager instance.
52
+ *
53
+ * @param config - HookManager configuration
54
+ * @param obsConfig - Observability configuration
55
+ */
56
+ constructor(config?: HookManagerConfig, obsConfig?: ObservabilityConfig);
57
+ /**
58
+ * Run all registered actions asynchronously via priority queue with observability.
59
+ *
60
+ * This override adds metrics and tracing to the base implementation.
61
+ *
62
+ * @template TArgs - The type of arguments passed to the action.
63
+ * @param hook - The name of the hook.
64
+ * @param args - The arguments to pass to the callbacks.
65
+ * @param options - Event options for async dispatch.
66
+ */
67
+ doActionAsync<TArgs = unknown>(hook: string, args: TArgs, options?: EventOptions): Promise<void>;
68
+ /**
69
+ * Run all registered actions synchronously with observability.
70
+ *
71
+ * This override adds metrics and tracing to the base implementation.
72
+ *
73
+ * @template TArgs - The type of arguments passed to the action.
74
+ * @param hook - The name of the hook.
75
+ * @param args - The arguments to pass to the callbacks.
76
+ */
77
+ doActionSync<TArgs = unknown>(hook: string, args: TArgs): Promise<void>;
78
+ /**
79
+ * Get the EventMetrics instance.
80
+ *
81
+ * @returns EventMetrics instance if observability is enabled, undefined otherwise
82
+ */
83
+ getMetrics(): EventMetrics | undefined;
84
+ /**
85
+ * Get the EventTracer instance.
86
+ *
87
+ * @returns EventTracer instance if tracing is enabled, undefined otherwise
88
+ */
89
+ getTracer(): EventTracer | undefined;
90
+ /**
91
+ * Update observability configuration at runtime.
92
+ *
93
+ * @param config - New observability configuration
94
+ */
95
+ setObservabilityConfig(config: Partial<ObservabilityConfig>): void;
96
+ /**
97
+ * Get the EventTracing instance.
98
+ *
99
+ * @returns EventTracing instance if tracing is enabled, undefined otherwise
100
+ */
101
+ getEventTracing(): EventTracing | undefined;
102
+ /**
103
+ * Get current observability configuration.
104
+ *
105
+ * @returns Current observability configuration
106
+ */
107
+ getObservabilityConfig(): ObservabilityConfig;
108
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Worker Pool Metrics Recorder for OpenTelemetry integration.
3
+ *
4
+ * Tracks Worker Pool statistics and emits OpenTelemetry metrics.
5
+ *
6
+ * @internal
7
+ */
8
+ import type { Meter } from '@opentelemetry/api';
9
+ /**
10
+ * Worker job status for metrics.
11
+ */
12
+ export declare enum WorkerJobStatus {
13
+ COMPLETED = "completed",
14
+ FAILED = "failed"
15
+ }
16
+ /**
17
+ * Stream Worker Metrics Recorder.
18
+ *
19
+ * Collects and records metrics related to Worker Pool execution:
20
+ * - Pool size and utilization
21
+ * - Job execution duration
22
+ * - Job success/failure counts
23
+ * - Queue depth
24
+ */
25
+ export declare class StreamWorkerMetrics {
26
+ private meter;
27
+ private jobDurationHistogram?;
28
+ private jobCounterCompleted?;
29
+ constructor(meter: Meter);
30
+ /**
31
+ * Initialize OpenTelemetry metrics.
32
+ */
33
+ private initializeMetrics;
34
+ /**
35
+ * Record job execution duration.
36
+ *
37
+ * @param durationSeconds - Duration in seconds
38
+ * @param status - Job status (completed or failed)
39
+ * @param queue - Queue name
40
+ */
41
+ recordJobDuration(durationSeconds: number, status: WorkerJobStatus, queue?: string): void;
42
+ /**
43
+ * Record pool size change.
44
+ *
45
+ * @param poolSize - Current pool size
46
+ * @param callback - Optional callback to fetch pool size dynamically
47
+ */
48
+ setPoolSizeProvider(callback: () => number): void;
49
+ private poolSizeCallback?;
50
+ /**
51
+ * Get current pool size.
52
+ */
53
+ getPoolSize(): number;
54
+ /**
55
+ * Record queue depth change.
56
+ *
57
+ * @param depth - Current queue depth
58
+ * @param callback - Optional callback to fetch queue depth dynamically
59
+ */
60
+ setQueueDepthProvider(callback: () => number): void;
61
+ private queueDepthCallback?;
62
+ /**
63
+ * Get current queue depth.
64
+ */
65
+ getQueueDepth(): number;
66
+ }
67
+ /**
68
+ * Worker Metrics Recorder interface for dependency injection.
69
+ */
70
+ export interface WorkerMetricsRecorder {
71
+ recordJobDuration(durationSeconds: number, status: WorkerJobStatus, queue?: string): void;
72
+ setPoolSizeProvider(callback: () => number): void;
73
+ setQueueDepthProvider(callback: () => number): void;
74
+ getPoolSize(): number;
75
+ getQueueDepth(): number;
76
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export { EventMetrics } from './EventMetrics';
5
+ /**
6
+ * @public
7
+ */
8
+ export { EventTracer } from './EventTracer';
9
+ /**
10
+ * @public
11
+ */
12
+ export { EventTracing, type EventTracingConfig, getEventTracing } from './EventTracing';
13
+ /**
14
+ * @public
15
+ */
16
+ export { type ObservabilityConfig, ObservableHookManager } from './ObservableHookManager';
17
+ /**
18
+ * @public
19
+ */
20
+ export { OTelEventMetrics, type QueueDepthCallback } from './OTelEventMetrics';
21
+ /**
22
+ * @public
23
+ */
24
+ export { StreamWorkerMetrics, WorkerJobStatus, type WorkerMetricsRecorder, } from './StreamWorkerMetrics';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Minimal metric types for event observability.
3
+ * Avoids importing @gravito/monitor from core to prevent circular dependency.
4
+ * Runtime implementations are provided by @gravito/monitor MetricsRegistry.
5
+ *
6
+ * @internal
7
+ */
8
+ export interface EventMetricCounter {
9
+ inc(labels: Record<string, string>): void;
10
+ }
11
+ export interface EventMetricGauge {
12
+ set(value: number, labels: Record<string, string>): void;
13
+ }
14
+ export interface EventMetricHistogram {
15
+ observe(value: number, labels: Record<string, string>): void;
16
+ }
@@ -0,0 +1,77 @@
1
+ import { BackpressureManager } from './BackpressureManager';
2
+ import type { DeadLetterQueue } from './DeadLetterQueue';
3
+ import type { OTelEventMetrics } from './observability/OTelEventMetrics';
4
+ import { type PriorityStatistics } from './PriorityEscalationManager';
5
+ import type { BackpressureStrategy, EventQueueConfig, EventTask, MultiPriorityQueueDepth } from './types';
6
+ /**
7
+ * Result of an enqueue operation.
8
+ *
9
+ * - `{ status: 'queued', id }` - Task successfully queued
10
+ * - `{ status: 'dropped' }` - Task dropped due to backpressure
11
+ * - `{ status: 'delayed', id, delayMs }` - Task should be re-enqueued after delayMs
12
+ *
13
+ * @internal
14
+ */
15
+ export type EnqueueResult = {
16
+ status: 'queued';
17
+ id: string;
18
+ } | {
19
+ status: 'dropped';
20
+ } | {
21
+ status: 'delayed';
22
+ id: string;
23
+ delayMs: number;
24
+ };
25
+ /**
26
+ * Priority queue core: manages event task queues and backpressure.
27
+ *
28
+ * Handles enqueueing, dequeuing, backpressure logic, and priority escalation.
29
+ * This class is used internally by EventPriorityQueue as a composition target.
30
+ *
31
+ * @internal
32
+ */
33
+ export declare class QueueCore {
34
+ criticalPriority: EventTask[];
35
+ highPriority: EventTask[];
36
+ normalPriority: EventTask[];
37
+ lowPriority: EventTask[];
38
+ processingPartitions: Set<string>;
39
+ private taskIdCounter;
40
+ private dlq?;
41
+ private otelEventMetrics?;
42
+ private backpressureManager?;
43
+ private priorityStats?;
44
+ private config;
45
+ constructor(config?: EventQueueConfig);
46
+ setDeadLetterQueue(dlq: DeadLetterQueue): void;
47
+ setOTelEventMetrics(metrics: OTelEventMetrics): void;
48
+ setPriorityStatistics(stats: PriorityStatistics): void;
49
+ getPriorityStatistics(): PriorityStatistics | undefined;
50
+ getBackpressureManager(): BackpressureManager | undefined;
51
+ getConfig(): EventQueueConfig;
52
+ getDLQ(): DeadLetterQueue | undefined;
53
+ createTaskId(): string;
54
+ /**
55
+ * Enqueue a task into the appropriate priority queue.
56
+ * Applies priority escalation and backpressure logic.
57
+ */
58
+ enqueue(task: EventTask): EnqueueResult;
59
+ /**
60
+ * Dequeue the next task based on priority and partition ordering.
61
+ * Priority order: CRITICAL > HIGH > NORMAL > LOW
62
+ */
63
+ dequeue(): EventTask | undefined;
64
+ /**
65
+ * Re-enqueue a task for retry.
66
+ */
67
+ enqueueRetry(task: EventTask): void;
68
+ getDepth(): number;
69
+ getDepthByPriority(priority: 'critical' | 'high' | 'normal' | 'low'): number;
70
+ getQueueDepthByPriority(): MultiPriorityQueueDepth;
71
+ clear(): void;
72
+ syncBackpressure(): void;
73
+ private handleBackpressure;
74
+ private dropOldest;
75
+ private dequeueFromPriority;
76
+ }
77
+ export type { BackpressureStrategy, EventQueueConfig, EventTask };
@@ -0,0 +1,51 @@
1
+ import type { Span } from '@opentelemetry/api';
2
+ import { CircuitBreaker } from './CircuitBreaker';
3
+ import type { DeadLetterQueue } from './DeadLetterQueue';
4
+ import type { EventOptions } from './EventOptions';
5
+ import type { EventMetrics } from './observability/EventMetrics';
6
+ import type { EventTracing } from './observability/EventTracing';
7
+ import type { OTelEventMetrics } from './observability/OTelEventMetrics';
8
+ import type { RetryScheduler } from './RetryScheduler';
9
+ import type { EventTask } from './types';
10
+ /**
11
+ * Executes event tasks with circuit breaker protection, retry logic,
12
+ * exponential backoff, DLQ integration, and distributed tracing.
13
+ *
14
+ * @internal
15
+ */
16
+ export declare class TaskExecutor {
17
+ private eventCircuitBreakers;
18
+ private eventMetrics?;
19
+ private otelEventMetrics?;
20
+ private eventTracing?;
21
+ private currentDispatchSpan?;
22
+ private retryScheduler?;
23
+ private dlq?;
24
+ private persistentDLQHandler?;
25
+ private enqueueRetryFn?;
26
+ setDeadLetterQueue(dlq: DeadLetterQueue): void;
27
+ setPersistentDLQHandler(handler: (hook: string, args: unknown, options: EventOptions, error: Error, retryCount: number, firstFailedAt: number) => Promise<void>): void;
28
+ setEventMetrics(metrics: EventMetrics): void;
29
+ setOTelEventMetrics(metrics: OTelEventMetrics): void;
30
+ setEventTracing(tracing: EventTracing): void;
31
+ setCurrentDispatchSpan(span: Span | undefined): void;
32
+ getCurrentDispatchSpan(): Span | undefined;
33
+ setRetryScheduler(scheduler: RetryScheduler): void;
34
+ getRetryScheduler(): RetryScheduler | undefined;
35
+ /**
36
+ * Set the callback to use when re-enqueueing a task after a retry delay.
37
+ */
38
+ setEnqueueRetryFn(fn: (task: EventTask) => void): void;
39
+ getCircuitBreaker(hook: string): CircuitBreaker;
40
+ getCircuitBreakers(): Map<string, CircuitBreaker>;
41
+ resetCircuitBreaker(hook: string): boolean;
42
+ /**
43
+ * Execute an event task by running all its callbacks.
44
+ * Implements circuit breaker protection, retry logic, and DLQ integration.
45
+ */
46
+ executeTask(task: EventTask, processingPartitions: Set<string>): Promise<void>;
47
+ private sendToDLQ;
48
+ private getOrCreateEventCircuitBreaker;
49
+ private calculateRetryDelay;
50
+ private executeWithTimeout;
51
+ }