Effect CommunityEC
Effect Community2mo ago
3 replies
ikigai

Issue with Tracing in Managed Runtime Setup

I am trying to provide tracing into a managed runtime. When I do that using following code snippet, log traces are not emitted. However, when I provide trace layer directly to the program using effect.provide, it works.

Any clue on what am I doing wrong and how I can accomplish embedding trace layer into my managed runtime?

here's the link to the playground where this issue can be reproduced - https://effect.website/play/#41ef2584c84a

import { WebSdk } from "@effect/opentelemetry"
import { BatchSpanProcessor, ConsoleSpanExporter } from "@opentelemetry/sdk-trace-base"
import { Effect, Layer, ManagedRuntime } from "effect"

export const TraceLayer = Layer.unwrapEffect(Effect.gen(function*() {
  return WebSdk.layer(() => ({
    resource: { serviceName: "scratch" },
    spanProcessor: new BatchSpanProcessor(new ConsoleSpanExporter())
  }))
}))

const runtime = ManagedRuntime.make(TraceLayer)
// const runtime = ManagedRuntime.make(Layer.empty);

const program = Effect.gen(function*() {
  yield* Effect.log("Welcome to the Effect Playground!")
}).pipe(Effect.withSpan("program", {
  attributes: { source: "Playground" }
}))

program.pipe(
  // Effect.provide(TraceLayer),
  runtime.runPromise
)
Was this page helpful?