(
span: AnySpan | ReadonlyArray<AnySpan>,
attributes?: Record<string, unknown>
): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R>
<A, E, R>(
self: Effect<A, E, R>,
span: AnySpan | ReadonlyArray<AnySpan>,
attributes?: Record<string, unknown>
): Effect<A, E, R>Adds a link with the provided span to all spans in this effect.
Details
This is useful for connecting spans that are related but not in a direct parent-child relationship. For example, you might want to link spans from parallel operations or connect spans across different traces.
Example (Linking one span to another span)
import { Effect } from "effect"
const parentEffect = Effect.withSpan("parent-operation")(
Effect.succeed("parent result")
)
const childEffect = Effect.withSpan("child-operation")(
Effect.succeed("child result")
)
// Link the child span to the parent span
const program = Effect.gen(function*() {
const parentSpan = yield* Effect.currentSpan
const result = yield* childEffect.pipe(
Effect.linkSpans(parentSpan, { relationship: "follows" })
)
return result
})Example (Linking multiple spans at once)
import { Effect } from "effect"
// Link multiple spans
const program = Effect.gen(function*() {
const span1 = yield* Effect.currentSpan
const span2 = yield* Effect.currentSpan
return yield* Effect.succeed("result").pipe(
Effect.linkSpans([span1, span2], {
type: "dependency",
source: "multiple-operations"
})
)
})export const const linkSpans: {
(
span: AnySpan | ReadonlyArray<AnySpan>,
attributes?: Record<string, unknown>
): <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E, R>
<A, E, R>(
self: Effect<A, E, R>,
span: AnySpan | ReadonlyArray<AnySpan>,
attributes?: Record<string, unknown>
): Effect<A, E, R>
}
Adds a link with the provided span to all spans in this effect.
Details
This is useful for connecting spans that are related but not in a direct
parent-child relationship. For example, you might want to link spans from
parallel operations or connect spans across different traces.
Example (Linking one span to another span)
import { Effect } from "effect"
const parentEffect = Effect.withSpan("parent-operation")(
Effect.succeed("parent result")
)
const childEffect = Effect.withSpan("child-operation")(
Effect.succeed("child result")
)
// Link the child span to the parent span
const program = Effect.gen(function*() {
const parentSpan = yield* Effect.currentSpan
const result = yield* childEffect.pipe(
Effect.linkSpans(parentSpan, { relationship: "follows" })
)
return result
})
Example (Linking multiple spans at once)
import { Effect } from "effect"
// Link multiple spans
const program = Effect.gen(function*() {
const span1 = yield* Effect.currentSpan
const span2 = yield* Effect.currentSpan
return yield* Effect.succeed("result").pipe(
Effect.linkSpans([span1, span2], {
type: "dependency",
source: "multiple-operations"
})
)
})
linkSpans: {
(
span: AnySpan | ReadonlyArray<AnySpan>span: 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 | interface ReadonlyArray<T>ReadonlyArray<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>,
attributes: Record<string, unknown> | undefinedattributes?: type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, unknown>
): <function (type parameter) A in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, R>R>(self: Effect<A, E, R>(parameter) self: {
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;
}
self: 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<function (type parameter) A in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, R>R>) => 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<function (type parameter) A in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, R>R>
<function (type parameter) A in <A, E, R>(self: Effect<A, E, R>, span: AnySpan | ReadonlyArray<AnySpan>, attributes?: Record<string, unknown>): Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>, span: AnySpan | ReadonlyArray<AnySpan>, attributes?: Record<string, unknown>): Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>, span: AnySpan | ReadonlyArray<AnySpan>, attributes?: Record<string, unknown>): Effect<A, E, R>R>(
self: Effect<A, E, R>(parameter) self: {
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;
}
self: 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<function (type parameter) A in <A, E, R>(self: Effect<A, E, R>, span: AnySpan | ReadonlyArray<AnySpan>, attributes?: Record<string, unknown>): Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>, span: AnySpan | ReadonlyArray<AnySpan>, attributes?: Record<string, unknown>): Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>, span: AnySpan | ReadonlyArray<AnySpan>, attributes?: Record<string, unknown>): Effect<A, E, R>R>,
span: AnySpan | ReadonlyArray<AnySpan>span: 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 | interface ReadonlyArray<T>ReadonlyArray<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>,
attributes: Record<string, unknown> | undefinedattributes?: type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, unknown>
): 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<function (type parameter) A in <A, E, R>(self: Effect<A, E, R>, span: AnySpan | ReadonlyArray<AnySpan>, attributes?: Record<string, unknown>): Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>, span: AnySpan | ReadonlyArray<AnySpan>, attributes?: Record<string, unknown>): Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>, span: AnySpan | ReadonlyArray<AnySpan>, attributes?: Record<string, unknown>): Effect<A, E, R>R>
} = import internalinternal.const linkSpans: {
(
span:
| Tracer.AnySpan
| ReadonlyArray<Tracer.AnySpan>,
attributes?: Record<string, unknown>
): <A, E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
<A, E, R>(
self: Effect.Effect<A, E, R>,
span:
| Tracer.AnySpan
| ReadonlyArray<Tracer.AnySpan>,
attributes?: Record<string, unknown>
): Effect.Effect<A, E, R>
}
linkSpans