@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.
- package/README.md +100 -6
- package/README.zh-TW.md +101 -6
- package/dist/Application.d.ts +256 -0
- package/dist/CommandKernel.d.ts +33 -0
- package/dist/ConfigManager.d.ts +65 -0
- package/dist/Container/RequestScopeManager.d.ts +62 -0
- package/dist/Container/RequestScopeMetrics.d.ts +144 -0
- package/dist/Container.d.ts +153 -0
- package/dist/ErrorHandler.d.ts +66 -0
- package/dist/Event.d.ts +5 -0
- package/dist/EventManager.d.ts +123 -0
- package/dist/GlobalErrorHandlers.d.ts +47 -0
- package/dist/GravitoServer.d.ts +28 -0
- package/dist/HookManager.d.ts +435 -0
- package/dist/Listener.d.ts +4 -0
- package/dist/Logger.d.ts +20 -0
- package/dist/PlanetCore.d.ts +402 -0
- package/dist/RequestContext.d.ts +97 -0
- package/dist/Route.d.ts +36 -0
- package/dist/Router.d.ts +270 -0
- package/dist/ServiceProvider.d.ts +178 -0
- package/dist/adapters/GravitoEngineAdapter.d.ts +27 -0
- package/dist/adapters/bun/AdaptiveAdapter.d.ts +99 -0
- package/dist/adapters/bun/BunContext.d.ts +54 -0
- package/dist/adapters/bun/BunNativeAdapter.d.ts +66 -0
- package/dist/adapters/bun/BunRequest.d.ts +31 -0
- package/dist/adapters/bun/BunWebSocketHandler.d.ts +48 -0
- package/dist/adapters/bun/RadixNode.d.ts +19 -0
- package/dist/adapters/bun/RadixRouter.d.ts +32 -0
- package/dist/adapters/bun/index.d.ts +7 -0
- package/dist/adapters/bun/types.d.ts +20 -0
- package/dist/adapters/index.d.ts +12 -0
- package/dist/adapters/types.d.ts +235 -0
- package/dist/binary/BinaryUtils.d.ts +105 -0
- package/dist/binary/index.d.ts +5 -0
- package/dist/cli/queue-commands.d.ts +6 -0
- package/dist/compat/async-local-storage.browser.d.ts +9 -0
- package/dist/compat/async-local-storage.d.ts +7 -0
- package/dist/compat/crypto.browser.d.ts +5 -0
- package/dist/compat/crypto.d.ts +6 -0
- package/dist/compat.d.ts +23 -1
- package/dist/compat.js +3 -0
- package/dist/compat.js.map +9 -0
- package/dist/engine/AOTRouter.d.ts +139 -0
- package/dist/engine/FastContext.d.ts +141 -0
- package/dist/engine/Gravito.d.ts +131 -0
- package/dist/engine/MinimalContext.d.ts +102 -0
- package/dist/engine/analyzer.d.ts +113 -0
- package/dist/engine/constants.d.ts +23 -0
- package/dist/engine/index.d.ts +14 -910
- package/dist/engine/index.js +623 -622
- package/dist/engine/index.js.map +23 -0
- package/dist/engine/path.d.ts +26 -0
- package/dist/engine/pool.d.ts +83 -0
- package/dist/engine/types.d.ts +149 -0
- package/dist/error-handling/RequestScopeErrorContext.d.ts +126 -0
- package/dist/events/BackpressureManager.d.ts +215 -0
- package/dist/events/CircuitBreaker.d.ts +229 -0
- package/dist/events/DeadLetterQueue.d.ts +219 -0
- package/dist/events/EventBackend.d.ts +12 -0
- package/dist/events/EventOptions.d.ts +204 -0
- package/dist/events/EventPriorityQueue.d.ts +63 -0
- package/dist/events/FlowControlStrategy.d.ts +109 -0
- package/dist/events/IdempotencyCache.d.ts +60 -0
- package/dist/events/MessageQueueBridge.d.ts +184 -0
- package/dist/events/PriorityEscalationManager.d.ts +82 -0
- package/dist/events/RetryScheduler.d.ts +104 -0
- package/dist/events/WorkerPool.d.ts +98 -0
- package/dist/events/WorkerPoolConfig.d.ts +153 -0
- package/dist/events/WorkerPoolMetrics.d.ts +65 -0
- package/dist/events/aggregation/AggregationWindow.d.ts +77 -0
- package/dist/events/aggregation/DeduplicationManager.d.ts +135 -0
- package/dist/events/aggregation/EventAggregationManager.d.ts +108 -0
- package/dist/events/aggregation/EventBatcher.d.ts +99 -0
- package/dist/events/aggregation/index.d.ts +10 -0
- package/dist/events/aggregation/types.d.ts +117 -0
- package/dist/events/index.d.ts +26 -0
- package/dist/events/observability/EventMetrics.d.ts +132 -0
- package/dist/events/observability/EventTracer.d.ts +68 -0
- package/dist/events/observability/EventTracing.d.ts +161 -0
- package/dist/events/observability/OTelEventMetrics.d.ts +332 -0
- package/dist/events/observability/ObservableHookManager.d.ts +108 -0
- package/dist/events/observability/StreamWorkerMetrics.d.ts +76 -0
- package/dist/events/observability/index.d.ts +24 -0
- package/dist/events/observability/metrics-types.d.ts +16 -0
- package/dist/events/queue-core.d.ts +77 -0
- package/dist/events/task-executor.d.ts +51 -0
- package/dist/events/types.d.ts +134 -0
- package/dist/exceptions/AuthenticationException.d.ts +8 -0
- package/dist/exceptions/AuthorizationException.d.ts +8 -0
- package/dist/exceptions/CircularDependencyException.d.ts +9 -0
- package/dist/exceptions/GravitoException.d.ts +23 -0
- package/dist/exceptions/HttpException.d.ts +9 -0
- package/dist/exceptions/ModelNotFoundException.d.ts +10 -0
- package/dist/exceptions/ValidationException.d.ts +22 -0
- package/dist/exceptions/index.d.ts +7 -0
- package/dist/ffi/NativeAccelerator.d.ts +69 -0
- package/dist/ffi/NativeHasher.d.ts +139 -0
- package/dist/ffi/cbor-fallback.d.ts +96 -0
- package/dist/ffi/hash-fallback.d.ts +33 -0
- package/dist/ffi/index.d.ts +10 -0
- package/dist/ffi/index.js +131 -0
- package/dist/ffi/index.js.map +11 -0
- package/dist/ffi/types.d.ts +135 -0
- package/dist/health/HealthProvider.d.ts +67 -0
- package/dist/helpers/Arr.d.ts +19 -0
- package/dist/helpers/Str.d.ts +38 -0
- package/dist/helpers/data.d.ts +25 -0
- package/dist/helpers/errors.d.ts +34 -0
- package/dist/helpers/response.d.ts +41 -0
- package/dist/helpers.d.ts +338 -0
- package/dist/hooks/ActionManager.d.ts +132 -0
- package/dist/hooks/AsyncDetector.d.ts +84 -0
- package/dist/hooks/FilterManager.d.ts +71 -0
- package/dist/hooks/MigrationWarner.d.ts +24 -0
- package/dist/hooks/dlq-operations.d.ts +60 -0
- package/dist/hooks/index.d.ts +11 -0
- package/dist/hooks/types.d.ts +107 -0
- package/dist/http/CookieJar.d.ts +51 -0
- package/dist/http/cookie.d.ts +29 -0
- package/dist/http/index.d.ts +12 -0
- package/dist/{compat-CI8hiulX.d.cts → http/types.d.ts} +35 -16
- package/dist/index.browser.d.ts +34 -0
- package/dist/index.d.ts +60 -10981
- package/dist/index.js +10808 -11273
- package/dist/index.js.map +166 -0
- package/dist/observability/QueueDashboard.d.ts +136 -0
- package/dist/observability/contracts.d.ts +137 -0
- package/dist/observability/index.d.ts +13 -0
- package/dist/reliability/DeadLetterQueueManager.d.ts +349 -0
- package/dist/reliability/RetryPolicy.d.ts +217 -0
- package/dist/reliability/index.d.ts +6 -0
- package/dist/router/ControllerDispatcher.d.ts +12 -0
- package/dist/router/RequestValidator.d.ts +20 -0
- package/dist/runtime/adapter-bun.d.ts +12 -0
- package/dist/runtime/adapter-deno.d.ts +12 -0
- package/dist/runtime/adapter-node.d.ts +12 -0
- package/dist/runtime/adapter-unknown.d.ts +13 -0
- package/dist/runtime/archive.d.ts +17 -0
- package/dist/runtime/compression.d.ts +21 -0
- package/dist/runtime/deep-equals.d.ts +56 -0
- package/dist/runtime/detection.d.ts +22 -0
- package/dist/runtime/escape.d.ts +34 -0
- package/dist/runtime/index.browser.d.ts +20 -0
- package/dist/runtime/index.d.ts +44 -0
- package/dist/runtime/markdown.d.ts +44 -0
- package/dist/runtime/types.d.ts +436 -0
- package/dist/runtime-helpers.d.ts +67 -0
- package/dist/runtime.d.ts +11 -0
- package/dist/security/Encrypter.d.ts +33 -0
- package/dist/security/Hasher.d.ts +29 -0
- package/dist/testing/HttpTester.d.ts +39 -0
- package/dist/testing/TestResponse.d.ts +78 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/transpiler-utils.d.ts +170 -0
- package/dist/types/events.d.ts +94 -0
- package/dist/types.d.ts +13 -0
- package/package.json +25 -56
- package/src/ffi/native/cbor.c +1148 -0
- package/dist/Metrics-VOWWRNNR.js +0 -219
- package/dist/chunk-R5U7XKVJ.js +0 -16
- package/dist/compat-CI8hiulX.d.ts +0 -376
- package/dist/compat.cjs +0 -18
- package/dist/compat.d.cts +0 -1
- package/dist/engine/index.cjs +0 -1764
- package/dist/engine/index.d.cts +0 -922
- package/dist/index.cjs +0 -14906
- package/dist/index.d.cts +0 -11008
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event aggregation and deduplication types (FS-102)
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
import { BackpressureState } from '../BackpressureManager';
|
|
6
|
+
/**
|
|
7
|
+
* Deduplication statistics.
|
|
8
|
+
*/
|
|
9
|
+
export interface DeduplicationStats {
|
|
10
|
+
/** Total events submitted */
|
|
11
|
+
totalEvents: number;
|
|
12
|
+
/** Events after deduplication */
|
|
13
|
+
deduplicatedEvents: number;
|
|
14
|
+
/** Events removed by deduplication */
|
|
15
|
+
removedCount: number;
|
|
16
|
+
/** Number of patterns aggregated */
|
|
17
|
+
patternsAggregated: number;
|
|
18
|
+
/** Deduplication rate (%) */
|
|
19
|
+
deduplicationRate: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Batch submission statistics.
|
|
23
|
+
*/
|
|
24
|
+
export interface BatchStats {
|
|
25
|
+
/** Total batches submitted */
|
|
26
|
+
totalBatches: number;
|
|
27
|
+
/** Total events submitted */
|
|
28
|
+
totalEvents: number;
|
|
29
|
+
/** Average batch size */
|
|
30
|
+
averageBatchSize: number;
|
|
31
|
+
/** Average batch latency (ms) */
|
|
32
|
+
averageBatchLatency: number;
|
|
33
|
+
/** Last flush timestamp */
|
|
34
|
+
lastFlushTime: number;
|
|
35
|
+
/** Pending events in queue */
|
|
36
|
+
pendingEvents: number;
|
|
37
|
+
/** Auto-triggered flushes */
|
|
38
|
+
autoFlushCount: number;
|
|
39
|
+
/** Manual flushes */
|
|
40
|
+
manualFlushCount: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Aggregation window statistics.
|
|
44
|
+
*/
|
|
45
|
+
export interface WindowStats {
|
|
46
|
+
/** Current window size (ms) */
|
|
47
|
+
currentWindowMs: number;
|
|
48
|
+
/** Minimum window size (ms) */
|
|
49
|
+
minWindowMs: number;
|
|
50
|
+
/** Maximum window size (ms) */
|
|
51
|
+
maxWindowMs: number;
|
|
52
|
+
/** Last window adjustment reason */
|
|
53
|
+
lastAdjustmentReason?: string;
|
|
54
|
+
/** Window adjustment count */
|
|
55
|
+
adjustmentCount: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Complete aggregation statistics.
|
|
59
|
+
*/
|
|
60
|
+
export interface AggregationStats {
|
|
61
|
+
deduplication: DeduplicationStats;
|
|
62
|
+
batching: BatchStats;
|
|
63
|
+
window: WindowStats;
|
|
64
|
+
timestamp: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Aggregation configuration options.
|
|
68
|
+
*/
|
|
69
|
+
export interface AggregationConfig {
|
|
70
|
+
/** Enable aggregation (default: false) */
|
|
71
|
+
enabled: boolean;
|
|
72
|
+
/** Window size in milliseconds (default: 200) */
|
|
73
|
+
windowMs?: number;
|
|
74
|
+
/** Batch size threshold (default: 50) */
|
|
75
|
+
batchSize?: number;
|
|
76
|
+
/** Deduplication strategy */
|
|
77
|
+
deduplication?: 'pattern' | 'idempotencyKey' | 'off';
|
|
78
|
+
/** Deduplication pattern (string or function) */
|
|
79
|
+
pattern?: string | ((args: unknown) => string);
|
|
80
|
+
/** Merge priority when deduplicating */
|
|
81
|
+
mergePriority?: 'highest' | 'earliest' | 'latest';
|
|
82
|
+
/** Enable background cleanup (default: true) */
|
|
83
|
+
enableCleanup?: boolean;
|
|
84
|
+
/** Cleanup interval (ms, default: 5 minutes) */
|
|
85
|
+
cleanupIntervalMs?: number;
|
|
86
|
+
/** TTL for deduplication entries (ms, default: 10 minutes) */
|
|
87
|
+
ttlMs?: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Default aggregation configuration.
|
|
91
|
+
*/
|
|
92
|
+
export declare const DEFAULT_AGGREGATION_CONFIG: Required<AggregationConfig>;
|
|
93
|
+
/**
|
|
94
|
+
* Priority order for merge decisions.
|
|
95
|
+
*/
|
|
96
|
+
export declare const PRIORITY_ORDER: Record<string, number>;
|
|
97
|
+
/**
|
|
98
|
+
* Backpressure-aware window configuration.
|
|
99
|
+
*/
|
|
100
|
+
export interface WindowAdjustmentConfig {
|
|
101
|
+
/** Window for NORMAL backpressure state */
|
|
102
|
+
normalMs: number;
|
|
103
|
+
/** Window for WARNING backpressure state */
|
|
104
|
+
warningMs: number;
|
|
105
|
+
/** Window for CRITICAL backpressure state */
|
|
106
|
+
criticalMs: number;
|
|
107
|
+
/** Window for OVERFLOW backpressure state */
|
|
108
|
+
overflowMs: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Default window adjustment configuration based on backpressure.
|
|
112
|
+
*/
|
|
113
|
+
export declare const DEFAULT_WINDOW_ADJUSTMENT: WindowAdjustmentConfig;
|
|
114
|
+
/**
|
|
115
|
+
* Get suggested window size based on backpressure state.
|
|
116
|
+
*/
|
|
117
|
+
export declare function getSuggestedWindow(state: BackpressureState, config?: WindowAdjustmentConfig): number;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event system exports for async event dispatch.
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
export * from './EventBackend';
|
|
6
|
+
export type { EventOptions } from './EventOptions';
|
|
7
|
+
export { DEFAULT_EVENT_OPTIONS } from './EventOptions';
|
|
8
|
+
export type { BackpressureStrategy, EventQueueConfig, EventTask } from './types';
|
|
9
|
+
export type { BackpressureConfig, BackpressureDecision, BackpressureMetricsSnapshot, } from './BackpressureManager';
|
|
10
|
+
export { BackpressureManager, BackpressureState } from './BackpressureManager';
|
|
11
|
+
export type { CircuitBreakerMetrics, CircuitBreakerMetricsRecorder, CircuitBreakerOptions, } from './CircuitBreaker';
|
|
12
|
+
export { CircuitBreaker, CircuitBreakerState } from './CircuitBreaker';
|
|
13
|
+
export type { DLQEntry, DLQEntryCallback, DLQEntrySource, DLQFilter } from './DeadLetterQueue';
|
|
14
|
+
export { DeadLetterQueue } from './DeadLetterQueue';
|
|
15
|
+
export { EventPriorityQueue } from './EventPriorityQueue';
|
|
16
|
+
export * from './FlowControlStrategy';
|
|
17
|
+
export { IdempotencyCache } from './IdempotencyCache';
|
|
18
|
+
export { MessageQueueBridge } from './MessageQueueBridge';
|
|
19
|
+
export type { PriorityStatistics } from './PriorityEscalationManager';
|
|
20
|
+
export { PriorityEscalationManager } from './PriorityEscalationManager';
|
|
21
|
+
export type { RetrySchedulerConfig } from './RetryScheduler';
|
|
22
|
+
export { RetryScheduler } from './RetryScheduler';
|
|
23
|
+
export type { DeadLetterDecision, MultiPriorityQueueDepth, WindowAdjustment } from './types';
|
|
24
|
+
export { WorkerPool } from './WorkerPool';
|
|
25
|
+
export type { WorkerPoolConfig, WorkerPoolStats, WorkerStats } from './WorkerPoolConfig';
|
|
26
|
+
export { WorkerPoolMetrics } from './WorkerPoolMetrics';
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/core - Event System Metrics
|
|
3
|
+
*
|
|
4
|
+
* Manages metric collection for event dispatch and listener execution.
|
|
5
|
+
*/
|
|
6
|
+
import type { EventMetricGauge, EventMetricHistogram } from './metrics-types';
|
|
7
|
+
/**
|
|
8
|
+
* Event metrics collector for monitoring and observability.
|
|
9
|
+
*
|
|
10
|
+
* Collects 6 core metrics:
|
|
11
|
+
* - Event dispatch latency (Histogram)
|
|
12
|
+
* - Listener execution time (Histogram)
|
|
13
|
+
* - Queue depth by priority (Gauge)
|
|
14
|
+
* - Failure count by error type (Counter)
|
|
15
|
+
* - Timeout count (Counter)
|
|
16
|
+
* - Processed event count by status (Counter)
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare class EventMetrics {
|
|
21
|
+
private dispatchLatency;
|
|
22
|
+
private listenerExecutionTime;
|
|
23
|
+
private queueDepthGauge;
|
|
24
|
+
private failureCounter;
|
|
25
|
+
private timeoutCounter;
|
|
26
|
+
private processedCounter;
|
|
27
|
+
private circuitBreakerStateGauge;
|
|
28
|
+
private circuitBreakerTransitionsCounter;
|
|
29
|
+
private circuitBreakerFailuresCounter;
|
|
30
|
+
private circuitBreakerSuccessesCounter;
|
|
31
|
+
private circuitBreakerOpenDurationHistogram;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new EventMetrics instance.
|
|
34
|
+
*
|
|
35
|
+
* @param registry - MetricsRegistry from @gravito/monitor
|
|
36
|
+
* @param prefix - Metric name prefix (default: 'gravito_event_')
|
|
37
|
+
*/
|
|
38
|
+
constructor(registry: any, // MetricsRegistry type
|
|
39
|
+
prefix?: string);
|
|
40
|
+
/**
|
|
41
|
+
* Record event dispatch latency.
|
|
42
|
+
*
|
|
43
|
+
* @param eventName - Name of the event
|
|
44
|
+
* @param priority - Priority level (high, normal, low)
|
|
45
|
+
* @param seconds - Duration in seconds
|
|
46
|
+
*/
|
|
47
|
+
recordDispatchLatency(eventName: string, priority: string, seconds: number): void;
|
|
48
|
+
/**
|
|
49
|
+
* Record listener execution time.
|
|
50
|
+
*
|
|
51
|
+
* @param eventName - Name of the event
|
|
52
|
+
* @param index - Index of the listener in the callback list
|
|
53
|
+
* @param seconds - Duration in seconds
|
|
54
|
+
*/
|
|
55
|
+
recordListenerExecution(eventName: string, index: number, seconds: number): void;
|
|
56
|
+
/**
|
|
57
|
+
* Update queue depth gauge for a specific priority.
|
|
58
|
+
*
|
|
59
|
+
* @param priority - Priority level (high, normal, low)
|
|
60
|
+
* @param depth - Current queue depth
|
|
61
|
+
*/
|
|
62
|
+
updateQueueDepth(priority: string, depth: number): void;
|
|
63
|
+
/**
|
|
64
|
+
* Record event processing failure.
|
|
65
|
+
*
|
|
66
|
+
* @param eventName - Name of the event
|
|
67
|
+
* @param errorType - Type of error (e.g., 'TypeError', 'TimeoutError')
|
|
68
|
+
*/
|
|
69
|
+
recordFailure(eventName: string, errorType: string): void;
|
|
70
|
+
/**
|
|
71
|
+
* Record event processing timeout.
|
|
72
|
+
*
|
|
73
|
+
* @param eventName - Name of the event
|
|
74
|
+
*/
|
|
75
|
+
recordTimeout(eventName: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Record processed event (success or failure).
|
|
78
|
+
*
|
|
79
|
+
* @param eventName - Name of the event
|
|
80
|
+
* @param status - Processing status ('success' or 'failure')
|
|
81
|
+
*/
|
|
82
|
+
recordProcessed(eventName: string, status: 'success' | 'failure'): void;
|
|
83
|
+
/**
|
|
84
|
+
* Get reference to dispatch latency histogram.
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
getDispatchLatencyHistogram(): EventMetricHistogram;
|
|
88
|
+
/**
|
|
89
|
+
* Get reference to listener execution time histogram.
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
getListenerExecutionHistogram(): EventMetricHistogram;
|
|
93
|
+
/**
|
|
94
|
+
* Get reference to queue depth gauge.
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
getQueueDepthGauge(): EventMetricGauge;
|
|
98
|
+
/**
|
|
99
|
+
* Record circuit breaker state change.
|
|
100
|
+
*
|
|
101
|
+
* @param eventName - Name of the event
|
|
102
|
+
* @param state - Circuit breaker state (0=CLOSED, 1=HALF_OPEN, 2=OPEN)
|
|
103
|
+
*/
|
|
104
|
+
recordCircuitBreakerState(eventName: string, state: number): void;
|
|
105
|
+
/**
|
|
106
|
+
* Record circuit breaker state transition.
|
|
107
|
+
*
|
|
108
|
+
* @param eventName - Name of the event
|
|
109
|
+
* @param fromState - Previous state
|
|
110
|
+
* @param toState - New state
|
|
111
|
+
*/
|
|
112
|
+
recordCircuitBreakerTransition(eventName: string, fromState: string, toState: string): void;
|
|
113
|
+
/**
|
|
114
|
+
* Record circuit breaker failure.
|
|
115
|
+
*
|
|
116
|
+
* @param eventName - Name of the event
|
|
117
|
+
*/
|
|
118
|
+
recordCircuitBreakerFailure(eventName: string): void;
|
|
119
|
+
/**
|
|
120
|
+
* Record circuit breaker success.
|
|
121
|
+
*
|
|
122
|
+
* @param eventName - Name of the event
|
|
123
|
+
*/
|
|
124
|
+
recordCircuitBreakerSuccess(eventName: string): void;
|
|
125
|
+
/**
|
|
126
|
+
* Record circuit breaker OPEN duration.
|
|
127
|
+
*
|
|
128
|
+
* @param eventName - Name of the event
|
|
129
|
+
* @param seconds - Duration in seconds
|
|
130
|
+
*/
|
|
131
|
+
recordCircuitBreakerOpenDuration(eventName: string, seconds: number): void;
|
|
132
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/core - Event System Tracer
|
|
3
|
+
*
|
|
4
|
+
* Manages OpenTelemetry distributed tracing for event dispatch.
|
|
5
|
+
*/
|
|
6
|
+
import type { Span } from '@opentelemetry/api';
|
|
7
|
+
/**
|
|
8
|
+
* Event tracer for distributed tracing support.
|
|
9
|
+
*
|
|
10
|
+
* Integrates with OpenTelemetry to provide:
|
|
11
|
+
* - Event dispatch tracing
|
|
12
|
+
* - Listener execution tracing
|
|
13
|
+
* - Error recording
|
|
14
|
+
* - Span hierarchy
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export declare class EventTracer {
|
|
19
|
+
private tracer;
|
|
20
|
+
/**
|
|
21
|
+
* Create a new EventTracer instance.
|
|
22
|
+
*
|
|
23
|
+
* @param tracerName - Name of the tracer (default: '@gravito/core')
|
|
24
|
+
*/
|
|
25
|
+
constructor(tracerName?: string);
|
|
26
|
+
/**
|
|
27
|
+
* Start a span for event dispatch.
|
|
28
|
+
*
|
|
29
|
+
* @param eventName - Name of the event
|
|
30
|
+
* @param callbackCount - Number of callbacks registered for this event
|
|
31
|
+
* @param priority - Priority level (high, normal, low)
|
|
32
|
+
* @returns Span for the event dispatch
|
|
33
|
+
*/
|
|
34
|
+
startDispatchSpan(eventName: string, callbackCount: number, priority: string): Span;
|
|
35
|
+
/**
|
|
36
|
+
* Start a span for listener execution.
|
|
37
|
+
*
|
|
38
|
+
* @param _parentSpan - Parent span for this listener
|
|
39
|
+
* @param eventName - Name of the event
|
|
40
|
+
* @param listenerIndex - Index of the listener in the callback list
|
|
41
|
+
* @returns Child span for the listener execution
|
|
42
|
+
*/
|
|
43
|
+
startListenerSpan(_parentSpan: Span, eventName: string, listenerIndex: number): Span;
|
|
44
|
+
/**
|
|
45
|
+
* Record an error in the span.
|
|
46
|
+
*
|
|
47
|
+
* @param span - Span to record error in
|
|
48
|
+
* @param error - Error that occurred
|
|
49
|
+
*/
|
|
50
|
+
recordError(span: Span, error: Error): void;
|
|
51
|
+
/**
|
|
52
|
+
* End a span with a specific status.
|
|
53
|
+
*
|
|
54
|
+
* @param span - Span to end
|
|
55
|
+
* @param status - Status ('ok' or 'error')
|
|
56
|
+
*/
|
|
57
|
+
endSpan(span: Span, status?: 'ok' | 'error'): void;
|
|
58
|
+
/**
|
|
59
|
+
* Create a timer span for measuring duration.
|
|
60
|
+
*
|
|
61
|
+
* @param eventName - Name of the event
|
|
62
|
+
* @returns Object with span and duration recording function
|
|
63
|
+
*/
|
|
64
|
+
startTimer(eventName: string): {
|
|
65
|
+
span: Span;
|
|
66
|
+
endTimer: (status?: 'ok' | 'error') => void;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/core - Event System Tracing
|
|
3
|
+
*
|
|
4
|
+
* 使用 OpenTelemetry API 實現事件系統的分佈式追蹤。
|
|
5
|
+
* 提供事件派發、監聽器執行與隊列操作的端到端追蹤。
|
|
6
|
+
*/
|
|
7
|
+
import type { Span } from '@opentelemetry/api';
|
|
8
|
+
/**
|
|
9
|
+
* 事件追蹤配置
|
|
10
|
+
*/
|
|
11
|
+
export interface EventTracingConfig {
|
|
12
|
+
/** Tracer 名稱 */
|
|
13
|
+
tracerName?: string;
|
|
14
|
+
/** 是否記錄詳細的 payload 信息 */
|
|
15
|
+
capturePayload?: boolean;
|
|
16
|
+
/** 最大 payload 大小(字節) */
|
|
17
|
+
maxPayloadSize?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 事件追蹤管理器
|
|
21
|
+
*
|
|
22
|
+
* 提供事件系統的分佈式追蹤能力,包括:
|
|
23
|
+
* - 事件派發追蹤
|
|
24
|
+
* - 監聽器執行追蹤
|
|
25
|
+
* - 隊列操作追蹤
|
|
26
|
+
* - 異常記錄與追蹤
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare class EventTracing {
|
|
31
|
+
private tracer;
|
|
32
|
+
private config;
|
|
33
|
+
constructor(config?: EventTracingConfig);
|
|
34
|
+
/**
|
|
35
|
+
* 為事件派發創建追蹤 Span
|
|
36
|
+
*
|
|
37
|
+
* @param eventName - 事件名稱
|
|
38
|
+
* @param listenerCount - 監聽器數量
|
|
39
|
+
* @param priority - 優先級(high, normal, low)
|
|
40
|
+
* @param payload - 事件負載(可選,用於調試)
|
|
41
|
+
* @returns Span 實例
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const tracer = new EventTracing()
|
|
46
|
+
* const span = tracer.startDispatchSpan('order:created', 3, 'high', orderData)
|
|
47
|
+
* try {
|
|
48
|
+
* // 派發事件
|
|
49
|
+
* await dispatchEvent()
|
|
50
|
+
* tracer.endDispatchSpan(span, 'ok')
|
|
51
|
+
* } catch (error) {
|
|
52
|
+
* tracer.endDispatchSpan(span, 'error', error)
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
startDispatchSpan(eventName: string, listenerCount: number, priority?: 'high' | 'normal' | 'low', payload?: unknown): Span;
|
|
57
|
+
/**
|
|
58
|
+
* 為監聽器執行創建追蹤 Span
|
|
59
|
+
*
|
|
60
|
+
* @param _parentSpan - 父 Span
|
|
61
|
+
* @param eventName - 事件名稱
|
|
62
|
+
* @param listenerName - 監聽器名稱/標識
|
|
63
|
+
* @param listenerIndex - 監聽器索引
|
|
64
|
+
* @returns 子 Span 實例
|
|
65
|
+
*/
|
|
66
|
+
startListenerSpan(_parentSpan: Span, eventName: string, listenerName: string, listenerIndex: number): Span;
|
|
67
|
+
/**
|
|
68
|
+
* 為隊列操作創建追蹤 Span
|
|
69
|
+
*
|
|
70
|
+
* @param _parentSpan - 父 Span
|
|
71
|
+
* @param operationType - 操作類型(enqueue, dequeue, requeue)
|
|
72
|
+
* @param eventName - 事件名稱
|
|
73
|
+
* @param priority - 優先級
|
|
74
|
+
* @returns Span 實例
|
|
75
|
+
*/
|
|
76
|
+
startQueueOperationSpan(_parentSpan: Span, operationType: 'enqueue' | 'dequeue' | 'requeue', eventName: string, priority: 'high' | 'normal' | 'low'): Span;
|
|
77
|
+
/**
|
|
78
|
+
* 結束事件派發 Span
|
|
79
|
+
*
|
|
80
|
+
* @param span - Span 實例
|
|
81
|
+
* @param status - 完成狀態(ok, error)
|
|
82
|
+
* @param error - 如果 status 為 error,傳遞錯誤對象
|
|
83
|
+
*/
|
|
84
|
+
endDispatchSpan(span: Span, status?: 'ok' | 'error', error?: Error): void;
|
|
85
|
+
/**
|
|
86
|
+
* 結束監聽器執行 Span
|
|
87
|
+
*
|
|
88
|
+
* @param span - Span 實例
|
|
89
|
+
* @param status - 完成狀態(ok, error)
|
|
90
|
+
* @param duration - 執行時間(毫秒)
|
|
91
|
+
* @param error - 如果發生錯誤,傳遞錯誤對象
|
|
92
|
+
*/
|
|
93
|
+
endListenerSpan(span: Span, status?: 'ok' | 'error', duration?: number, error?: Error): void;
|
|
94
|
+
/**
|
|
95
|
+
* 結束隊列操作 Span
|
|
96
|
+
*
|
|
97
|
+
* @param span - Span 實例
|
|
98
|
+
* @param status - 完成狀態(ok, error)
|
|
99
|
+
* @param queueDepth - 當前隊列深度
|
|
100
|
+
* @param error - 如果發生錯誤,傳遞錯誤對象
|
|
101
|
+
*/
|
|
102
|
+
endQueueOperationSpan(span: Span, status?: 'ok' | 'error', queueDepth?: number, error?: Error): void;
|
|
103
|
+
/**
|
|
104
|
+
* 在 Span 中添加自定義屬性
|
|
105
|
+
*
|
|
106
|
+
* @param span - Span 實例
|
|
107
|
+
* @param attributes - 屬性對象
|
|
108
|
+
*/
|
|
109
|
+
addSpanAttributes(span: Span, attributes: Record<string, string | number | boolean>): void;
|
|
110
|
+
/**
|
|
111
|
+
* 在 Span 中添加自定義事件
|
|
112
|
+
*
|
|
113
|
+
* @param span - Span 實例
|
|
114
|
+
* @param eventName - 事件名稱
|
|
115
|
+
* @param attributes - 事件屬性(可選)
|
|
116
|
+
*/
|
|
117
|
+
addSpanEvent(span: Span, eventName: string, attributes?: Record<string, string | number | boolean>): void;
|
|
118
|
+
/**
|
|
119
|
+
* 記錄異常到 Span
|
|
120
|
+
*
|
|
121
|
+
* @param span - Span 實例
|
|
122
|
+
* @param error - 錯誤對象
|
|
123
|
+
*/
|
|
124
|
+
recordException(span: Span, error: Error | string): void;
|
|
125
|
+
/**
|
|
126
|
+
* 創建定時器 Span(用於測量操作時間)
|
|
127
|
+
*
|
|
128
|
+
* @param operationName - 操作名稱
|
|
129
|
+
* @returns 對象包含 span 和結束函數
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const { span, endTimer } = tracer.startTimer('slow-operation')
|
|
134
|
+
* try {
|
|
135
|
+
* await slowOperation()
|
|
136
|
+
* endTimer('ok')
|
|
137
|
+
* } catch (error) {
|
|
138
|
+
* endTimer('error', error)
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
startTimer(operationName: string): {
|
|
143
|
+
span: Span;
|
|
144
|
+
endTimer: (status?: 'ok' | 'error', error?: Error) => void;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* 獲取 tracer 實例(用於高級用法)
|
|
148
|
+
*
|
|
149
|
+
* @returns OpenTelemetry Tracer 實例
|
|
150
|
+
*/
|
|
151
|
+
getTracer(): import("@opentelemetry/api").Tracer;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 獲取或創建全局 EventTracing 實例
|
|
155
|
+
*
|
|
156
|
+
* @param config - 配置選項
|
|
157
|
+
* @returns EventTracing 實例
|
|
158
|
+
*
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
export declare function getEventTracing(config?: EventTracingConfig): EventTracing;
|