ExternalSpanRepresents a span created outside Effect's tracer, carrying trace and span identifiers, sampling state, and annotations so it can be used as a parent or link in Effect tracing.
Example (Creating an external span value)
import { Context } from "effect"
import type { Tracer } from "effect"
// Create an external span from another tracing system
const externalSpan: Tracer.ExternalSpan = {
_tag: "ExternalSpan",
spanId: "span-abc-123",
traceId: "trace-xyz-789",
sampled: true,
annotations: Context.empty()
}
console.log(`External span: ${externalSpan.spanId}`)models
Source effect/Tracer.ts:1967 lines
export interface ExternalSpan {
readonly ExternalSpan._tag: "ExternalSpan"_tag: "ExternalSpan"
readonly ExternalSpan.spanId: stringspanId: string
readonly ExternalSpan.traceId: stringtraceId: string
readonly ExternalSpan.sampled: booleansampled: boolean
readonly 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: 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>
}Referenced by 4 symbols