UNPKG

enhanced-adot-node-autoinstrumentation

Version:

This package provides Amazon Web Services distribution of the OpenTelemetry Node Instrumentation, which allows for auto-instrumentation of NodeJS applications.

234 lines 8.19 kB
import { CloudWatchLogsClientConfig } from '@aws-sdk/client-cloudwatch-logs'; import { Aggregation, AggregationTemporality, InstrumentType, PushMetricExporter, ResourceMetrics } from '@opentelemetry/sdk-metrics'; import { ExportResult } from '@opentelemetry/core'; /** * OpenTelemetry metrics exporter for CloudWatch EMF format. * * This exporter converts OTel metrics into CloudWatch EMF logs which are then * sent to CloudWatch Logs. CloudWatch Logs automatically extracts the metrics * from the EMF logs. */ export declare class AWSCloudWatchEMFExporter implements PushMetricExporter { private namespace; private logGroupName; private logStreamName; private aggregationTemporality; private logsClient; private logStreamExists; private logStreamExistsPromise; private eventBatch; private EMF_SUPPORTED_UNITS; private UNIT_MAPPING; /** * Initialize the CloudWatch EMF exporter. * * @param namespace CloudWatch namespace for metrics * @param logGroupName CloudWatch log group name * @param logStreamName Optional CloudWatch log stream name (auto-generated if not provided) * @param AggregationTemporality Optional AggregationTemporality to indicate the way additive quantities are expressed * @param cloudwatchLogsConfig Optional CloudWatch Logs Client Configuration. Configure region here if needed explicitly. */ constructor(namespace: string | undefined, logGroupName: string, logStreamName?: string, aggregationTemporality?: AggregationTemporality, cloudwatchLogsConfig?: CloudWatchLogsClientConfig); /** * Generate a unique log stream name. * * @returns {string} */ private generateLogStreamName; /** * Ensure the log group exists, create if it doesn't. */ private ensureLogGroupExists; /** * Ensure the log stream exists, create if it doesn't. */ private ensureLogStreamExists; /** * Get CloudWatch unit from unit in MetricRecord * * @param record Metric Record * @returns {string | undefined} */ private getUnit; /** * Extract dimension names from attributes. * For now, use all attributes as dimensions for the dimension selection logic. * * @param attributes OpenTelemetry Attributes to extract Dimension Names from * @returns {string[]} */ private getDimensionNames; /** * Create a hashable key from attributes for grouping metrics. * * @param attributes OpenTelemetry Attributes used to create an attributes key * @returns {string} */ private getAttributesKey; /** * Normalize an OpenTelemetry timestamp to milliseconds for CloudWatch. * * @param hrTime Datapoint timestamp * @returns {number} Timestamp in milliseconds */ private normalizeTimestamp; /** * Create a base metric record with instrument information. * * @param metricName Name of the metric * @param metricUnit Unit of the metric * @param metricDescription Description of the metric * @param timestamp Normalized end epoch timestamp when metric data was collected * @param attributes Attributes of the metric data * @returns {MetricRecord} */ private createMetricRecord; /** * Convert a Gauge metric datapoint to a metric record. * * @param metric Gauge Metric Data * @param dataPoint The datapoint to convert * @returns {MetricRecord} */ private convertGauge; /** * Convert a Sum metric datapoint to a metric record. * * @param metric The metric object * @param dataPoint The datapoint to convert * @returns {MetricRecord} */ private convertSum; /** * Convert a Histogram metric datapoint to a metric record. * * @param metric The metric object * @param dataPoint The datapoint to convert * @returns {MetricRecord} */ private convertHistogram; /** * Convert an ExponentialHistogram metric datapoint to a metric record. * This function follows the logic of CalculateDeltaDatapoints in the Go implementation, * converting exponential buckets to their midpoint values. * * @param metric The metric object * @param dataPoint The datapoint to convert * @returns {MetricRecord} */ private convertExpHistogram; /** * Group metric record by attributes and timestamp. * * @param record The metric record * @param timestampMs The timestamp in milliseconds * @returns {[string, number]} Values for the key to group metrics */ private groupByAttributesAndTimestamp; /** * Create EMF log from metric records. * metricRecords is already grouped by attributes, so this * function creates a single EMF Log for these records. * * @param metricRecords List of MetricRecords * @param resource * @param timestamp * @returns {EMFLog} */ private createEmfLog; /** * Method to handle safely pushing a MetricRecord into a Map of a Map of a list of MetricRecords * * @param groupedMetrics * @param groupAttribute * @param groupTimestamp * @param record */ private pushMetricRecordIntoGroupedMetrics; /** * Export metrics as EMF logs to CloudWatch. * Groups metrics by attributes and timestamp before creating EMF logs. * * @param resourceMetrics Resource Metrics data containing scope metrics * @param resultCallback callback for when the export has completed * @returns {Promise<void>} */ export(resourceMetrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): Promise<void>; /** * Validate the log event according to CloudWatch Logs constraints. * Implements the same validation logic as the Go version. * * @param logEvent The log event to validate * @returns {boolean} */ private validateLogEvent; /** * Create a new log event batch * * @returns {EventBatch} */ private createEventBatch; /** * Check if adding the next event would exceed CloudWatch Logs limits. * * @param batch The current batch * @param nextEventSize Size of the next event in bytes CW_MAX_REQUEST_EVENT_COUNT * @returns {boolean} true if adding the next event would exceed limits */ private eventBatchExceedsLimit; /** * Check if the event batch spans more than 24 hours. * * @param batch The event batch * @param targetTimestampMs The timestamp of the event to add * @returns {boolean} true if the batch is active and can accept the event */ private isBatchActive; /** * Append a log event to the batch. * * @param batch The event batch * @param logEvent The log event to append * @param eventSize Size of the event in bytes */ private appendToBatch; /** * Sort log events in the batch by timestamp. * * @param batch The event batch */ private sortLogEvents; /** * Send a batch of log events to CloudWatch Logs. * * @param batch The event batch * @returns {Promise<void>} */ private sendLogBatch; /** * Send a log event to CloudWatch Logs. * * This function implements the same logic as the Go version in the OTel Collector. * It batches log events according to CloudWatch Logs constraints and sends them * when the batch is full or spans more than 24 hours. * * @param logEvent The log event to send * @returns {Promise<void>} */ private sendLogEvent; /** * Force flush any pending metrics. * * @param timeoutMillis Timeout in milliseconds */ forceFlush(timeoutMillis?: number): Promise<void>; /** * Shutdown the exporter after force flush. * * @returns {Promise<void>} */ shutdown(): Promise<void>; selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality; selectAggregation(instrumentType: InstrumentType): Aggregation; } //# sourceMappingURL=otlp-aws-emf-exporter.d.ts.map