Hyperlinkv0.8.0-beta.28

Effect

Effect.annotateLogsScopedconsteffect/Effect.ts:14109
(key: string, value: unknown): Effect<void, never, Scope>
(values: Record<string, unknown>): Effect<void, never, Scope>

Adds log annotations to the current scope.

When to use

Use to attach log annotations that last until the current scope closes.

Details

This differs from annotateLogs, which only annotates a specific effect. annotateLogsScoped updates annotations for the entire current Scope and restores the previous annotations when the scope closes.

Example (Adding scoped log annotations)

import { Effect } from "effect"

const program = Effect.scoped(
  Effect.gen(function*() {
    yield* Effect.log("before")
    yield* Effect.annotateLogsScoped({ requestId: "req-123" })
    yield* Effect.log("inside scope")
  })
)

Effect.runPromise(program)
export const annotateLogsScoped: {
  (key: string, value: unknown): Effect<void, never, Scope>
  (values: Record<string, unknown>): Effect<void, never, Scope>
} = internal.annotateLogsScoped