Effect CommunityEC
Effect Community16mo ago
1 reply
Gibbs

Adding Delay to DevToolsLayer for Trace Visibility in Effect Programs

Why is it needed to add a delay on the DevToolsLayer ? If I remove it in the playground, traces are no longer visible in the trace viewer..
Same goes for the vscode extension, adding Layer.effectDiscard(Effect.sleep(100)) is required on our app to make traces visible..
For instance, given this program and two versions of a DevToolLayer: DevToolsLive and DevToolsLiveDelayed:
import { DevTools } from "@effect/experimental";
import { NodeRuntime, NodeSocket } from "@effect/platform-node";
import { Effect, Layer } from "effect";

const program = Effect.log("Hello!").pipe(
  Effect.withSpan("Hi", { attributes: { foo: "bar" } })
);

const DevToolsLive = DevTools.layerWebSocket().pipe(
  Layer.provide(NodeSocket.layerWebSocketConstructor)
);

const DevToolsLiveDelayed = Layer.effectDiscard(Effect.sleep(100)).pipe(
  Layer.provide(DevToolsLive)
);

Then executing the program with DevToolsLive never stops and the trace is not visible in the vscode extension:
program.pipe(Effect.provide(DevToolsLive), NodeRuntime.runMain);

Whereas running it with the DevToolsLiveDelayed works fine (program exits and trace visible)
program.pipe(Effect.provide(DevToolsLiveDelayed), NodeRuntime.runMain);
Was this page helpful?