Prompt Chain

Integrate AI Observability with OpenTelemetry

Built-in OpenTelemetry tracing for promptfoo LLM evaluations, capturing GenAI semantic conventions and provider spans across OpenAI, Anthropic, Azure OpenAI

Works with opentelemetry

74
Spark score
out of 100
Updated 9 days ago
Version 0.121.19
Models

Add to Favorites

Why it matters

Integrate AI observability into your CI/CD pipeline using OpenTelemetry. This asset helps you monitor and debug AI model performance within your existing DevOps workflows.

Outcomes

What it gets done

01

Set up OpenTelemetry for AI model tracing.

02

Monitor AI performance metrics in real-time.

03

Debug AI-related issues within the CI/CD process.

04

Analyze AI model behavior and identify bottlenecks.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/pfoo-built-in | bash

Steps

Steps in the chain

01
Set up environment variables
02
Run the evaluation
03
View traces in the UI

Overview

Built In

Built In provides automatic OpenTelemetry tracing for promptfoo LLM evaluations, capturing detailed span data for every provider call. It records GenAI semantic convention attributes including token usage, model parameters, temperature settings, and provider-specific metadata. Traces export to promptfoo's UI or external OTLP backends like Jaeger and Honeycomb. Use Built In when you need observability into LLM provider behavior during evaluations, want to analyze token consumption patterns across test cases, or need to integrate promptfoo into existing OpenTelemetry-instrumented infrastructure. It is useful for evaluation pipelines requiring visibility and performance analysis across multiple providers.

What it does

Built In provides automatic OpenTelemetry instrumentation for promptfoo LLM provider calls. It captures detailed span data following GenAI semantic conventions, including token usage, model parameters, and provider-specific attributes across every evaluation run. Tracing is enabled by default and exports to promptfoo's UI or external OTLP backends like Jaeger and Honeycomb.

When to use - and when NOT to

Use Built In when you need to debug LLM provider behavior, analyze token consumption patterns across test cases, or integrate promptfoo evaluations into existing observability stacks. It is useful for evaluation pipelines where you need visibility into model calls, or when comparing behavior across multiple providers. Do NOT use this if you need to disable tracing for specific requirements, which can be done by setting PROMPTFOO_DISABLE_TRACING to true.

Inputs and outputs

You provide API keys for the LLM providers you want to test and optionally configure environment variables to control tracing behavior. The system automatically instruments every LLM call during evaluation. You receive detailed trace spans in the promptfoo UI Traces tab or your configured OTLP backend, containing GenAI semantic convention attributes including gen_ai.system, gen_ai.operation.name, gen_ai.request.model, gen_ai.request.max_tokens, gen_ai.request.temperature, gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, gen_ai.usage.total_tokens, gen_ai.usage.cached_tokens, gen_ai.usage.reasoning_tokens, gen_ai.response.model, gen_ai.response.id, and gen_ai.response.finish_reasons, plus promptfoo-specific attributes including promptfoo.provider.id, promptfoo.eval.id, promptfoo.test.index, and promptfoo.prompt.label.

Integrations

Built In supports LLM providers with full tracing instrumentation: OpenAI, Anthropic, Azure OpenAI, AWS Bedrock, Google Vertex AI, Ollama, Mistral, Cohere, Huggingface, IBM Watsonx, HTTP, OpenRouter, Replicate, OpenAI-compatible providers (inherited), and Cloudflare AI (inherited). For observability backends, it exports to any OTLP-compatible system including Jaeger (open-source distributed tracing) and Honeycomb (observability platform). Configuration uses standard OpenTelemetry environment variables (OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, OTEL_SERVICE_NAME) and promptfoo-specific controls (PROMPTFOO_DISABLE_TRACING).

Quick start example

Initialize and run the example:

npx promptfoo@latest init --example integration-opentelemetry/built-in
cd integration-opentelemetry/built-in

Set provider credentials:

export OPENAI_API_KEY=sk-...
export ANTHROPIC_API_KEY=sk-ant-...

