import type { HistogramBoundaries, HistogramBoundariesOps } from "@effect/core/io/Metrics/Boundaries" export const MetricSym = Symbol.for("@effect/core/io/Metric") export type MetricSym = typeof MetricSym /** * A `Metric` represents a concurrent metric which accepts * updates of type `In` and are aggregated to a stateful value of type `Out`. * * For example, a counter metric would have type `Metric`, * representing the fact that the metric can be updated with numbers (the amount * to increment or decrement the counter by), and the state of the counter is a * number. * * There are five primitive metric types supported by Effect: * * - Counters * - Frequencies * - Gauges * - Histograms * - Summaries * * @tsplus type effect/core/io/Metrics/Metric */ export interface Metric { readonly [MetricSym]: MetricSym readonly keyType: Type readonly unsafeUpdate: (input: In, extraTags: HashSet) => void readonly unsafeValue: (extraTags: HashSet) => Out (effect: Effect): Effect } /** * @tsplus type effect/core/io/Metrics/Metric.Ops */ export interface MetricOps { /** * The type of the underlying primitive metric. For example, this could be * `MetricKeyType.Counter` or `MetricKeyType.Gauge`. */ ( keyType: Type, unsafeUpdate: (input: In, extraTags: HashSet) => void, unsafeValue: (extraTags: HashSet) => Out ): Metric } export const Metric: MetricOps = function( keyType: Type, unsafeUpdate: (input: In, extraTags: HashSet) => void, unsafeValue: (extraTags: HashSet) => Out ): Metric { const metric: Metric = Object.assign( (effect: Effect): Effect => effect.tap((a) => Effect.sync(unsafeUpdate(a, HashSet.empty()))), { [MetricSym]: MetricSym, keyType, unsafeUpdate, unsafeValue } as const ) return metric } export declare namespace Metric { export interface Counter extends Metric {} export interface Gauge extends Metric {} export interface Frequency extends Metric {} export interface Histogram extends Metric {} export interface Summary extends Metric {} export namespace Histogram { export type Boundaries = HistogramBoundaries } } /** * @tsplus static effect/core/io/Metrics/Metric.Ops $ */ export const metricAspects: MetricAspects = {} /** * @tsplus static effect/core/io/Metrics/Metric.Ops Histogram */ export const histogramBoundaries: { readonly Boundaries: HistogramBoundariesOps } = { Boundaries: {} } /** * @tsplus type effect/core/io/Metrics/Metric.Aspects */ export interface MetricAspects {}