(options: {
readonly spanId: string
readonly traceId: string
readonly sampled?: boolean | undefined
readonly annotations?: Context.Context<never> | undefined
}): ExternalSpanCreates an ExternalSpan from trace and span identifiers, defaulting
sampled to true and annotations to an empty context when they are not
provided.
Example (Creating an external span)
import { Effect, Tracer } from "effect"
// Create an external span from another tracing system
const span = Tracer.externalSpan({
spanId: "span-abc-123",
traceId: "trace-xyz-789",
sampled: true
})
// Use the external span as a parent
const program = Effect.succeed("Hello").pipe(
Effect.withSpan("child-operation", { parent: span })
)constructors
Source effect/Tracer.ts:44714 lines
export const const externalSpan: (options: {
readonly spanId: string
readonly traceId: string
readonly sampled?: boolean | undefined
readonly annotations?:
| Context.Context<never>
| undefined
}) => ExternalSpan
Creates an ExternalSpan from trace and span identifiers, defaulting
sampled to true and annotations to an empty context when they are not
provided.
Example (Creating an external span)
import { Effect, Tracer } from "effect"
// Create an external span from another tracing system
const span = Tracer.externalSpan({
spanId: "span-abc-123",
traceId: "trace-xyz-789",
sampled: true
})
// Use the external span as a parent
const program = Effect.succeed("Hello").pipe(
Effect.withSpan("child-operation", { parent: span })
)
externalSpan = (
options: {
readonly spanId: string
readonly traceId: string
readonly sampled?: boolean | undefined
readonly annotations?:
| Context.Context<never>
| undefined
}
options: {
readonly spanId: stringspanId: string
readonly traceId: stringtraceId: string
readonly sampled?: boolean | undefinedsampled?: boolean | undefined
readonly annotations?: Context.Context<never> | undefinedannotations?: import ContextContext.interface Context<in Services>Immutable collection of service implementations used for dependency
injection in Effect programs.
Details
The type parameter tracks the service identifiers available in the context.
At runtime, services are stored by each key's string key.
Example (Creating a context with multiple services)
import { Context } from "effect"
// Create a context with multiple services
const Logger = Context.Service<{ log: (msg: string) => void }>("Logger")
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
const context = Context.make(Logger, {
log: (msg: string) => console.log(msg)
})
.pipe(Context.add(Database, { query: (sql) => `Result: ${sql}` }))
Context<never> | undefined
}
): ExternalSpan => ({
ExternalSpan._tag: "ExternalSpan"_tag: "ExternalSpan",
ExternalSpan.spanId: stringspanId: options: {
readonly spanId: string
readonly traceId: string
readonly sampled?: boolean | undefined
readonly annotations?:
| Context.Context<never>
| undefined
}
options.spanId: stringspanId,
ExternalSpan.traceId: stringtraceId: options: {
readonly spanId: string
readonly traceId: string
readonly sampled?: boolean | undefined
readonly annotations?:
| Context.Context<never>
| undefined
}
options.traceId: stringtraceId,
ExternalSpan.sampled: booleansampled: options: {
readonly spanId: string
readonly traceId: string
readonly sampled?: boolean | undefined
readonly annotations?:
| Context.Context<never>
| undefined
}
options.sampled?: boolean | undefinedsampled ?? true,
ExternalSpan.annotations: Context.Context<never>(property) ExternalSpan.annotations: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
annotations: options: {
readonly spanId: string
readonly traceId: string
readonly sampled?: boolean | undefined
readonly annotations?:
| Context.Context<never>
| undefined
}
options.annotations?: Context.Context<never> | undefinedannotations ?? import ContextContext.const empty: () => Context<never>Returns an empty Context.
Example (Creating an empty context)
import { Context } from "effect"
import * as assert from "node:assert"
assert.strictEqual(Context.isContext(Context.empty()), true)
empty()
})Referenced by 2 symbols