OpenInference JS
    Preparing search index...
    • Experimental

      Wraps a function with tracing capabilities, specifically marking it as a CHAIN span.

      This is a convenience function that wraps withSpan with the OpenInference span kind pre-configured to CHAIN. Chain spans represent a sequence of operations or a workflow in an LLM application, such as a series of processing steps or a pipeline.

      This API is experimental and may change in future versions

      Type Parameters

      • Fn extends AnyFn

        The function type being wrapped, preserving original signature

      Parameters

      • fn: Fn

        The function to wrap with CHAIN span tracing

      • Optionaloptions: Omit<SpanTraceOptions<AnyFn>, "kind">

        Configuration options for tracing behavior (excluding kind)

        • tracer

          Custom OpenTelemetry tracer instance (defaults to global tracer)

        • name

          Custom span name (defaults to function name)

        • openTelemetrySpanKind

          OpenTelemetry span kind (defaults to INTERNAL)

        • processInput

          Custom function to process input arguments into attributes

        • processOutput

          Custom function to process output values into attributes

        • attributes

          Base attributes to be added to every span created

      Returns Fn

      A wrapped function with identical signature that creates CHAIN spans during execution

      // Trace a data processing pipeline
      const processData = (data: any[]) => {
      return data.map(item => transform(item)).filter(item => validate(item));
      };
      const tracedProcess = traceChain(processData, { name: "data-pipeline" });

      // Trace a multi-step workflow
      const executeWorkflow = async (input: WorkflowInput) => {
      const step1 = await preprocessInput(input);
      const step2 = await processStep(step1);
      return await finalizeOutput(step2);
      };
      const tracedWorkflow = traceChain(executeWorkflow);