OpenTelemetry GenAI Utils
Project description
This package plugs the deepeval metrics suite into the OpenTelemetry GenAI evaluation pipeline. When it is installed a Deepeval evaluator is registered automatically and, unless explicitly disabled, is executed for every LLM/agent invocation alongside the builtin metrics.
Installation
Install the evaluator (and its runtime dependencies) from PyPI:
pip install opentelemetry-util-genai-evals-deepeval
The command pulls in opentelemetry-util-genai, deepeval and openai automatically so the evaluator is ready to use right after installation.
Requirements
opentelemetry-util-genai together with deepeval and openai – these are installed automatically when you install this package.
An LLM provider supported by Deepeval. By default the evaluator uses OpenAI’s gpt-4o-mini model because it offers the best balance of latency and cost for judge workloads right now, so make sure OPENAI_API_KEY is available. To override the model, set DEEPEVAL_EVALUATION_MODEL (or DEEPEVAL_MODEL / OPENAI_MODEL) to a different deployment along with the corresponding provider credentials.
(Optional) DEEPEVAL_API_KEY if your Deepeval account requires it.
Configuration
Use OTEL_INSTRUMENTATION_GENAI_EVALS_EVALUATORS to select the metrics that should run. Leaving the variable unset enables every registered evaluator with its default metric set. Examples:
OTEL_INSTRUMENTATION_GENAI_EVALS_EVALUATORS=Deepeval – run the default Deepeval bundle (Bias, Toxicity, Answer Relevancy, Faithfulness).
OTEL_INSTRUMENTATION_GENAI_EVALS_EVALUATORS=Deepeval(LLMInvocation(bias(threshold=0.75))) – override the Bias threshold for LLM invocations and skip the remaining metrics.
OTEL_INSTRUMENTATION_GENAI_EVALS_EVALUATORS=none – disable the evaluator entirely.
Results are emitted through the standard GenAI evaluation emitters (events, metrics, spans). Each metric includes helper attributes such as deepeval.success, deepeval.threshold and any evaluation model metadata returned by Deepeval. Metrics that cannot run because required inputs are missing (for example Faithfulness without a retrieval_context) are marked as label="skipped" and carry a deepeval.error attribute so you can wire the necessary data or disable that metric explicitly.
GEval Metric Scoring
The GEval-based metrics use specific scoring conventions:
Hallucination Metric:
Score range: 0.0 to 1.0 (lower is better)
0.0 = No hallucination (output fully grounded in input)
1.0 = Maximum hallucination (fabrications or contradictions)
Attribute deepeval.hallucination.geval_score contains the original GEval score (inverted internally)
Sentiment Metric:
Score range: 0.0 to 1.0
0.0-0.35 = Negative sentiment
0.35-0.65 = Neutral sentiment
0.65-1.0 = Positive sentiment
Attribute deepeval.sentiment.compound provides a -1 to +1 compound score for backward compatibility
Default OpenAI Usage
If you’re using OpenAI directly, no additional configuration is needed. Simply set OPENAI_API_KEY and the evaluator will work out of the box:
export OPENAI_API_KEY="sk-your-openai-api-key"
The custom DEEPEVAL_LLM_* environment variables described below are only needed when using a custom LLM provider (e.g., Azure OpenAI, private deployments, or API gateways). They do not affect the default OpenAI behavior.
Custom LLM Provider Configuration
Use these environment variables to configure a custom LLM endpoint (e.g., Azure OpenAI, private deployments, or LLM gateways). These settings are optional and only apply when DEEPEVAL_LLM_BASE_URL is set.
Required Dependency: Custom LLM provider support requires the litellm package:
pip install litellm
Basic Configuration:
Environment Variable |
Description |
|---|---|
DEEPEVAL_LLM_BASE_URL |
Custom LLM endpoint URL (required for custom providers) |
DEEPEVAL_LLM_MODEL |
Model name (default: gpt-4o-mini) |
DEEPEVAL_LLM_PROVIDER |
Provider identifier for model prefix (default: openai) |
DEEPEVAL_LLM_API_KEY |
Static API key (use this OR OAuth2, not both) |
DEEPEVAL_LLM_AUTH_HEADER |
Auth header name (default: api-key) |
DEEPEVAL_LLM_EXTRA_HEADERS |
JSON string of additional HTTP headers (see examples below) |
DEEPEVAL_LLM_CLIENT_APP_NAME |
App key/name passed in request body for some providers |
OAuth2 Authentication
For providers requiring OAuth2 token-based authentication:
Environment Variable |
Description |
|---|---|
DEEPEVAL_LLM_TOKEN_URL |
OAuth2 token endpoint (enables OAuth2 mode) |
DEEPEVAL_LLM_CLIENT_ID |
OAuth2 client ID |
DEEPEVAL_LLM_CLIENT_SECRET |
OAuth2 client secret |
DEEPEVAL_LLM_GRANT_TYPE |
OAuth2 grant type (default: client_credentials) |
DEEPEVAL_LLM_SCOPE |
OAuth2 scope (optional) |
DEEPEVAL_LLM_AUTH_METHOD |
Token auth method: basic (default) or post |
Examples
Static API Key (Azure OpenAI):
export DEEPEVAL_LLM_BASE_URL="https://your-resource.openai.azure.com/openai/deployments"
export DEEPEVAL_LLM_MODEL="gpt-4o"
export DEEPEVAL_LLM_PROVIDER="azure"
export DEEPEVAL_LLM_API_KEY="your-api-key"
OAuth2 with Basic Auth (Okta-style):
export DEEPEVAL_LLM_BASE_URL="https://llm-gateway.example.com/openai/deployments/gpt-4o-mini"
export DEEPEVAL_LLM_MODEL="gpt-4o-mini"
export DEEPEVAL_LLM_CLIENT_ID="your-client-id"
export DEEPEVAL_LLM_CLIENT_SECRET="your-client-secret"
export DEEPEVAL_LLM_TOKEN_URL="https://identity.example.com/oauth2/default/v1/token"
export DEEPEVAL_LLM_CLIENT_APP_NAME="your-app-key"
OAuth2 with Azure Active Directory:
export DEEPEVAL_LLM_BASE_URL="https://your-api.example.com/v1"
export DEEPEVAL_LLM_MODEL="gpt-4o"
export DEEPEVAL_LLM_PROVIDER="openai"
export DEEPEVAL_LLM_CLIENT_ID="azure-client-id"
export DEEPEVAL_LLM_CLIENT_SECRET="azure-client-secret"
export DEEPEVAL_LLM_TOKEN_URL="https://login.microsoftonline.com/tenant-id/oauth2/v2.0/token"
export DEEPEVAL_LLM_SCOPE="api://resource/.default"
export DEEPEVAL_LLM_AUTH_METHOD="post"
Custom Headers (for API gateways requiring additional headers):
# Add custom headers as JSON
export DEEPEVAL_LLM_EXTRA_HEADERS='{"system-code": "APP-123", "x-tenant-id": "tenant-abc"}'
# Combined with other settings
export DEEPEVAL_LLM_BASE_URL="https://gateway.example.com/openai/deployments"
export DEEPEVAL_LLM_MODEL="gpt-4o"
export DEEPEVAL_LLM_API_KEY="your-api-key"
export DEEPEVAL_LLM_EXTRA_HEADERS='{"system-code": "MYAPP-001"}'
The DEEPEVAL_LLM_EXTRA_HEADERS environment variable accepts a JSON-formatted string containing key-value pairs that will be added as HTTP headers to all LLM API requests. This is useful for API gateways that require custom headers for authentication or tracking.
Note: LiteLLM does not natively support setting extra_headers via environment variables (it must be passed programmatically). We provide DEEPEVAL_LLM_EXTRA_HEADERS to bridge this gap for DeepEval users who need custom headers without code changes. See LiteLLM SDK Header Support for more details on how headers work in LiteLLM.
Concurrent Evaluation Mode
For high-throughput evaluation scenarios, enable concurrent processing:
# Enable concurrent evaluation
export OTEL_INSTRUMENTATION_GENAI_EVALS_CONCURRENT=true
export OTEL_INSTRUMENTATION_GENAI_EVALS_WORKERS=4
# Optional: Bounded queue for backpressure
export OTEL_INSTRUMENTATION_GENAI_EVALS_QUEUE_SIZE=100
When concurrent mode is enabled:
Multiple worker threads process evaluations in parallel
DeepEval’s internal async mode is enabled (run_async=True)
Metrics within each invocation are evaluated concurrently (up to 10 parallel)
Significant throughput improvement for LLM-as-a-Judge evaluations
Important: When using concurrent mode, add a buffer wait time after your application’s main work completes to allow all evaluations to finish:
from opentelemetry.util.genai.handler import get_telemetry_handler
# ... your application code ...
handler = get_telemetry_handler()
handler.wait_for_evaluations(timeout=60) # Wait up to 60 seconds
Performance Considerations
Sequential Mode (default): Safe, ordered evaluation. Best for low-volume scenarios.
Concurrent Mode: 2-4x throughput improvement. Best for batch processing or high-volume scenarios.
Worker Count: Start with 4 workers, adjust based on LLM API rate limits.
Queue Size: Use bounded queue (e.g., 100-1000) to prevent memory exhaustion under load.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file splunk_otel_genai_evals_deepeval-0.1.13.tar.gz.
File metadata
- Download URL: splunk_otel_genai_evals_deepeval-0.1.13.tar.gz
- Upload date:
- Size: 35.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.3 cpython/3.11.14 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ce43662768e12c1fe279e160bfc73fc2bdc9b30f53c89a14ac05126c37b8c4a
|
|
| MD5 |
8b9d9ca97c61de48c788655a43b8439e
|
|
| BLAKE2b-256 |
d4d9843413daa35ba1a723472a5634749c4a36c9a0350d5a8606cb32d771aba2
|
File details
Details for the file splunk_otel_genai_evals_deepeval-0.1.13-py3-none-any.whl.
File metadata
- Download URL: splunk_otel_genai_evals_deepeval-0.1.13-py3-none-any.whl
- Upload date:
- Size: 30.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.3 cpython/3.11.14 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4133f080d9317aba8840051eb3b607e1d7b1a1474e1afcd1d9cae1ec32eb01b2
|
|
| MD5 |
bf221d65e3821ba5cb18c5de34abe9a8
|
|
| BLAKE2b-256 |
5e9094564eafbfb919cad80f3ec05830a1f02b59ac9b61c70bb45ca878be16da
|