( MetricName: string, Value: number, Unit: StandardUnit, labels: Record<string, string | undefined> )
| 92 | } |
| 93 | |
| 94 | function enqueue( |
| 95 | MetricName: string, |
| 96 | Value: number, |
| 97 | Unit: StandardUnit, |
| 98 | labels: Record<string, string | undefined> |
| 99 | ): void { |
| 100 | if (!ENABLED) return |
| 101 | buffer.push({ |
| 102 | MetricName, |
| 103 | Value, |
| 104 | Unit, |
| 105 | Timestamp: new Date(), |
| 106 | Dimensions: buildDimensions(labels), |
| 107 | }) |
| 108 | if (buffer.length > MAX_BUFFER) { |
| 109 | // Flushing has stalled (CloudWatch slow/erroring) — bound memory by dropping |
| 110 | // the oldest points instead of growing without limit. |
| 111 | const overflow = buffer.length - MAX_BUFFER |
| 112 | buffer.splice(0, overflow) |
| 113 | dropped += overflow |
| 114 | } |
| 115 | ensureBackground() |
| 116 | if (buffer.length >= FLUSH_THRESHOLD) void flushHostedKeyMetrics() |
| 117 | } |
| 118 | |
| 119 | /** Drain the buffer to CloudWatch. Safe to call repeatedly; await before exit. */ |
| 120 | export async function flushHostedKeyMetrics(): Promise<void> { |
no test coverage detected