effect-io-ai

Package: effect
Module: Metric

Metric.summaryWithTimestamp

Creates a Summary metric that records observations with explicit timestamps and calculates quantiles.

When to use

Use when you need a metric that records statistical information about a set of values together with timestamps.

Details

Inputs to this metric are [value, timestamp] pairs; the current clock is used when reading quantiles against the configured maxAge.

The optional description describes the summary, and attributes attach dimensions to it. maxAge controls how long observations are retained, maxSize controls how many observations are kept, and quantiles lists the quantiles to calculate, such as [0.5, 0.9].

Example (Creating summaries with explicit timestamps)

import { Metric } from "effect"

const responseTimesSummary = Metric.summaryWithTimestamp(
  "response_times_summary",
  {
    description: "Measures the distribution of response times",
    maxAge: "60 seconds", // Retain observations for 60 seconds.
    maxSize: 1000, // Keep a maximum of 1000 observations.
    quantiles: [0.5, 0.9, 0.99] // Calculate 50th, 90th, and 99th quantiles.
  }
)

Signature

declare const summaryWithTimestamp: (name: string, options: { readonly description?: string | undefined; readonly attributes?: Metric.Attributes | undefined; readonly maxAge: Duration.Input; readonly maxSize: number; readonly quantiles: ReadonlyArray<number>; }) => Summary<[value: number, timestamp: number]>

Source

Since v4.0.0