import { CloudWatchClient } from '@aws-sdk/client-cloudwatch'; export declare const DEFAULT_NAMESPACE = "ssr"; export declare const getDimensions: () => Record; /** * Input metric for sending to CloudWatch. * * @property name - The name of the metric (required) * @property value - The numeric value of the metric (optional, defaults to 0) * @property timestamp - The timestamp for the metric (optional, defaults to current time) * @property unit - The unit for the metric (optional, defaults to 'Count') * @property dimensions - Key-value pairs for metric dimensions (optional) */ interface InputMetric { name: string; value?: number; timestamp?: Date; unit?: string; dimensions?: Record; } /** * A class that handles asynchronous sending of CloudWatch metrics. * * This class uses a singleton pattern. Use MetricsSender.getSender() * to get the singleton instance. Metrics can be queued and sent in * batches, or sent immediately. The class automatically batches metrics * into groups of 20 (CloudWatch's limit per request). * * In local development environments, metrics are queued but not sent * unless the SEND_CW_METRICS environment variable is set. */ export declare class MetricsSender { private _CW; private _queue; static _override: boolean; private static _instance; /** @internal Test hook: inject a CloudWatch client for unit tests */ static _testClient: CloudWatchClient | null; private constructor(); /** * Return the number of metrics waiting to be sent * @returns {number} */ get queueLength(): number; /** * Create a CloudWatch AWS SDK client, or return a falsy value * if this MetricsSender is not actually sending metrics. * * The client is only created when running in a remote environment * (AWS Lambda) or when SEND_CW_METRICS environment variable is set. * The client is configured with maxAttempts: 1 to prevent retries * and reduce latency under high load. * * @private * @returns {CloudWatchClient|null} The CloudWatch client, or null if not sending metrics */ private _setup; /** * Convert InputMetric to MetricDatum format * * @private * @param metric - Input metric to convert * @param defaultTimestamp - Default timestamp to use if not provided * @returns Converted metric datum */ private _convertToMetricDatum; /** * Send metrics to CloudWatch using putMetricData. * * Errors are caught and logged but not re-thrown. If the client * is null (local environment without SEND_CW_METRICS), this method * returns immediately without sending. * * @private * @param cw - CloudWatch client (may be null) * @param metrics - Array of MetricDatum to send * @returns Promise that resolves when the send operation completes (or immediately if client is null) */ private _putMetricData; /** * Batch and send metrics. Handles batching into groups of 20 (CloudWatch limit) * and sends them asynchronously (fire and forget). Errors are logged but not raised. * * @private * @param metrics - Array of metrics to send */ private _sendBatchedMetrics; /** * Send any queued metrics. Returns a Promise that resolves immediately * after starting the send operations (fire and forget). Errors are logged * but not raised. The queue is cleared before sending begins. * * @returns Promise that resolves immediately after starting send operations */ flush(): Promise; /** * Add one or more custom metric values to the queue of those waiting * to be sent, or send them immediately. This function supports simple * name-and-value metrics. It doesn't support more complex CloudWatch types. * * A metric is an object with at least 'name' (string) and optionally 'value' * (number, defaults to 0). It may also optionally include 'timestamp' * (defaults to the time of the call to send()), and 'unit', which * must be one of Seconds, Microseconds, Milliseconds, Bytes, Kilobytes, * Megabytes, Gigabytes, Terabytes, Bits, Kilobits, Megabits, Gigabits, * Terabits, Percent, Count, Bytes/Second, Kilobytes/Second, * Megabytes/Second, Gigabytes/Second, Terabytes/Second, * Bits/Second, Kilobits/Second, Megabits/Second, Gigabits/Second, * Terabits/Second, Count/Second or None (defaults to 'Count'). * There may also be a 'dimensions' * object, which has dimension names as keys and dimension * values as values. Empty or falsy dimension values are filtered out. * * In a local development environment, metrics are queued but not sent * unless the SEND_CW_METRICS environment variable is set. This allows * for testing metric sending behavior locally. * * The metrics are added to an internal queue so that they can be * batched up to send more efficiently. They are only sent when * flush() is called, unless immediate is true. * * @private * @param metrics - Array of InputMetric objects to send * @param immediate - If true, send metrics immediately instead of queuing (default: false) */ send(metrics: InputMetric[], immediate?: boolean): void; /** * Get the singleton MetricsSender instance. * * Creates a new instance if one doesn't exist, otherwise returns * the existing instance. * * @returns The singleton MetricsSender instance */ static getSender(): MetricsSender; } export {};