interface LLMObs {
    enabled: boolean;
    annotate(options): void;
    annotate(span, options): void;
    decorate(options): any;
    disable(): void;
    enable(options): void;
    exportSpan(span?): ExportedLLMObsSpan;
    flush(): void;
    submitEvaluation(spanContext, options): void;
    trace<T>(options, fn): T;
    wrap<T>(options, fn): T;
}

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

  • 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

    Returns ExportedLLMObsSpan

    An object containing the span and trace IDs.

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

    Returns void

  • Submits a custom evalutation 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, done) => T)

      The function to instrument.

        • (span, done): T
        • Parameters

          • span: export=.Span
          • done: ((error?) => void)
              • (error?): void
              • Parameters

                • Optional error: Error

                Returns void

          Returns T

    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)

    Parameters

    Returns T

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