Integrating Effect with OpenTelemetry: Understanding Global Span Context

I'm just not quite wrapping my head around integrating effect with opentelemetry. I have a third-party lib which uses the @opentelementry/api, but it seems like effect doesn't manage the global otel context.

import { NodeSdk } from "@effect/opentelemetry";
import { trace } from "@opentelemetry/api";
import {
  BatchSpanProcessor,
  ConsoleSpanExporter,
} from "@opentelemetry/sdk-trace-base";
import { Effect } from "effect";

const program = Effect.gen(function* () {
  const span = yield* Effect.currentSpan;

  console.log(`span: ${!!span}`); // true

  const globalSpan = yield* Effect.sync(() => trace.getActiveSpan());

  console.log(`globalSpan: ${!!globalSpan}`); // false
}).pipe(Effect.withSpan("myspan"));

const NodeSdkLive = NodeSdk.layer(() => ({
  resource: { serviceName: "example" },
  spanProcessor: new BatchSpanProcessor(new ConsoleSpanExporter()),
}));

void Effect.runPromise(program.pipe(Effect.provide(NodeSdkLive)));


Why is globalSpan undefined in the repro above? 🫣
Was this page helpful?