Context.Reference<ReadonlyArray<SpanLink>>Context reference for managing span links that are automatically added to all new spans. Span links connect related spans that are not in a parent-child relationship.
When to use
Use to attach shared links to every span created in the current context.
Example (Managing span links)
import { Effect, References, Tracer } from "effect"
const spanLinksExample = Effect.gen(function*() {
// Get current links (empty by default)
const current = yield* References.TracerSpanLinks
console.log(current.length) // 0
// Create an external span for the example
const externalSpan = Tracer.externalSpan({
spanId: "external-span-123",
traceId: "trace-456"
})
// Create span links
const spanLink: Tracer.SpanLink = {
span: externalSpan,
attributes: {
relationship: "follows-from",
priority: "high"
}
}
// Set global span links
yield* Effect.provideService(
Effect.gen(function*() {
// Get current links
const links = yield* References.TracerSpanLinks
console.log(links.length) // 1
// All new spans will include these links
yield* Effect.gen(function*() {
yield* Effect.log("This span will have linked spans")
return "operation complete"
})
}),
References.TracerSpanLinks,
[spanLink]
)
// Clear links
yield* Effect.provideService(
Effect.gen(function*() {
const links = yield* References.TracerSpanLinks
console.log(links.length) // 0
}),
References.TracerSpanLinks,
[]
)
})references
Source effect/References.ts:6091 lines
export const const TracerSpanLinks: Context.Reference<
ReadonlyArray<SpanLink>
>
const TracerSpanLinks: {
key: string;
Service: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<SpanLink>>): Array<SpanLink>; (...items: Array<SpanLink | ConcatArray<SpanLink>>): Array<SpanLink> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<SpanLink>;
indexOf: (searchElement: SpanLink, fromIndex?: number) => number;
lastIndexOf: (searchElement: SpanLink, fromIndex?: number) => number;
every: { (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => unknown, thisArg?: any): bo…;
some: (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => void, thisArg?: any) => void;
map: (callbackfn: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => value is S, thisArg?: any): Array<S>; (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => unknown, thisArg?: any): Array<SpanLink…;
reduce: { (callbackfn: (previousValue: SpanLink, currentValue: SpanLink, currentIndex: number, array: ReadonlyArray<SpanLink>) => SpanLink): SpanLink; (callbackfn: (previousValue: SpanLink, currentValue: SpanLink, currentIndex: number, array: Read…;
reduceRight: { (callbackfn: (previousValue: SpanLink, currentValue: SpanLink, currentIndex: number, array: ReadonlyArray<SpanLink>) => SpanLink): SpanLink; (callbackfn: (previousValue: SpanLink, currentValue: SpanLink, currentIndex: number, array: Read…;
find: { (predicate: (value: SpanLink, index: number, obj: ReadonlyArray<SpanLink>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SpanLink, index: number, obj: ReadonlyArray<SpanLink>) => unknown, thisArg?: any): SpanLink | un…;
findIndex: (predicate: (value: SpanLink, index: number, obj: ReadonlyArray<SpanLink>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, SpanLink]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<SpanLink>;
includes: (searchElement: SpanLink, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: SpanLink, index: number, array: Array<SpanLink>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => SpanLink | undefined;
findLast: { (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => unknown, thisArg?: any): SpanLink …;
findLastIndex: (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => unknown, thisArg?: any) => number;
toReversed: () => Array<SpanLink>;
toSorted: (compareFn?: ((a: SpanLink, b: SpanLink) => number) | undefined) => Array<SpanLink>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<SpanLink>): Array<SpanLink>; (start: number, deleteCount?: number): Array<SpanLink> };
with: (index: number, value: SpanLink) => Array<SpanLink>;
};
defaultValue: () => Shape;
of: (this: void, self: ReadonlyArray<SpanLink>) => ReadonlyArray<SpanLink>;
context: (self: ReadonlyArray<SpanLink>) => Context.Context<never>;
use: (f: (service: ReadonlyArray<SpanLink>) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: ReadonlyArray<SpanLink>) => A) => Effect<A, never, never>;
Identifier: Identifier;
stack: string | undefined;
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;
}
Context reference for managing span links that are automatically added to all new spans.
Span links connect related spans that are not in a parent-child relationship.
When to use
Use to attach shared links to every span created in the current context.
Example (Managing span links)
import { Effect, References, Tracer } from "effect"
const spanLinksExample = Effect.gen(function*() {
// Get current links (empty by default)
const current = yield* References.TracerSpanLinks
console.log(current.length) // 0
// Create an external span for the example
const externalSpan = Tracer.externalSpan({
spanId: "external-span-123",
traceId: "trace-456"
})
// Create span links
const spanLink: Tracer.SpanLink = {
span: externalSpan,
attributes: {
relationship: "follows-from",
priority: "high"
}
}
// Set global span links
yield* Effect.provideService(
Effect.gen(function*() {
// Get current links
const links = yield* References.TracerSpanLinks
console.log(links.length) // 1
// All new spans will include these links
yield* Effect.gen(function*() {
yield* Effect.log("This span will have linked spans")
return "operation complete"
})
}),
References.TracerSpanLinks,
[spanLink]
)
// Clear links
yield* Effect.provideService(
Effect.gen(function*() {
const links = yield* References.TracerSpanLinks
console.log(links.length) // 0
}),
References.TracerSpanLinks,
[]
)
})
TracerSpanLinks: import ContextContext.type Context.Reference = /*unresolved*/ anyReference<interface ReadonlyArray<T>ReadonlyArray<SpanLink>> = import referencesreferences.const TracerSpanLinks: Context.Reference<
ReadonlyArray<SpanLink>
>
const TracerSpanLinks: {
key: string;
Service: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<SpanLink>>): Array<SpanLink>; (...items: Array<SpanLink | ConcatArray<SpanLink>>): Array<SpanLink> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<SpanLink>;
indexOf: (searchElement: SpanLink, fromIndex?: number) => number;
lastIndexOf: (searchElement: SpanLink, fromIndex?: number) => number;
every: { (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => unknown, thisArg?: any): bo…;
some: (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => void, thisArg?: any) => void;
map: (callbackfn: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => value is S, thisArg?: any): Array<S>; (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => unknown, thisArg?: any): Array<SpanLink…;
reduce: { (callbackfn: (previousValue: SpanLink, currentValue: SpanLink, currentIndex: number, array: ReadonlyArray<SpanLink>) => SpanLink): SpanLink; (callbackfn: (previousValue: SpanLink, currentValue: SpanLink, currentIndex: number, array: Read…;
reduceRight: { (callbackfn: (previousValue: SpanLink, currentValue: SpanLink, currentIndex: number, array: ReadonlyArray<SpanLink>) => SpanLink): SpanLink; (callbackfn: (previousValue: SpanLink, currentValue: SpanLink, currentIndex: number, array: Read…;
find: { (predicate: (value: SpanLink, index: number, obj: ReadonlyArray<SpanLink>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SpanLink, index: number, obj: ReadonlyArray<SpanLink>) => unknown, thisArg?: any): SpanLink | un…;
findIndex: (predicate: (value: SpanLink, index: number, obj: ReadonlyArray<SpanLink>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, SpanLink]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<SpanLink>;
includes: (searchElement: SpanLink, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: SpanLink, index: number, array: Array<SpanLink>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => SpanLink | undefined;
findLast: { (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => unknown, thisArg?: any): SpanLink …;
findLastIndex: (predicate: (value: SpanLink, index: number, array: ReadonlyArray<SpanLink>) => unknown, thisArg?: any) => number;
toReversed: () => Array<SpanLink>;
toSorted: (compareFn?: ((a: SpanLink, b: SpanLink) => number) | undefined) => Array<SpanLink>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<SpanLink>): Array<SpanLink>; (start: number, deleteCount?: number): Array<SpanLink> };
with: (index: number, value: SpanLink) => Array<SpanLink>;
};
defaultValue: () => Shape;
of: (this: void, self: ReadonlyArray<SpanLink>) => ReadonlyArray<SpanLink>;
context: (self: ReadonlyArray<SpanLink>) => Context.Context<never>;
use: (f: (service: ReadonlyArray<SpanLink>) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: ReadonlyArray<SpanLink>) => A) => Effect<A, never, never>;
Identifier: Identifier;
stack: string | undefined;
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;
}
TracerSpanLinks