Context.Reference<Map<string, Metric.Metadata<any, any>>>Context reference for the metric registry in the current context.
When to use
Use when you need a custom metric registry for an isolated program or test instead of the default registry.
Details
By default, the reference creates an empty Map the first time it is
resolved. Metrics register their metadata and hooks lazily in this map when
they are read or updated.
Gotchas
Because Context.Reference caches default values, the default Map is
shared by contexts that do not provide an override. Provide MetricRegistry
with a fresh Map when isolation matters.
export const const MetricRegistry: Context.Reference<
Map<string, Metric.Metadata<any, any>>
>
const MetricRegistry: {
key: string;
Service: {
clear: () => void;
delete: (key: string) => boolean;
forEach: (callbackfn: (value: Metric.Metadata<any, any>, key: string, map: Map<string, Metric.Metadata<any, any>>) => void, thisArg?: any) => void;
get: (key: string) => Metric.Metadata<any, any> | undefined;
has: (key: string) => boolean;
set: (key: string, value: Metric.Metadata<any, any>) => Map<string, Metric.Metadata<any, any>>;
size: number;
entries: () => MapIterator<[string, Metric.Metadata<any, any>]>;
keys: () => MapIterator<string>;
values: () => MapIterator<Metric.Metadata<any, any>>;
};
defaultValue: () => Shape;
of: (this: void, self: Map<string, Metric.Metadata<any, any>>) => Map<string, Metric.Metadata<any, any>>;
context: (self: Map<string, Metric.Metadata<any, any>>) => Context.Context<never>;
use: (f: (service: Map<string, Metric.Metadata<any, any>>) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: Map<string, Metric.Metadata<any, any>>) => A) => Effect<A, never, never>;
Identifier: Identifier;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
Context reference for the metric registry in the current context.
When to use
Use when you need a custom metric registry for an isolated program or test
instead of the default registry.
Details
By default, the reference creates an empty Map the first time it is
resolved. Metrics register their metadata and hooks lazily in this map when
they are read or updated.
Gotchas
Because Context.Reference caches default values, the default Map is
shared by contexts that do not provide an override. Provide MetricRegistry
with a fresh Map when isolation matters.
MetricRegistry = import ContextContext.Reference<interface Map<K, V>Map<string, Metric.interface Metric<in Input, out State>.Metadata<in Input, out State>Interface containing complete metadata information about a metric.
Example (Inspecting metric metadata)
import { Data, Effect, Metric } from "effect"
class MetadataError extends Data.TaggedError("MetadataError")<{
readonly operation: string
}> {}
const program = Effect.gen(function*() {
// Create metrics with different configurations
const requestCounter = Metric.counter("http_requests_total", {
description: "Total number of HTTP requests",
attributes: { service: "api", version: "1.0" }
})
const memoryGauge = Metric.gauge("memory_usage_bytes", {
description: "Current memory usage in bytes"
})
const statusFrequency = Metric.frequency("http_status_codes")
// The Metadata interface contains complete information about a metric:
// - id: metric identifier
// - type: metric type ("Counter", "Gauge", etc.)
// - description: optional description
// - attributes: optional key-value attributes
// - hooks: low-level operations interface
// Each metric has associated metadata that can be inspected
yield* Metric.update(requestCounter, 10)
yield* Metric.update(memoryGauge, 256000000)
yield* Metric.update(statusFrequency, "200")
return {
counter: {
id: requestCounter.id, // "http_requests_total"
type: requestCounter.type, // "Counter"
description: requestCounter.description // "Total number of HTTP requests"
},
gauge: {
id: memoryGauge.id, // "memory_usage_bytes"
type: memoryGauge.type, // "Gauge"
description: memoryGauge.description // "Current memory usage in bytes"
},
frequency: {
id: statusFrequency.id, // "http_status_codes"
type: statusFrequency.type, // "Frequency"
description: statusFrequency.description // undefined
}
}
})
Metadata<any, any>>>(
const MetricRegistryKey: "~effect/observability/Metric/MetricRegistryKey"MetricRegistryKey,
{ defaultValue: () => Map<any, any>defaultValue: () => new var Map: MapConstructor
new () => Map<any, any> (+3 overloads)
Map() }
)