(options: {
readonly start: number
readonly factor: number
readonly count: number
}): ReadonlyArray<number>Creates histogram bucket boundaries with exponentially increasing values.
Details
Creates boundaries that grow exponentially, useful for metrics that span multiple orders of magnitude. Each boundary is calculated as start * factor^i.
Example (Creating exponential boundaries)
import { Data, Effect, Metric } from "effect"
class BoundaryError extends Data.TaggedError("BoundaryError")<{
readonly operation: string
}> {}
// Create exponential boundaries for request size histogram
// Buckets: 0-1KB, 1-2KB, 2-4KB, 4-8KB, 8KB+
const sizeBoundaries = Metric.exponentialBoundaries({
start: 1, // Starting at 1KB
factor: 2, // Each boundary doubles the previous
count: 5 // Creates 4 boundaries + infinity
})
console.log(sizeBoundaries) // [1, 2, 4, 8, Infinity]
// Create a histogram for tracking request payload sizes
const requestSizeHistogram = Metric.histogram("request_size_kb", {
description: "Request payload size distribution in KB",
boundaries: sizeBoundaries
})
// For very wide ranges, use larger factors
const latencyBoundaries = Metric.exponentialBoundaries({
start: 0.1, // Start at 0.1ms
factor: 10, // Each boundary is 10x larger
count: 6 // Creates ranges: 0.1ms, 1ms, 10ms, 100ms, 1000ms+
})
const program = Effect.gen(function*() {
// Record different request sizes
yield* Metric.update(requestSizeHistogram, 1.5) // Goes in 1-2KB bucket
yield* Metric.update(requestSizeHistogram, 3.2) // Goes in 2-4KB bucket
yield* Metric.update(requestSizeHistogram, 12) // Goes in 8KB+ bucket
const value = yield* Metric.value(requestSizeHistogram)
return value
})export const const exponentialBoundaries: (options: {
readonly start: number
readonly factor: number
readonly count: number
}) => ReadonlyArray<number>
Creates histogram bucket boundaries with exponentially increasing values.
Details
Creates boundaries that grow exponentially, useful for metrics that span
multiple orders of magnitude. Each boundary is calculated as start * factor^i.
Example (Creating exponential boundaries)
import { Data, Effect, Metric } from "effect"
class BoundaryError extends Data.TaggedError("BoundaryError")<{
readonly operation: string
}> {}
// Create exponential boundaries for request size histogram
// Buckets: 0-1KB, 1-2KB, 2-4KB, 4-8KB, 8KB+
const sizeBoundaries = Metric.exponentialBoundaries({
start: 1, // Starting at 1KB
factor: 2, // Each boundary doubles the previous
count: 5 // Creates 4 boundaries + infinity
})
console.log(sizeBoundaries) // [1, 2, 4, 8, Infinity]
// Create a histogram for tracking request payload sizes
const requestSizeHistogram = Metric.histogram("request_size_kb", {
description: "Request payload size distribution in KB",
boundaries: sizeBoundaries
})
// For very wide ranges, use larger factors
const latencyBoundaries = Metric.exponentialBoundaries({
start: 0.1, // Start at 0.1ms
factor: 10, // Each boundary is 10x larger
count: 6 // Creates ranges: 0.1ms, 1ms, 10ms, 100ms, 1000ms+
})
const program = Effect.gen(function*() {
// Record different request sizes
yield* Metric.update(requestSizeHistogram, 1.5) // Goes in 1-2KB bucket
yield* Metric.update(requestSizeHistogram, 3.2) // Goes in 2-4KB bucket
yield* Metric.update(requestSizeHistogram, 12) // Goes in 8KB+ bucket
const value = yield* Metric.value(requestSizeHistogram)
return value
})
exponentialBoundaries = (options: {
readonly start: number
readonly factor: number
readonly count: number
}
options: {
readonly start: numberstart: number
readonly factor: numberfactor: number
readonly count: numbercount: number
}): interface ReadonlyArray<T>ReadonlyArray<number> =>
const boundariesFromIterable: (
iterable: Iterable<number>
) => ReadonlyArray<number>
Creates histogram bucket boundaries from an iterable set of values.
Details
Processes any iterable of numbers by removing duplicates, filtering out
non-positive values, and automatically appending positive infinity as the
final boundary.
Example (Creating boundaries from values)
import { Data, Effect, Metric } from "effect"
class BoundaryError extends Data.TaggedError("BoundaryError")<{
readonly operation: string
}> {}
// Create boundaries from an array of custom values
const customBoundaries = Metric.boundariesFromIterable([
10,
25,
50,
100,
250,
500,
1000
])
console.log(customBoundaries) // [10, 25, 50, 100, 250, 500, 1000, Infinity]
// Automatically removes duplicates and negative values
const messyBoundaries = Metric.boundariesFromIterable([
-5,
0,
10,
10,
25,
25,
50,
-1
])
console.log(messyBoundaries) // [10, 25, 50, Infinity]
// Works with any iterable (Set, generator functions, etc.)
const setBoundaries = Metric.boundariesFromIterable(
new Set([100, 200, 300, 200, 100])
)
console.log(setBoundaries) // [100, 200, 300, Infinity]
// Use with histogram metric
const responseTimeHistogram = Metric.histogram("response_times", {
description: "API response time distribution",
boundaries: customBoundaries
})
const program = Effect.gen(function*() {
yield* Metric.update(responseTimeHistogram, 75) // Goes in 50-100ms bucket
yield* Metric.update(responseTimeHistogram, 150) // Goes in 100-250ms bucket
const value = yield* Metric.value(responseTimeHistogram)
return value
})
boundariesFromIterable(import ArrArr.makeBy(options: {
readonly start: number
readonly factor: number
readonly count: number
}
options.count: numbercount - 1, (i: anyi) => options: {
readonly start: number
readonly factor: number
readonly count: number
}
options.start: numberstart * var Math: MathAn intrinsic object that provides basic mathematics functionality and constants.
Math.Math.pow(x: number, y: number): numberReturns the value of a base expression taken to a specified power.
pow(options: {
readonly start: number
readonly factor: number
readonly count: number
}
options.factor: numberfactor, i: anyi)))