Run evaluation and view traces:

npx promptfoo eval -c promptfooconfig.yaml
npx promptfoo view

Export to Jaeger:

docker run -d --name jaeger \
  -e COLLECTOR_OTLP_ENABLED=true \
  -p 16686:16686 \
  -p 4318:4318 \
  jaegertracing/all-in-one:latest
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 npx promptfoo eval

Who it's for

Built In is for ML engineers and DevOps teams running systematic LLM evaluations who need observability into provider behavior, token economics, and model performance. It serves platform teams integrating promptfoo into existing OpenTelemetry-instrumented infrastructure, and data scientists debugging prompt performance across multiple providers. Unlike manual logging approaches, Built In provides standardized GenAI semantic conventions and zero-configuration instrumentation for supported providers.

Source README

integration-opentelemetry/built-in (OpenTelemetry Built-in Tracing)

You can run this example with:

npx promptfoo@latest init --example integration-opentelemetry/built-in
cd integration-opentelemetry/built-in

This example demonstrates promptfoo's built-in OpenTelemetry tracing for LLM provider calls.

Quick Start

  1. Set up environment variables:
### Required for the providers you want to test
export OPENAI_API_KEY=sk-...
export ANTHROPIC_API_KEY=sk-ant-...
### Add other provider keys as needed
  1. Run the evaluation:
npx promptfoo eval -c promptfooconfig.yaml
  1. View traces in the UI:
npx promptfoo view

Navigate to the Traces tab to see detailed span information.

Configuration

Tracing is enabled by default. Configure via environment variables:

Variable Default Description
PROMPTFOO_DISABLE_TRACING false Set to true to disable tracing
OTEL_EXPORTER_OTLP_ENDPOINT - Export traces to external OTLP backend
OTEL_SERVICE_NAME promptfoo Service name in traces

Viewing Traces Externally

With Jaeger

  1. Start Jaeger:
docker run -d --name jaeger \
  -e COLLECTOR_OTLP_ENABLED=true \
  -p 16686:16686 \
  -p 4318:4318 \
  jaegertracing/all-in-one:latest
  1. Run eval with OTLP export:
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 npx promptfoo eval
  1. View at http://localhost:16686

With Honeycomb

OTEL_EXPORTER_OTLP_ENDPOINT=https://api.honeycomb.io \
OTEL_EXPORTER_OTLP_HEADERS="x-honeycomb-team=YOUR_API_KEY" \
npx promptfoo eval

Trace Attributes

Each LLM call span includes:

GenAI Semantic Conventions

  • gen_ai.system - Provider system (openai, anthropic, etc.)
  • gen_ai.operation.name - Operation type (chat, completion, embedding)
  • gen_ai.request.model - Requested model name
  • gen_ai.request.max_tokens - Max tokens setting
  • gen_ai.request.temperature - Temperature setting
  • gen_ai.usage.input_tokens - Prompt tokens used
  • gen_ai.usage.output_tokens - Completion tokens used
  • gen_ai.usage.total_tokens - Total tokens
  • gen_ai.usage.cached_tokens - Cached tokens (Anthropic)
  • gen_ai.usage.reasoning_tokens - Reasoning tokens (o1 models)
  • gen_ai.response.model - Actual model used
  • gen_ai.response.id - Provider response ID
  • gen_ai.response.finish_reasons - Finish reasons

Promptfoo Attributes

  • promptfoo.provider.id - Provider identifier
  • promptfoo.eval.id - Evaluation run ID
  • promptfoo.test.index - Test case index
  • promptfoo.prompt.label - Prompt label

Supported Providers

All major providers are instrumented:

Provider Tracing Support
OpenAI
Anthropic
Azure OpenAI
AWS Bedrock
Google Vertex AI
Ollama
Mistral
Cohere
Huggingface
IBM Watsonx
HTTP
OpenRouter
Replicate
OpenAI-compatible ✓ (inherited)
Cloudflare AI ✓ (inherited)

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.