Hyperlinkv0.8.0-beta.28

Effect

Effect.withLogSpanconsteffect/Effect.ts:14145
(label: string): <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, R>
<A, E, R>(effect: Effect<A, E, R>, label: string): Effect<A, E, R>

Adds a span to each log line in this effect.

Example (Adding a log span)

import { Effect } from "effect"

const databaseOperation = Effect.gen(function*() {
  yield* Effect.log("Connecting to database")
  yield* Effect.log("Executing query")
  yield* Effect.log("Processing results")
  return "data"
})

const httpRequest = Effect.gen(function*() {
  yield* Effect.log("Making HTTP request")
  const data = yield* Effect.withLogSpan(databaseOperation, "db-operation")
  yield* Effect.log("Sending response")
  return data
})

const program = Effect.withLogSpan(httpRequest, "http-handler")

Effect.runPromise(program)
// All log messages will include span information showing the nested operation context
logging
Source effect/Effect.ts:1414512 lines
export const withLogSpan = dual<
  (label: string) => <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, R>,
  <A, E, R>(effect: Effect<A, E, R>, label: string) => Effect<A, E, R>
>(
  2,
  (effect, label) =>
    internal.flatMap(internal.currentTimeMillis, (now) =>
      internal.updateService(effect, CurrentLogSpans, (spans) => {
        const span: [label: string, timestamp: number] = [label, now]
        return [span, ...spans]
      }))
)