import * as Duration from "../Duration.ts"; import * as Effect from "../Effect.ts"; import type * as Headers from "../http/Headers.ts"; import type * as HttpClient from "../http/HttpClient.ts"; import * as Layer from "../Layer.ts"; import type * as Scope from "../Scope.ts"; import * as Exporter from "./OtlpExporter.ts"; import type { Fixed64, KeyValue } from "./OtlpResource.ts"; import * as OtlpResource from "./OtlpResource.ts"; import { OtlpSerialization } from "./OtlpSerialization.ts"; /** * Determines how metric values relate to the time interval over which they are aggregated. * * **Details** * * `"cumulative"` reports total since a fixed start time. Each data point depends on all previous measurements. This is the default behavior. * * `"delta"` reports changes since the last export. Each interval is independent with no dependency on previous measurements. * * Summaries are always cumulative, regardless of this setting. * * **Example** (Configuring aggregation temporality) * * ```ts import.meta.vitest * import { Layer } from "effect" * import { OtlpMetrics } from "effect/observability" * * // Use delta temporality for backends that prefer it (e.g., Datadog, Dynatrace) * const metricsLayer = OtlpMetrics.layer({ * url: "http://localhost:4318/v1/metrics", * temporality: "delta" * }) * * // Use cumulative temporality for backends like Prometheus * const cumulativeLayer = OtlpMetrics.layer({ * url: "http://localhost:4318/v1/metrics", * temporality: "cumulative" // This is the default * }) * * const result = [Layer.isLayer(metricsLayer), Layer.isLayer(cumulativeLayer)] // => [true, true] * ``` * * @stability unstable * @category models * @since 4.0.0 */ export type AggregationTemporality = "cumulative" | "delta"; /** * Starts a scoped OTLP metrics exporter. * * **Details** * * The exporter snapshots registered Effect metrics on the configured interval, serializes them with the selected aggregation temporality, and flushes during scope finalization up to `shutdownTimeout`. * Manual flushing also triggers a snapshot. With delta temporality, each * successful export advances the previous-export state, so frequent successful * flushes narrow the delta aggregation windows. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const make: (options: { readonly url: string; readonly resource?: { readonly serviceName?: string | undefined; readonly serviceVersion?: string | undefined; readonly attributes?: Record; } | undefined; readonly headers?: Headers.Input | undefined; /** * Request compression. Defaults to "none". Gzip uses * HttpClientRequest's default minimum body size of 1KB. */ readonly compression?: "gzip" | "none" | undefined; readonly exportInterval?: Duration.Input | undefined; readonly shutdownTimeout?: Duration.Input | undefined; readonly temporality?: AggregationTemporality | undefined; }) => Effect.Effect; /** * Layer that starts the OTLP metrics exporter created by `make`. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layer: (options: { readonly url: string; readonly resource?: { readonly serviceName?: string | undefined; readonly serviceVersion?: string | undefined; readonly attributes?: Record; } | undefined; readonly headers?: Headers.Input | undefined; /** * Request compression. Defaults to "none". Gzip uses * HttpClientRequest's default minimum body size of 1KB. */ readonly compression?: "gzip" | "none" | undefined; readonly exportInterval?: Duration.Input | undefined; readonly shutdownTimeout?: Duration.Input | undefined; readonly temporality?: AggregationTemporality | undefined; }) => Layer.Layer; /** * Creates an OTLP metrics layer from OpenTelemetry configuration. * * **Details** * * Compression accepts "gzip" or "none". * `OTEL_EXPORTER_OTLP_METRICS_COMPRESSION` takes precedence over * `OTEL_EXPORTER_OTLP_COMPRESSION`, defaulting to "none". Gzip uses * HttpClientRequest's default minimum body size of 1KB. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerFromConfig: (options?: { readonly resource?: { readonly serviceName?: string | undefined; readonly serviceVersion?: string | undefined; readonly attributes?: Record; } | undefined; readonly headers?: Headers.Input | undefined; }) => Layer.Layer; /** * OTLP metrics payload serialized by `OtlpMetrics`. * * @stability unstable * @category models * @since 4.0.0 */ export interface MetricsData { readonly resourceMetrics: ReadonlyArray; } /** Properties of an InstrumentationScope. */ interface IInstrumentationScope { /** InstrumentationScope name */ name: string; /** InstrumentationScope version */ version?: string; /** InstrumentationScope attributes */ attributes?: Array; /** InstrumentationScope droppedAttributesCount */ droppedAttributesCount?: number; } /** Properties of a ResourceMetrics. */ interface IResourceMetrics { /** ResourceMetrics resource */ resource: OtlpResource.Resource; /** ResourceMetrics scopeMetrics */ scopeMetrics: Array; /** ResourceMetrics schemaUrl */ schemaUrl?: string | undefined; } /** Properties of an IScopeMetrics. */ interface IScopeMetrics { /** ScopeMetrics scope */ scope: IInstrumentationScope; /** ScopeMetrics metrics */ metrics: Array; /** ScopeMetrics schemaUrl */ schemaUrl?: string | undefined; } /** Properties of a Metric. */ interface IMetric { /** Metric name */ name: string; /** Metric description */ description?: string; /** Metric unit */ unit?: string; /** Metric gauge */ gauge?: IGauge; /** Metric sum */ sum?: ISum; /** Metric histogram */ histogram?: IHistogram; /** Metric exponentialHistogram */ exponentialHistogram?: IExponentialHistogram; /** Metric summary */ summary?: ISummary; } /** Properties of a Gauge. */ interface IGauge { /** Gauge dataPoints */ dataPoints: Array; } /** Properties of a Sum. */ interface ISum { /** Sum dataPoints */ dataPoints: Array; /** Sum aggregationTemporality */ aggregationTemporality: EAggregationTemporality; /** Sum isMonotonic */ isMonotonic: boolean; } /** Properties of a Histogram. */ interface IHistogram { /** Histogram dataPoints */ dataPoints: Array; /** Histogram aggregationTemporality */ aggregationTemporality?: EAggregationTemporality; } /** Properties of an ExponentialHistogram. */ interface IExponentialHistogram { /** ExponentialHistogram dataPoints */ dataPoints: Array; /** ExponentialHistogram aggregationTemporality */ aggregationTemporality?: EAggregationTemporality; } /** Properties of a Summary. */ interface ISummary { /** Summary dataPoints */ dataPoints: Array; } /** Properties of a NumberDataPoint. */ interface INumberDataPoint { /** NumberDataPoint attributes */ attributes: Array; /** NumberDataPoint startTimeUnixNano */ startTimeUnixNano?: Fixed64; /** NumberDataPoint timeUnixNano */ timeUnixNano?: Fixed64; /** NumberDataPoint asDouble */ asDouble?: number | null; /** NumberDataPoint asInt */ asInt?: number | string; /** NumberDataPoint exemplars */ exemplars?: Array; /** NumberDataPoint flags */ flags?: number; } /** Properties of a HistogramDataPoint. */ interface IHistogramDataPoint { /** HistogramDataPoint attributes */ attributes?: Array; /** HistogramDataPoint startTimeUnixNano */ startTimeUnixNano?: Fixed64; /** HistogramDataPoint timeUnixNano */ timeUnixNano?: Fixed64; /** HistogramDataPoint count */ count?: number; /** HistogramDataPoint sum */ sum?: number; /** HistogramDataPoint bucketCounts */ bucketCounts?: Array; /** HistogramDataPoint explicitBounds */ explicitBounds?: Array; /** HistogramDataPoint exemplars */ exemplars?: Array; /** HistogramDataPoint flags */ flags?: number; /** HistogramDataPoint min */ min?: number; /** HistogramDataPoint max */ max?: number; } /** Properties of an ExponentialHistogramDataPoint. */ interface IExponentialHistogramDataPoint { /** ExponentialHistogramDataPoint attributes */ attributes?: Array; /** ExponentialHistogramDataPoint startTimeUnixNano */ startTimeUnixNano?: Fixed64; /** ExponentialHistogramDataPoint timeUnixNano */ timeUnixNano?: Fixed64; /** ExponentialHistogramDataPoint count */ count?: number; /** ExponentialHistogramDataPoint sum */ sum?: number; /** ExponentialHistogramDataPoint scale */ scale?: number; /** ExponentialHistogramDataPoint zeroCount */ zeroCount?: number; /** ExponentialHistogramDataPoint positive */ positive?: IBuckets; /** ExponentialHistogramDataPoint negative */ negative?: IBuckets; /** ExponentialHistogramDataPoint flags */ flags?: number; /** ExponentialHistogramDataPoint exemplars */ exemplars?: Array; /** ExponentialHistogramDataPoint min */ min?: number; /** ExponentialHistogramDataPoint max */ max?: number; } /** Properties of a SummaryDataPoint. */ interface ISummaryDataPoint { /** SummaryDataPoint attributes */ attributes?: Array; /** SummaryDataPoint startTimeUnixNano */ startTimeUnixNano?: Fixed64; /** SummaryDataPoint timeUnixNano */ timeUnixNano?: Fixed64; /** SummaryDataPoint count */ count?: number; /** SummaryDataPoint sum */ sum?: number; /** SummaryDataPoint quantileValues */ quantileValues?: Array; /** SummaryDataPoint flags */ flags?: number; } /** Properties of a ValueAtQuantile. */ interface IValueAtQuantile { /** ValueAtQuantile quantile */ quantile?: number; /** ValueAtQuantile value */ value?: number; } /** Properties of a Buckets. */ interface IBuckets { /** Buckets offset */ offset?: number; /** Buckets bucketCounts */ bucketCounts?: Array; } /** Properties of an Exemplar. */ interface IExemplar { /** Exemplar filteredAttributes */ filteredAttributes?: Array; /** Exemplar timeUnixNano */ timeUnixNano?: string; /** Exemplar asDouble */ asDouble?: number; /** Exemplar asInt */ asInt?: number; /** Exemplar spanId */ spanId?: string | Uint8Array; /** Exemplar traceId */ traceId?: string | Uint8Array; } /** * AggregationTemporality defines how a metric aggregator reports aggregated * values. It describes how those values relate to the time interval over * which they are aggregated. */ declare const EAggregationTemporality: { readonly AGGREGATION_TEMPORALITY_UNSPECIFIED: 0; /** DELTA is an AggregationTemporality for a metric aggregator which reports changes since last report time. Successive metrics contain aggregation of values from continuous and non-overlapping intervals. The values for a DELTA metric are based only on the time interval associated with one measurement cycle. There is no dependency on previous measurements like is the case for CUMULATIVE metrics. For example, consider a system measuring the number of requests that it receives and reports the sum of these requests every second as a DELTA metric: 1. The system starts receiving at time=t_0. 2. A request is received, the system measures 1 request. 3. A request is received, the system measures 1 request. 4. A request is received, the system measures 1 request. 5. The 1 second collection cycle ends. A metric is exported for the number of requests received over the interval of time t_0 to t_0+1 with a value of 3. 6. A request is received, the system measures 1 request. 7. A request is received, the system measures 1 request. 8. The 1 second collection cycle ends. A metric is exported for the number of requests received over the interval of time t_0+1 to t_0+2 with a value of 2. */ readonly AGGREGATION_TEMPORALITY_DELTA: 1; /** CUMULATIVE is an AggregationTemporality for a metric aggregator which reports changes since a fixed start time. This means that current values of a CUMULATIVE metric depend on all previous measurements since the start time. Because of this, the sender is required to retain this state in some form. If this state is lost or invalidated, the CUMULATIVE metric values MUST be reset and a new fixed start time following the last reported measurement time sent MUST be used. For example, consider a system measuring the number of requests that it receives and reports the sum of these requests every second as a CUMULATIVE metric: 1. The system starts receiving at time=t_0. 2. A request is received, the system measures 1 request. 3. A request is received, the system measures 1 request. 4. A request is received, the system measures 1 request. 5. The 1 second collection cycle ends. A metric is exported for the number of requests received over the interval of time t_0 to t_0+1 with a value of 3. 6. A request is received, the system measures 1 request. 7. A request is received, the system measures 1 request. 8. The 1 second collection cycle ends. A metric is exported for the number of requests received over the interval of time t_0 to t_0+2 with a value of 5. 9. The system experiences a fault and loses state. 10. The system recovers and resumes receiving at time=t_1. 11. A request is received, the system measures 1 request. 12. The 1 second collection cycle ends. A metric is exported for the number of requests received over the interval of time t_1 to t_0+1 with a value of 1. Note: Even though, when reporting changes since last report time, using CUMULATIVE is valid, it is not recommended. This may cause problems for systems that do not use start_time to determine when the aggregation value was reset (e.g. Prometheus). */ readonly AGGREGATION_TEMPORALITY_CUMULATIVE: 2; }; type EAggregationTemporality = typeof EAggregationTemporality[keyof typeof EAggregationTemporality]; export {}; //# sourceMappingURL=OtlpMetrics.d.ts.map