Context.Reference<FiberRuntimeMetricsService | undefined>Context reference for the optional service that records fiber runtime metrics.
When to use
Use to provide or inspect the service that receives fiber start and end notifications for automatic runtime metrics.
Details
When provided, the runtime can notify the service about child-fiber start and
end events. When the reference is undefined, automatic fiber runtime metric
collection is disabled.
Example (Accessing the fiber runtime metrics service)
import { Data, Effect, Metric } from "effect"
class MetricsError extends Data.TaggedError("MetricsError")<{
readonly operation: string
}> {}
const program = Effect.gen(function*() {
// Access the fiber runtime metrics service
const metricsService = yield* Metric.FiberRuntimeMetrics
if (metricsService) {
console.log("Runtime metrics are enabled")
} else {
console.log("Runtime metrics are disabled")
}
// Enable runtime metrics for the application
const enabledLayer = Metric.enableRuntimeMetricsLayer
return yield* Effect.gen(function*() {
// Create some concurrent fibers to see metrics in action
yield* Effect.all([
Effect.sleep("100 millis"),
Effect.sleep("200 millis"),
Effect.sleep("300 millis")
], { concurrency: "unbounded" })
// Create test metrics to demonstrate the service
const testCounter = Metric.counter("test_counter")
yield* Metric.update(testCounter, 5)
const counterValue = yield* Metric.value(testCounter)
return { counterValue, metricsEnabled: true }
}).pipe(Effect.provide(enabledLayer))
})export const const FiberRuntimeMetrics: Context.Reference<
FiberRuntimeMetricsService | undefined
>
const FiberRuntimeMetrics: {
defaultValue: () => Shape;
of: (this: void, self: FiberRuntimeMetricsService | undefined) => FiberRuntimeMetricsService | undefined;
context: (self: FiberRuntimeMetricsService | undefined) => Context.Context<never>;
use: (f: (service: FiberRuntimeMetricsService | undefined) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: FiberRuntimeMetricsService | undefined) => A) => Effect<A, never, never>;
Identifier: Identifier;
Service: Shape;
key: string;
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 optional service that records fiber runtime
metrics.
When to use
Use to provide or inspect the service that receives fiber start and end
notifications for automatic runtime metrics.
Details
When provided, the runtime can notify the service about child-fiber start and
end events. When the reference is undefined, automatic fiber runtime metric
collection is disabled.
Example (Accessing the fiber runtime metrics service)
import { Data, Effect, Metric } from "effect"
class MetricsError extends Data.TaggedError("MetricsError")<{
readonly operation: string
}> {}
const program = Effect.gen(function*() {
// Access the fiber runtime metrics service
const metricsService = yield* Metric.FiberRuntimeMetrics
if (metricsService) {
console.log("Runtime metrics are enabled")
} else {
console.log("Runtime metrics are disabled")
}
// Enable runtime metrics for the application
const enabledLayer = Metric.enableRuntimeMetricsLayer
return yield* Effect.gen(function*() {
// Create some concurrent fibers to see metrics in action
yield* Effect.all([
Effect.sleep("100 millis"),
Effect.sleep("200 millis"),
Effect.sleep("300 millis")
], { concurrency: "unbounded" })
// Create test metrics to demonstrate the service
const testCounter = Metric.counter("test_counter")
yield* Metric.update(testCounter, 5)
const counterValue = yield* Metric.value(testCounter)
return { counterValue, metricsEnabled: true }
}).pipe(Effect.provide(enabledLayer))
})
FiberRuntimeMetrics = import ContextContext.Reference<FiberRuntimeMetricsService | undefined>(
import InternalMetricInternalMetric.const FiberRuntimeMetricsKey: "effect/observability/Metric/FiberRuntimeMetricsKey"FiberRuntimeMetricsKey,
{ defaultValue: LazyArg<undefined>defaultValue: import constUndefinedconstUndefined }
)