Context.Reference<ReadonlyRecord<string, unknown>>Context reference for managing log annotations that are automatically added to all log entries. These annotations provide contextual metadata that appears in every log message.
When to use
Use to attach shared contextual metadata to every log entry emitted in the current context.
Example (Managing log annotations)
import { Console, Effect, References } from "effect"
const logAnnotationExample = Effect.gen(function*() {
// Get current annotations (empty by default)
const current = yield* References.CurrentLogAnnotations
console.log(current) // {}
// Run with custom log annotations
yield* Effect.provideService(
Effect.gen(function*() {
const annotations = yield* References.CurrentLogAnnotations
console.log(annotations) // { requestId: "req-123", userId: "user-456", version: "1.0.0" }
// All log entries will include these annotations
yield* Console.log("Starting operation")
yield* Console.info("Processing data")
}),
References.CurrentLogAnnotations,
{
requestId: "req-123",
userId: "user-456",
version: "1.0.0"
}
)
// Run with extended annotations
yield* Effect.provideService(
Effect.gen(function*() {
const extended = yield* References.CurrentLogAnnotations
console.log(extended) // { requestId: "req-123", userId: "user-456", version: "1.0.0", operation: "data-sync", timestamp: 1234567890 }
yield* Console.log("Operation completed with extended context")
}),
References.CurrentLogAnnotations,
{
requestId: "req-123",
userId: "user-456",
version: "1.0.0",
operation: "data-sync",
timestamp: 1234567890
}
)
})references
Source effect/References.ts:2332 lines
export const const CurrentLogAnnotations: Context.Reference<
ReadonlyRecord<string, unknown>
>
const CurrentLogAnnotations: {
defaultValue: () => Shape;
of: (this: void, self: ReadonlyRecord<string, unknown>) => ReadonlyRecord<string, unknown>;
context: (self: ReadonlyRecord<string, unknown>) => Context.Context<never>;
use: (f: (service: ReadonlyRecord<string, unknown>) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: ReadonlyRecord<string, unknown>) => 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 managing log annotations that are automatically added to all log entries.
These annotations provide contextual metadata that appears in every log message.
When to use
Use to attach shared contextual metadata to every log entry emitted in the
current context.
Example (Managing log annotations)
import { Console, Effect, References } from "effect"
const logAnnotationExample = Effect.gen(function*() {
// Get current annotations (empty by default)
const current = yield* References.CurrentLogAnnotations
console.log(current) // {}
// Run with custom log annotations
yield* Effect.provideService(
Effect.gen(function*() {
const annotations = yield* References.CurrentLogAnnotations
console.log(annotations) // { requestId: "req-123", userId: "user-456", version: "1.0.0" }
// All log entries will include these annotations
yield* Console.log("Starting operation")
yield* Console.info("Processing data")
}),
References.CurrentLogAnnotations,
{
requestId: "req-123",
userId: "user-456",
version: "1.0.0"
}
)
// Run with extended annotations
yield* Effect.provideService(
Effect.gen(function*() {
const extended = yield* References.CurrentLogAnnotations
console.log(extended) // { requestId: "req-123", userId: "user-456", version: "1.0.0", operation: "data-sync", timestamp: 1234567890 }
yield* Console.log("Operation completed with extended context")
}),
References.CurrentLogAnnotations,
{
requestId: "req-123",
userId: "user-456",
version: "1.0.0",
operation: "data-sync",
timestamp: 1234567890
}
)
})
CurrentLogAnnotations: import ContextContext.type Context.Reference = /*unresolved*/ anyReference<import ReadonlyRecordReadonlyRecord<string, unknown>> =
import referencesreferences.const CurrentLogAnnotations: Context.Reference<
ReadonlyRecord<string, unknown>
>
const CurrentLogAnnotations: {
defaultValue: () => Shape;
of: (this: void, self: ReadonlyRecord<string, unknown>) => ReadonlyRecord<string, unknown>;
context: (self: ReadonlyRecord<string, unknown>) => Context.Context<never>;
use: (f: (service: ReadonlyRecord<string, unknown>) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: ReadonlyRecord<string, unknown>) => 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;
}
CurrentLogAnnotationsReferenced by 2 symbols