Langfuse JS/TS SDKs
    Preparing search index...

    Function setLangfuseTracerProvider

    • Sets an isolated TracerProvider for Langfuse tracing operations.

      This allows Langfuse to use its own TracerProvider instance, separate from the global OpenTelemetry TracerProvider. This is useful for avoiding conflicts with other OpenTelemetry instrumentation in the application.

      ⚠️ Limitation: Span Context Sharing

      While this function isolates span processing and export, it does NOT provide complete trace isolation. OpenTelemetry context (trace IDs, parent spans) is still shared between the global and isolated providers. This means:

      • Spans created with the isolated provider inherit trace IDs from global spans
      • Spans created with the isolated provider inherit parent relationships from global spans
      • This can result in spans from different providers being part of the same logical trace

      Why this happens: OpenTelemetry uses a global context propagation mechanism that operates at the JavaScript runtime level, independent of individual TracerProvider instances. The context (containing trace ID, span ID) flows through async boundaries and is inherited by all spans created within that context, regardless of which TracerProvider creates them.

      Parameters

      • provider: null | TracerProvider

        The TracerProvider instance to use, or null to clear the isolated provider

      Returns void

      import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
      import { LangfuseSpanProcessor } from '@langfuse/otel';
      import { setLangfuseTracerProvider } from '@langfuse/tracing';

      // Create provider with span processors in constructor
      const provider = new NodeTracerProvider({
      spanProcessors: [new LangfuseSpanProcessor()]
      });

      setLangfuseTracerProvider(provider);

      // Note: Spans created with getLangfuseTracer() may still inherit
      // context from spans created with the global tracer