dd-trace
    Preparing search index...

    Interface LLMObs

    interface LLMObs {
        enabled: boolean;
        annotate(options: AnnotationOptions): void;
        annotate(span: undefined | Span, options: AnnotationOptions): void;
        decorate(options: LLMObsNamelessSpanOptions): any;
        deregisterProcessor(): void;
        disable(): void;
        enable(options: LLMObsEnableOptions): void;
        exportSpan(span?: Span): ExportedLLMObsSpan;
        flush(): void;
        registerProcessor(
            processor: (span: LLMObservabilitySpan) => null | LLMObservabilitySpan,
        ): void;
        submitEvaluation(
            spanContext: ExportedLLMObsSpan,
            options: EvaluationOptions,
        ): void;
        trace<T>(
            options: LLMObsNamedSpanOptions,
            fn: (span: Span, done: (error?: Error) => void) => T,
        ): T;
        wrap<T = (...args: any[]) => any>(
            options: LLMObsNamelessSpanOptions,
            fn: T,
        ): T;
    }
    Index

    Properties

    enabled: boolean

    Whether or not LLM Observability is enabled.

    Methods

    • Sets inputs, outputs, tags, metadata, and metrics as provided for a given LLM Observability span. Note that with the exception of tags, this method will override any existing values for the provided fields.

      For example:

      llmobs.trace({ kind: 'llm', name: 'myLLM', modelName: 'gpt-4o', modelProvider: 'openai' }, () => {
      llmobs.annotate({
      inputData: [{ content: 'system prompt', role: 'system' }, { content: 'user prompt', role: 'user' }],
      outputData: { content: 'response', role: 'ai' },
      metadata: { temperature: 0.7 },
      tags: { host: 'localhost' },
      metrics: { inputTokens: 10, outputTokens: 20, totalTokens: 30 }
      })
      })

      Parameters

      • options: AnnotationOptions

        An object containing the inputs, outputs, tags, metadata, and metrics to set on the span.

      Returns void

    • Parameters

      Returns void

    • Decorate a function in a javascript runtime that supports function decorators. Note that this is not supported in the Node.js runtime, but is in TypeScript.

      In TypeScript, this decorator is only supported in contexts where general TypeScript function decorators are supported.

      Parameters

      Returns any

    • Deregister a processor.

      Returns void

    • Disable LLM Observability tracing.

      Returns void

    • Returns a representation of a span to export its span and trace IDs. If no span is provided, the current LLMObs-type span will be used.

      Parameters

      • Optionalspan: Span

        Optional span to export.

      Returns ExportedLLMObsSpan

      An object containing the span and trace IDs.

    • Flushes any remaining spans and evaluation metrics to LLM Observability.

      Returns void

    • Register a processor to be called on each LLMObs span.

      This can be used to modify the span before it is sent to LLMObs. For example, you can modify the input/output. You can also return null to omit the span entirely from being sent to LLM Observability.

      Otherwise, if the return value from the processor is not an instance of LLMObservabilitySpan, the span will be dropped.

      To deregister the processor, call llmobs.deregisterProcessor()

      Parameters

      Returns void

      If a processor is already registered.

    • Submits a custom evaluation metric for a given span ID and trace ID.

      Parameters

      • spanContext: ExportedLLMObsSpan

        The span context of the span to submit the evaluation metric for.

      • options: EvaluationOptions

        An object containing the label, metric type, value, and tags of the evaluation metric.

      Returns void

    • Instruments a function by automatically creating a span activated on its scope.

      The span will automatically be finished when one of these conditions is met:

      • The function returns a promise, in which case the span will finish when the promise is resolved or rejected.
      • The function takes a callback as its second parameter, in which case the span will finish when that callback is called.
      • The function doesn't accept a callback and doesn't return a promise, in which case the span will finish at the end of the function execution.

      Type Parameters

      • T

      Parameters

      • options: LLMObsNamedSpanOptions

        Optional LLM Observability span options.

      • fn: (span: Span, done: (error?: Error) => void) => T

        The function to instrument.

      Returns T

      The return value of the function.

    • Wrap a function to automatically create a span activated on its scope when it's called.

      The span will automatically be finished when one of these conditions is met:

      • The function returns a promise, in which case the span will finish when the promise is resolved or rejected.
      • The function takes a callback as its last parameter, in which case the span will finish when that callback is called.
      • The function doesn't accept a callback and doesn't return a promise, in which case the span will finish at the end of the function execution.

      Type Parameters

      • T = (...args: any[]) => any

      Parameters

      Returns T

      A new function that wraps the provided function with span creation.