TraceVerde
用于LLM/GenAI应用程序的最全面的OpenTetry自动仪器库
*来自OpenTetry跟踪的跟踪。Verde的意思是绿色——可持续、透明的人工智能可观察性。*
](https://badge.fury.io/py/genai-otel-instrument) ](https://pypi.org/project/genai-otel-instrument/)  ](https://pepy.tech/project/genai-otel-instrument) ](https://pepy.tech/project/genai-otel-instrument) ](https://github.com/Mandark-droid/genai_otel_instrument)  
______________________________________________________________________
30秒内开始
pip install genai-otel-instrumentimport genai_otel
genai_otel.instrument()
# Your existing code works unchanged - traces, metrics, and costs are captured automatically
import openai
client = openai.OpenAI()
response = client.chat.completions.create(model="gpt-4o-mini", messages=[{"role": "user", "content": "Hello!"}])就是这样。没有包装器,没有装饰器,没有配置文件。每个LLM调用、数据库查询和代理交互都会自动跟踪并提供完整的成本明细。
为什么选择TraceVerde?
| 功能 | TraceVerde | OpenLIT | Traceloop/OpenLLMetric | Langfuse |
|---|---|---|---|---|
| 零代码设置 | 是 | 是 | 有 | 需要SDK |
| 法学硕士提供者 | 19+ | 25+ | 15+ | 通过集成 |
| 多代理框架 | 8(CrewAI、LangGraph、ADK、AutoGen、OpenAI代理、Pydantic AI等) | 有限 | 有限 | |
| 成本跟踪 | 自动(1050+型号) | 手动配置 | 手动配置 | |
| GPU指标(NVIDIA+AMD) | 是 | 否 | 否 | 不 |
| MCP工具检测 | 是(数据库、缓存、矢量数据库、队列) | 有限 | 有限 | 否 |
| 评估(PII、毒性、偏见、幻觉、及时注射) | 内置(6个探测器) | 否 | 否 | 单独服务 |
| OpenTetry原生 | 是 | 是 | 部分 | |
| 许可证 | Apache-2.0 | Apache-2.0 | Apache-2.0 | 麻省理工学院 |
什么被工具化了?
法学硕士提供者(19+)
OpenAI、OpenRouter、Anthropic、Google AI、Google GenAI、AWS Bedrock、Azure OpenAI、Cohere、Mistral AI、Together AI、Groq、Ollama、Vertex AI、Replicate、HuggingFace、SambaNova、Sarvam AI、双曲线、LiteLLM
多代理框架(8)
CrewAI、LangGraph、Google ADK、AutoGen、AutoGen AgentChat、OpenAI代理SDK、Pydantic AI、AWS基岩代理
MCP工具(20+)
数据库: PostgreSQL、MySQL、MongoDB、SQLAlchemy、TimescaleDB、OpenSearch、Elasticsearch、FalkorDB 缓存: Redis| 队列: 卡夫卡,拉比MQ| 储存: MinIO 矢量数据库: 松果、Weaviate、Qdrant、ChromaDB、Milvus、FAISS、LanceDB
内置评估(6个探测器)
PII检测(DSGVO/HIPAA/PCI-DSS)、毒性检测、偏差检测、快速注射检测、限制主题、致幻剂检测
截图
OpenAI traces with token usage, costs, and latency
More screenshots
Ollama(当地LLM)
SmolAgents与工具调用
GPU指标
OpenSearch仪表板
主要特点
自动成本跟踪
30多家供应商的1050多种型号,按请求成本细分。支持差别定价(提示与完成)、推理令牌、缓存定价和自定义模型定价。
# Cost tracking is enabled by default - just instrument and go
genai_otel.instrument()
# Or add custom pricing for proprietary models
export GENAI_CUSTOM_PRICING_JSON='{"chat":{"my-model":{"promptPrice":0.001,"completionPrice":0.002}}}'GPU指标(NVIDIA+AMD)
实时监控利用率、内存、温度、功率、PCIe吞吐量、节流和ECC错误。包括多GPU聚合指标。
pip install genai-otel-instrument[gpu] # NVIDIA
pip install genai-otel-instrument[amd-gpu] # AMD多代理跟踪
具有自动上下文传播的代理框架的完整跨度层次结构:
Crew Execution
+-- Agent: Senior Researcher (gpt-4)
| +-- Task: Research OpenTelemetry
| +-- openai.chat.completions (tokens: 1250, cost: $0.03)
+-- Agent: Technical Writer (ollama:llama2)
+-- Task: Write blog post
+-- ollama.chat (tokens: 890, cost: $0.00)多模态可观测性(v1.1.0)
上的图像、音频、视频和文档内容部分的一流捕获 OpenAI、Anthropic、谷歌Gemini和Groq的跨度。字节已卸载到您的 配置的对象存储(MinIO/S3/文件系统/HTTP),并从引用 span by URI——它们永远不会内联出现在span属性中。
# Opt in (default is off — text-only behaviour is byte-identical to 1.0.x)
export GENAI_OTEL_MEDIA_CAPTURE_MODE=full
export GENAI_OTEL_MEDIA_STORE=minio
export GENAI_OTEL_MEDIA_STORE_ENDPOINT=http://localhost:9000
export GENAI_OTEL_MEDIA_STORE_ACCESS_KEY=...
export GENAI_OTEL_MEDIA_STORE_SECRET_KEY=...
# Optional: plug in a redactor before upload
export GENAI_OTEL_MEDIA_REDACTOR=genai_otel.media.redactors.face_blurSpans得到相同多模态内容的两个共同发射表示:
- A. 扁平的、可查询的属性名称空间 —
gen_ai.prompt.{n}.content.{m}.{type, media_uri, media_mime_type, media_byte_size, media_source}加上agen_ai.completion.*镜像——用于索引平面属性的后端。
安全与评估
genai_otel.instrument(
enable_pii_detection=True, # GDPR/HIPAA/PCI-DSS compliance
enable_toxicity_detection=True, # Perspective API + Detoxify
enable_bias_detection=True, # 8 bias categories
enable_prompt_injection_detection=True,
enable_hallucination_detection=True,
enable_restricted_topics=True,
)配置
# Required
export OTEL_SERVICE_NAME=my-llm-app
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
# Optional
export GENAI_ENABLE_GPU_METRICS=true
export GENAI_ENABLE_COST_TRACKING=true
export GENAI_SAMPLING_RATE=0.5 # Reduce volume in production
export GENAI_ENABLED_INSTRUMENTORS=openai,crewai # Select specific instrumentors后端集成
适用于任何与OpenTetry兼容的后端:
Jaeger、Zipkin、Prometheus、Grafana、Datadog、New Relic、Honeycomb、AWS X-Ray、Google Cloud Trace、Elastic APM、Splunk、SigNoz、自托管OTel收集器
预建 Grafana仪表板模板 包括。
示例
90多个现成的示例,涵盖了每个提供者、框架和评估功能:
examples/
+-- openai/ # OpenAI chat, embeddings
+-- anthropic/ # Anthropic + PII/toxicity detection
+-- ollama/ # Local models + all evaluation features
+-- crewai_example.py # Multi-agent crew orchestration
+-- langgraph_example.py # Stateful graph workflows
+-- google_adk_example.py # Google Agent Development Kit
+-- autogen_example.py # Microsoft AutoGen agents
+-- pii_detection/ # 10 PII examples (GDPR, HIPAA, PCI-DSS)
+-- toxicity_detection/ # 8 toxicity examples
+-- bias_detection/ # 8 bias examples (hiring compliance, etc.)
+-- prompt_injection/ # 6 injection defense examples
+-- hallucination/ # 4 hallucination detection examples
+-- ... # And many more开放遥测标准贡献
TraceVerde不仅是OpenTetry GenAI语义约定的消费者,而且该库发现的生产差距正在向上游反馈到规范中 open-telemetry/semantic-conventions-genai:
| PR | 提案 | 状态 |
|---|---|---|
| #142 | 添加 document 到 Modality 枚举on BlobPart / FilePart / UriPart --PDF、DOCX和其他非图像/视频/音频有效载荷目前采用自由格式 string 支。BFSI KYC提取是一个大容量的真实例子。 | 已批准(@MikeGoldsmith) |
| #143 | 添加可选 byte_size 在三种媒体部分类型上,这样消费者就可以统一处理有效载荷大小,无论内容是内联、URI还是提供者文件id,这对捕获遥测和存储规划的成本都很有用。派丹蒂克 ge=0 → JSON 模式 "minimum": 0. | 正在审查中 |
| #144 | Make content / file_id / uri 可选并添加自由格式 stripped_reason (size_exceeded, modality_not_allowed, redactor_error, upload_error, no_store_configured)因此,仪器可以失败关闭——记录它观察到媒体部分,但故意不捕获其字节——同时保留原始部分 type 和 modality.通过高层强制执行 anyOf 因此,结构上的空部件无法验证。 | 正在审查中 |
这三个人都是从封闭的 open-telemetry/semantic-conventions#3673 在GenAI约定于2026年5月5日拆分为专用仓库之后。每个PR都在新回购的V2 Weaver模式下发布,并带有相应的 models.ipynb 更新和 make check-policies / make generate-all 验证。
TraceVerde v1.1.1已经通过双发射在导线上发射了所提出的形状(OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai),为这些公约的实施提供参考。
谁在使用TraceVerde?
TraceVerde被开发人员和团队用于构建生产GenAI应用程序。如果您正在使用TraceVerde,我们很乐意收到您的来信!
社区
- 文档 -完整指南、API参考资料和教程
- Discord 的中文翻译是“不和谐”或“纷争”。 -与社区聊天
- -Bug报告和功能请求
- 贡献 -如何做出贡献
许可证
版权所有2025 Kshitij Thakkar。根据 Apache许可证2.0.
