Arize Phoenix TS
    Preparing search index...

    Interface SpanTraceOptions<Fn>

    Configuration options for span tracing in OpenInference.

    This interface defines all the available options for customizing how functions are traced, including span naming, tracer selection, span classification, and custom input/output processing. These options are used by tracing decorators and wrapper functions to control the tracing behavior.

    // Basic configuration with custom name
    const basicOptions: SpanTraceOptions = {
    name: "my-custom-operation"
    };

    // Advanced configuration with custom processing and base attributes
    const advancedOptions: SpanTraceOptions = {
    name: "llm-call",
    kind: "LLM",
    openTelemetrySpanKind: SpanKind.CLIENT,
    attributes: {
    'service.name': 'ai-assistant',
    'llm.model_name': 'gpt-4',
    'environment': 'production'
    },
    processInput: (...args) => ({ "llm.prompt": args[0] }),
    processOutput: (result) => ({ "llm.response": result })
    };

    // Agent-specific configuration with context attributes
    const agentOptions: SpanTraceOptions = {
    kind: "AGENT",
    attributes: {
    'agent.type': 'decision-maker',
    'agent.version': '2.1.0'
    },
    processInput: (...args) => ({
    "agent.input": JSON.stringify(args[0]),
    "agent.context": args[1]?.context || "none"
    })
    };
    interface SpanTraceOptions<Fn extends AnyFn = AnyFn> {
        attributes?: Attributes;
        kind?:
            | OpenInferenceSpanKind
            | "LLM"
            | "CHAIN"
            | "TOOL"
            | "RETRIEVER"
            | "RERANKER"
            | "EMBEDDING"
            | "AGENT"
            | "GUARDRAIL"
            | "EVALUATOR";
        name?: string;
        openTelemetrySpanKind?: SpanKind;
        processInput?: InputToAttributesFn<Fn>;
        processOutput?: OutputToAttributesFn<Fn>;
        tracer?: Tracer;
    }

    Type Parameters

    Index

    Properties

    attributes?: Attributes

    Base attributes to be added to every span created with these options.

    These attributes will be merged with any attributes generated by input/output processors and OpenInference semantic attributes. Base attributes are useful for adding consistent metadata like service information, version numbers, environment details, or any other static attributes that should be present on all spans.

    // Custom business context
    attributes: {
    'metadata': JSON.stringify({ tenant: 'tenant-123', feature: 'new-algorithm-enabled', request: 'mobile-app' })
    }
    kind?:
        | OpenInferenceSpanKind
        | "LLM"
        | "CHAIN"
        | "TOOL"
        | "RETRIEVER"
        | "RERANKER"
        | "EMBEDDING"
        | "AGENT"
        | "GUARDRAIL"
        | "EVALUATOR"

    The OpenInference span kind for semantic categorization in LLM applications.

    This provides domain-specific classification for AI/ML operations, helping to organize and understand the different types of operations in an LLM workflow.

    OpenInferenceSpanKind.CHAIN
    
    - `LLM` for language model inference
    - `CHAIN` for workflow sequences
    - `AGENT` for autonomous decision-making
    - `TOOL` for external tool usage
    name?: string

    Custom name for the span.

    If not provided, the name of the decorated function or wrapped function will be used as the span name. This is useful for providing more descriptive or standardized names for operations.

    "user-authentication", "data-processing-pipeline", "llm-inference"
    
    openTelemetrySpanKind?: SpanKind

    The OpenTelemetry span kind to classify the span's role in a trace.

    This determines how the span is categorized in the OpenTelemetry ecosystem and affects how tracing tools display and analyze the span.

    SpanKind.INTERNAL
    
    - `SpanKind.CLIENT` for outbound requests
    - `SpanKind.SERVER` for inbound request handling
    - `SpanKind.INTERNAL` for internal operations
    processInput?: InputToAttributesFn<Fn>

    Custom function to process input arguments into span attributes.

    This allows for custom serialization and attribute extraction from function arguments. If not provided, the default input processor will be used, which safely JSON-stringifies the arguments.

    The function arguments to process

    OpenTelemetry attributes object

    processInput: (...args) => ({
    'input.value': JSON.stringify(args),
    'input.mime_type': MimeType.JSON
    })
    processOutput?: OutputToAttributesFn<Fn>

    Custom function to process output values into span attributes.

    This allows for custom serialization and attribute extraction from function return values. If not provided, the default output processor will be used, which safely JSON-stringifies the result.

    The function's return value to process

    OpenTelemetry attributes object

    processOutput: (result) => ({
    'output.value': JSON.stringify(result),
    'output.mime_type': MimeType.JSON
    })
    tracer?: Tracer

    Custom OpenTelemetry tracer instance to use for this span.

    If not provided, the current global tracer provider is consulted when the wrapped function is invoked. This allows wrappers created before provider registration or replacement to pick up the latest global tracer unless you pin a specific tracer here.

    const customTracer = trace.getTracer('my-service', '1.0.0');
    const options: SpanTraceOptions = { tracer: customTracer };