OpenTelemetry GenAI Utils
Project description
Minimal Overview
Utility function to provide APIs and data types to ease instrumentation of Generative AI workloads using OpenTelemetry semantic conventions.
Example usage for LLM Invocation.
from opentelemetry.util.genai.handler import get_telemetry_handler
handler = get_telemetry_handler()
user_input = "Hello"
inv = LLMInvocation(request_model="gpt-5-nano", provider="openai",
input_messages=[InputMessage(role="user", parts=[Text(user_input)])])
handler.start_llm(inv)
# your code which actuall invokes llm here
# response = client.chat.completions.create(...)
# ....
inv.output_messages = [OutputMessage(role="assistant", parts=[Text("Hi!")], finish_reason="stop")]
handler.stop_llm(inv)
See the example in examples/agentic_example.py for a full agent + LLM invocation flow.
Error Classification & Interrupts
The Error dataclass includes a classification field (ErrorClassification enum: REAL_ERROR, INTERRUPT, CANCELLATION) that controls span status behavior. Interrupts and cancellations leave span status as UNSET (default) instead of setting StatusCode.ERROR, preventing false-positive alerts for expected control-flow exceptions like LangGraph’s GraphInterrupt.
Concurrent Evaluation Mode
For high-throughput LLM-as-a-Judge evaluations, enable concurrent processing:
# Enable concurrent evaluation with 4 workers
export OTEL_INSTRUMENTATION_GENAI_EVALS_CONCURRENT=true
export OTEL_INSTRUMENTATION_GENAI_EVALS_WORKERS=4
# Optional: Set bounded queue for backpressure
export OTEL_INSTRUMENTATION_GENAI_EVALS_QUEUE_SIZE=100
Configuration options:
OTEL_INSTRUMENTATION_GENAI_EVALS_CONCURRENT - Enable concurrent mode (default: false)
OTEL_INSTRUMENTATION_GENAI_EVALS_WORKERS - Number of worker threads (default: 4)
OTEL_INSTRUMENTATION_GENAI_EVALS_QUEUE_SIZE - Bounded queue size, 0 for unbounded (default: 0)
Concurrent mode processes multiple evaluations in parallel, significantly improving throughput when using LLM-as-a-Judge metrics like DeepEval’s Bias, Toxicity, and Answer Relevancy.
Metrics
This library emits histogram metrics with explicit bucket boundaries per OpenTelemetry GenAI semantic conventions:
Duration Metrics (unit: seconds)
gen_ai.client.operation.duration - Duration of GenAI client operations
gen_ai.workflow.duration - Duration of GenAI workflows
gen_ai.agent.duration - Duration of agent operations
Bucket boundaries: [0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24, 20.48, 40.96, 81.92]
Token Usage Metrics (unit: tokens)
gen_ai.client.token.usage - Number of input and output tokens used
Bucket boundaries: [1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 67108864]
Evaluation Metrics (unit: score 0-1)
gen_ai.evaluation.score - GenAI evaluation score (default, when OTEL_INSTRUMENTATION_GENAI_EVALS_USE_SINGLE_METRIC is unset or true)
gen_ai.evaluation.<name> - Individual evaluation metrics (when OTEL_INSTRUMENTATION_GENAI_EVALS_USE_SINGLE_METRIC=false)
Bucket boundaries: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
Further Documentation
For architecture, design rationale, and broader usage patterns please consult: * Core concepts, high-level usage and setup * README.packages.architecture.md – extensibility architecture & emitter pipeline design.
Those documents cover configuration (environment variables, content capture modes, evaluation emission, extensibility via entry points) and release/stability notes.
Support & Stability
GenAI semantic conventions are incubating.
License
Apache 2.0 (see LICENSE).
Project details
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_util_genai-0.1.11.tar.gz.
File metadata
- Download URL: splunk_otel_util_genai-0.1.11.tar.gz
- Upload date:
- Size: 91.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.11.15 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cf53c1e40398591c0c973cc1a7542b842ad9eb86024921fd8efbc03d86a3257
|
|
| MD5 |
41a9a0871ff8cf5fad95a637d7bc0052
|
|
| BLAKE2b-256 |
93c7e2b531ee92659c551348d5de3ffb9e049a3cc3cd7d3b589d8a8a1ce201d7
|
File details
Details for the file splunk_otel_util_genai-0.1.11-py3-none-any.whl.
File metadata
- Download URL: splunk_otel_util_genai-0.1.11-py3-none-any.whl
- Upload date:
- Size: 77.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.11.15 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee0104d4f97d007200e912cf4937d0a4eedac16970e457b4f1440882afa6760a
|
|
| MD5 |
05690632d01d71c3667fd0ff46380b28
|
|
| BLAKE2b-256 |
078792517d1aa73d05c3bf0d002ab49e3367757fe5471eb03a4d30bea02f504a
|