Effect<AnySpan, Cause.NoSuchElementError, never>Returns the current parent span from the effect context.
Details
The effect succeeds with either a local span or external span when one is
present, and fails with NoSuchElementError when no parent span is
available.
Example (Reading the parent span)
import { Effect } from "effect"
const childOperation = Effect.gen(function*() {
const parentSpan = yield* Effect.currentParentSpan
yield* Effect.log(`Parent span: ${parentSpan}`)
return "child completed"
})
const program = Effect.gen(function*() {
yield* Effect.withSpan(childOperation, "child-span")
return "parent completed"
})
const traced = Effect.withSpan(program, "parent-span")export const const currentParentSpan: Effect<
AnySpan,
Cause.NoSuchElementError
>
const currentParentSpan: {
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;
}
Returns the current parent span from the effect context.
Details
The effect succeeds with either a local span or external span when one is
present, and fails with NoSuchElementError when no parent span is
available.
Example (Reading the parent span)
import { Effect } from "effect"
const childOperation = Effect.gen(function*() {
const parentSpan = yield* Effect.currentParentSpan
yield* Effect.log(`Parent span: ${parentSpan}`)
return "child completed"
})
const program = Effect.gen(function*() {
yield* Effect.withSpan(childOperation, "child-span")
return "parent completed"
})
const traced = Effect.withSpan(program, "parent-span")
currentParentSpan: interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<type AnySpan = Span | ExternalSpanA span value that can participate in tracing, either an Effect-managed
Span or an ExternalSpan propagated from another tracing system.
Example (Accepting any span)
import { Effect, Tracer } from "effect"
// Function that accepts any span type
const logSpan = (span: Tracer.AnySpan) => {
console.log(`Span ID: ${span.spanId}, Trace ID: ${span.traceId}`)
return Effect.succeed(span)
}
// Works with both Span and ExternalSpan
const externalSpan = Tracer.externalSpan({
spanId: "span-123",
traceId: "trace-456"
})
AnySpan, import CauseCause.type Cause.NoSuchElementError = /*unresolved*/ anyNoSuchElementError> = import internalinternal.const currentParentSpan: Effect.Effect<
Tracer.AnySpan,
Cause.NoSuchElementError
>
const currentParentSpan: {
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;
}
currentParentSpan