Are you sure you want to delete this access key?
This example demonstrates how to use OpenTelemetry to trace the internal operations of your LLM providers during Promptfoo evaluations.
Promptfoo's OpenTelemetry integration allows you to:
traceparent
fieldnpm install @opentelemetry/api \
@opentelemetry/sdk-trace-node \
@opentelemetry/exporter-trace-otlp-http \
@opentelemetry/resources \
@opentelemetry/semantic-conventions
Add the tracing configuration to your promptfooconfig.yaml
:
tracing:
enabled: true
otlp:
http:
enabled: true
port: 4318
In your provider code, extract the trace context and create child spans:
const { trace } = require('@opentelemetry/api');
module.exports = {
async callApi(prompt, context) {
// Check for trace context from Promptfoo
if (context.traceparent) {
// Parse and use the trace context
// ... (see provider examples)
}
// Your provider logic with spans
const span = tracer.startSpan('my_operation');
try {
// Do work...
span.setStatus({ code: SpanStatusCode.OK });
return { output: result };
} finally {
span.end();
}
},
};
promptfoo eval
Configure OpenTelemetry using standard environment variables:
# Endpoint for OTLP exporter (defaults to Promptfoo's receiver)
export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318"
# Optional: headers for authentication
export OTEL_EXPORTER_OTLP_HEADERS="api-key=your-key"
# Service name for your provider
export OTEL_SERVICE_NAME="my-rag-application"
# Enable tracing via environment variable
export PROMPTFOO_TRACING_ENABLED=true
See provider-simple-traced.js
for a clean example showing:
See provider-with-tracing.js
for a complete RAG pipeline example with:
See provider-simple.ts
for a TypeScript example showing:
Promptfoo now includes built-in trace visualization in the web UI:
Run your evaluation with tracing enabled:
promptfoo eval -c test-trace-ui.yaml
Open the web UI:
promptfoo view
Click on any test result's magnifying glass icon (🔎) to open the output dialog
Scroll down to see the "Trace Timeline" section showing:
Traces are stored in SQLite and linked to evaluations. The storage includes:
If you see errors like context.active is not a function
, this is because the OpenTelemetry context
API conflicts with Promptfoo's context parameter. To fix this:
Import OpenTelemetry context with an alias:
const { context: otelContext } = require('@opentelemetry/api');
Use different parameter names for Promptfoo context:
async callApi(prompt, promptfooContext) {
// Use promptfooContext for Promptfoo's context
// Use otelContext for OpenTelemetry's context API
}
tracing:
forwarding:
enabled: true
endpoint: 'http://jaeger:4318'
headers:
'api-key': '${JAEGER_API_KEY}'
// In your provider initialization
const sampler = new TraceIdRatioBasedSampler(0.1); // 10% sampling
Press p or to see the previous file or, n or to see the next file
Browsing data directories saved to S3 is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with AWS S3!
Are you sure you want to delete this access key?
Browsing data directories saved to Google Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with Google Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to Azure Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with Azure Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to S3 compatible storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with your S3 compatible storage!
Are you sure you want to delete this access key?