Hyperlinkv0.8.0-beta.28

Stream

Stream.withSpanconsteffect/Stream.ts:10338
(name: string, options?: SpanOptions): <A, E, R>(
  self: Stream<A, E, R>
) => Stream<A, E, Exclude<R, ParentSpan>>
<A, E, R>(
  self: Stream<A, E, R>,
  name: string,
  options?: SpanOptions
): Stream<A, E, Exclude<R, ParentSpan>>

Wraps the stream with a new span for tracing.

Example (Wrapping a stream in a span)

import { Console, Effect, Stream } from "effect"

const stream = Stream.fromArray([1, 2, 3]).pipe(Stream.withSpan("numbers"))

Effect.runPromise(
  Effect.gen(function*() {
    const values = yield* Stream.runCollect(stream)
    yield* Console.log(values)
  })
)
// [1, 2, 3]
tracing
Source effect/Stream.ts:1033813 lines
export const withSpan: {
  (name: string, options?: SpanOptions): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, Exclude<R, ParentSpan>>
  <A, E, R>(self: Stream<A, E, R>, name: string, options?: SpanOptions): Stream<A, E, Exclude<R, ParentSpan>>
} = function() {
  const dataFirst = isStream(arguments[0])
  const name = dataFirst ? arguments[1] : arguments[0]
  const options = addSpanStackTrace(dataFirst ? arguments[2] : arguments[1])
  if (dataFirst) {
    const self = arguments[0] as Stream<any, any, any>
    return fromChannel(Channel.withSpan(self.channel, name, options))
  }
  return (self: Stream<any, any, any>) => fromChannel(Channel.withSpan(self.channel, name, options))
} as any