mirror of
https://github.com/agentuniverse-ai/agentUniverse.git
synced 2026-02-09 01:59:19 +08:00
Feature: Add agent and tool span token count
This commit is contained in:
@@ -17,23 +17,26 @@
|
||||
| `au.agent.pair_id` | string | Agent 调用的配对 ID | `"agent-1234-5678"` |
|
||||
| `au.agent.duration` | float | Agent 执行总时长(秒) | `1.234` |
|
||||
| `au.agent.status` | string | Agent 执行状态 | `"success"` 或 `"error"` |
|
||||
| `au.agent.streaming` | bool | 是否流式 | `True` 或 `False`|
|
||||
|
||||
### 输入输出属性
|
||||
|
||||
| 属性名 | 类型 | 描述 |
|
||||
|--------|------|------|
|
||||
| `au.agent.input` | string | Agent 输入参数的 JSON 序列化 |
|
||||
| `au.agent.output` | string | Agent 输出结果的 JSON 序列化 |
|
||||
| `au.trace.caller_info` | string | 调用者信息的 JSON 序列化 |
|
||||
| `au.agent.first_token.duration` | float | 首个 token 响应时间(秒) |
|
||||
| 属性名 | 类型 | 描述 |
|
||||
|---------------------------------|------|----------------------|
|
||||
| `au.agent.input` | string | Agent 输入参数的 JSON 序列化 |
|
||||
| `au.agent.output` | string | Agent 输出结果的 JSON 序列化 |
|
||||
| `au.trace.caller_name` | string | 调用者名称 |
|
||||
| `au.trace.caller_type` | string | 调用者类型 |
|
||||
| `au.agent.first_token.duration` | float | 首个 token 响应时间(秒) |
|
||||
|
||||
### Token 使用属性
|
||||
|
||||
| 属性名 | 类型 | 描述 |
|
||||
|------------------------------------|------|--------------|
|
||||
| `au.agent.usage.prompt_tokens` | int | 提示词 token 数量 |
|
||||
| `au.agent.usage.completion_tokens` | int | 生成 token 数量 |
|
||||
| `au.agent.usage.total_tokens` | int | 总 token 数量 |
|
||||
| 属性名 | 类型 | 描述 |
|
||||
|--------------------------------|--------|---------------------|
|
||||
| `au.agent.usage.detail_tokens` | string | token消耗明细的 JSON 序列化 |
|
||||
| `au.agent.usage.prompt_tokens` | int | 提示词消耗token|
|
||||
| `au.agent.usage.completion_tokens`| int | 结果生成消耗token|
|
||||
| `au.agent.usage.total_tokens`| int | 总消耗token|
|
||||
|
||||
### 错误属性(仅在出错时设置)
|
||||
|
||||
@@ -55,20 +58,23 @@
|
||||
|
||||
### Histogram 直方图
|
||||
|
||||
| 指标名 | 类型 | 单位 | 描述 | 标签 |
|
||||
|------------------------------|------|------|------------------------|------|
|
||||
| `agent_call_duration` | Histogram | `s` | Agent 调用持续时间分布 | `agent_name`, `caller`, `streaming` |
|
||||
| `agent_first_token_duration` | Histogram | `s` | 首个 token 响应时间分布 | `agent_name`, `caller`, `streaming` |
|
||||
| `agent_total_tokens` | Histogram | `1` | Agent 调用总 token 数量分布 | `agent_name`, `caller`, `streaming` |
|
||||
| `agent_prompt_tokens` | Histogram | `1` | Agent 调用提示词 token 数量分布 | `agent_name`, `caller`, `streaming` |
|
||||
| `agent_completion_tokens` | Histogram | `1` | Agent 调用完成 token 数量分布 | `agent_name`, `caller`, `streaming` |
|
||||
| 指标名 | 类型 | 单位 | 描述 | 标签 |
|
||||
|------------------------------|------|------|--------------------------|------|
|
||||
| `agent_call_duration` | Histogram | `s` | Agent 调用持续时间分布 | `agent_name`, `caller`, `streaming` |
|
||||
| `agent_first_token_duration` | Histogram | `s` | 首个 token 响应时间分布 | `agent_name`, `caller`, `streaming` |
|
||||
| `agent_total_tokens` | Histogram | `1` | Agent 调用总 token 数量分布 | `agent_name`, `caller`, `streaming` |
|
||||
| `agent_prompt_tokens` | Histogram | `1` | Agent 调用提示词 token 数量分布 | `agent_name`, `caller`, `streaming` |
|
||||
| `agent_completion_tokens` | Histogram | `1` | Agent 调用完成 token 数量分布 | `agent_name`, `caller`, `streaming` |
|
||||
| `agent_cached_tokens` | Histogram | `1` | Agent 调用命中缓存 token 数量分布 | `agent_name`, `caller`, `streaming` |
|
||||
| `agent_reasoning_tokens` | Histogram | `1` | Agent 调用中模型思考 token 数量分布 | `agent_name`, `caller`, `streaming` |
|
||||
|
||||
### Metric 标签说明
|
||||
|
||||
| 标签名 | 描述 | 可能值 |
|
||||
|--------|------|--------|
|
||||
| `agent_name` | Agent 的名称 | 任意字符串 |
|
||||
| `caller` | 调用来源 | `"user"`, `"agent"`, 等 |
|
||||
| `streaming` | 是否为流式调用 | `true`, `false` |
|
||||
| `error_type` | 错误类型(仅错误指标) | 异常类名,如 `"ValueError"` |
|
||||
| 标签名 | 描述 | 可能值 |
|
||||
|------------------------|-----------|---------------------------------|
|
||||
| `au_agent_name` | Agent 的名称 | 任意字符串 |
|
||||
| `au_trace_caller_name` | 调用来源名称 | `"xxx_tool"`, `"xxx_agent"`, 等 |
|
||||
| `au_trace_caller_type` | 调用来源类型 | `"llm"`, `"agent"`, 等 |
|
||||
| `au_agent_streaming`| 是否为流式调用 | `true`, `false`|
|
||||
| `au_agent_status`| 状态标识 | `success`或异常类名,如 `"ValueError"` |
|
||||
|
||||
|
||||
@@ -8,30 +8,32 @@
|
||||
|
||||
### 基础属性
|
||||
|
||||
| 属性名 | 类型 | 描述 | 示例值 |
|
||||
|--------|------|------|-----------------------------|
|
||||
| `au.span.kind` | string | Span 类型标识 | `"llm"` |
|
||||
| `au.llm.name` | string | LLM 的名称 | `"gpt-4o"` |
|
||||
| 属性名 | 类型 | 描述 | 示例值 |
|
||||
|-----------------------|------|------|-----------------------------|
|
||||
| `au.span.kind` | string | Span 类型标识 | `"llm"` |
|
||||
| `au.llm.name` | string | LLM 的名称 | `"gpt-4o"` |
|
||||
| `au.llm.channel_name` | string | LLM 通道名称 | `"openai_official_channel"` |
|
||||
| `au.llm.duration` | float | LLM 执行总时长(秒) | `1.234` |
|
||||
| `au.llm.status` | string | LLM 执行状态 | `"success"` 或 `"error"` |
|
||||
|
||||
| `au.llm.duration` | float | LLM 执行总时长(秒) | `1.234` |
|
||||
| `au.llm.status` | string | LLM 执行状态 | `"success"` 或 `"error"` |
|
||||
| `au.llm.streaming` | bool | 是否流式 | `True` 或 `False`|
|
||||
### 输入输出属性
|
||||
|
||||
| 属性名 | 类型 | 描述 |
|
||||
|--------|------|------|
|
||||
| `au.llm.input` | string | LLM 输入参数的 JSON 序列化 |
|
||||
| `au.llm.llm_params` | string | LLM 参数配置的 JSON 序列化 |
|
||||
| `au.trace.caller_info` | string | 调用者信息的 JSON 序列化 |
|
||||
| `au.trace.caller_name` | string | 调用者名称 |
|
||||
| `au.trace.caller_type` | string | 调用者类型 |
|
||||
| `au.llm.first_token.duration` | float | 首个 token 响应时间(秒) |
|
||||
|
||||
### Token 使用属性
|
||||
|
||||
| 属性名 | 类型 | 描述 |
|
||||
|--------|------|--------------|
|
||||
| `au.llm.usage.prompt_tokens` | int | 提示词 token 数量 |
|
||||
| `au.llm.usage.completion_tokens` | int | 生成 token 数量 |
|
||||
| `au.llm.usage.total_tokens` | int | 总 token 数量 |
|
||||
| 属性名 | 类型 | 描述 |
|
||||
|----------------------------------|--------|---------------------|
|
||||
| `au.llm.usage.detail_tokens` | string | token消耗明细的 JSON 序列化 |
|
||||
| `au.llm.usage.prompt_tokens` | int | 提示词消耗token|
|
||||
| `au.llm.usage.completion_tokens`| int | 结果生成消耗token|
|
||||
| `au.llm.usage.total_tokens`| int | 总消耗token|
|
||||
|
||||
### 错误属性(仅在出错时设置)
|
||||
|
||||
@@ -53,80 +55,24 @@
|
||||
|
||||
### Histogram 直方图
|
||||
|
||||
| 指标名 | 类型 | 单位 | 描述 | 标签 |
|
||||
|--------|------|------|------|------|
|
||||
| `llm_call_duration` | Histogram | `s` | LLM 调用持续时间分布 | `llm_name`, `channel_name`, `caller` |
|
||||
| `llm_first_token_duration` | Histogram | `s` | 首个 token 响应时间分布 | `llm_name`, `channel_name`, `caller`, `streaming` |
|
||||
| `llm_total_tokens` | Histogram | `1` | LLM 调用总 token 数量分布 | `llm_name`, `channel_name`, `caller` |
|
||||
| `llm_prompt_tokens` | Histogram | `1` | LLM 调用提示词 token 数量分布 | `llm_name`, `channel_name`, `caller` |
|
||||
| `llm_completion_tokens` | Histogram | `1` | LLM 调用完成 token 数量分布 | `llm_name`, `channel_name`, `caller` |
|
||||
| 指标名 | 类型 | 单位 | 描述 | 标签 |
|
||||
|----------------------------|------|------|------------------------|------|
|
||||
| `llm_call_duration` | Histogram | `s` | LLM 调用持续时间分布 | `llm_name`, `channel_name`, `caller` |
|
||||
| `llm_first_token_duration` | Histogram | `s` | 首个 token 响应时间分布 | `llm_name`, `channel_name`, `caller`, `streaming` |
|
||||
| `llm_total_tokens` | Histogram | `1` | LLM 调用总 token 数量分布 | `llm_name`, `channel_name`, `caller` |
|
||||
| `llm_prompt_tokens` | Histogram | `1` | LLM 调用提示词 token 数量分布 | `llm_name`, `channel_name`, `caller` |
|
||||
| `llm_completion_tokens` | Histogram | `1` | LLM 调用完成 token 数量分布 | `llm_name`, `channel_name`, `caller` |
|
||||
| `llm_cached_tokens` | Histogram | `1` | LLM 调用命中缓存 token 数量分布 | `agent_name`, `caller`, `streaming` |
|
||||
| `llm_reasoning_tokens` | Histogram | `1` | LLM 调用中模型思考 token 数量分布 | `agent_name`, `caller`, `streaming` |
|
||||
|
||||
### Metric 标签说明
|
||||
|
||||
| 标签名 | 描述 | 可能值 |
|
||||
|--------|------|--------|
|
||||
| `llm_name` | LLM 的名称 | 任意字符串 |
|
||||
| `channel_name` | LLM 通道名称 | 任意字符串 |
|
||||
| `caller` | 调用来源 | `"user"`, `"agent"`, 等 |
|
||||
| `streaming` | 是否为流式调用 | `true`, `false` |
|
||||
| `error_type` | 错误类型(仅错误指标) | 异常类名,如 `"ValueError"` |
|
||||
| `au_llm_name` | LLM 的名称 | 任意字符串 |
|
||||
| `au_llm_channel_name` | LLM 通道名称 | 任意字符串 |
|
||||
| `au_trace_caller_name` | 调用来源名称| `"xxx_tool"`, `"xxx_agent"`, 等 |
|
||||
| `au_trace_caller_type` | 调用来源类型| `"llm"`, `"agent"`, 等 |
|
||||
| `au_llm_streaming` | 是否为流式调用 | `true`, `false` |
|
||||
| `au_llm_status` | 状态标识 | 异常类名,如 `"ValueError"` |
|
||||
|
||||
## 常量定义
|
||||
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
# @Time : 2025/6/10 15:01
|
||||
# @Author : fanen.lhy
|
||||
# @Email : fanen.lhy@antgroup.com
|
||||
# @FileName: consts.py
|
||||
|
||||
INSTRUMENTOR_NAME = "opentelemetry-instrumentation-agentuniverse-llm"
|
||||
INSTRUMENTOR_VERSION = "0.1.0"
|
||||
|
||||
# Metric names
|
||||
class MetricNames:
|
||||
"""Metric name constants."""
|
||||
LLM_CALLS_TOTAL = "llm_calls_total"
|
||||
LLM_ERRORS_TOTAL = "llm_errors_total"
|
||||
LLM_CALL_DURATION = "llm_call_duration"
|
||||
LLM_FIRST_TOKEN_DURATION = "llm_first_token_duration"
|
||||
LLM_TOTAL_TOKENS = "llm_total_tokens"
|
||||
LLM_PROMPT_TOKENS = "llm_prompt_tokens"
|
||||
LLM_COMPLETION_TOKENS = "llm_completion_tokens"
|
||||
|
||||
# Span attribute names
|
||||
class SpanAttributes:
|
||||
"""Span attribute name constants."""
|
||||
# Basic span attributes
|
||||
SPAN_KIND = "au.span.kind"
|
||||
AU_LLM_NAME = "au.llm.name"
|
||||
AU_LLM_CHANNEL_NAME = "au.llm.channel_name"
|
||||
AU_LLM_INPUT = "au.llm.input"
|
||||
AU_LLM_LLM_PARAMS = "au.llm.llm_params"
|
||||
AU_TRACE_CALLER_INFO = "au.trace.caller_info"
|
||||
|
||||
# Status and timing attributes
|
||||
AU_LLM_DURATION = "au.llm.duration"
|
||||
AU_LLM_STATUS = "au.llm.status"
|
||||
AU_LLM_FIRST_TOKEN_DURATION = "au.llm.first_token.duration"
|
||||
|
||||
# Token usage attributes
|
||||
AU_LLM_USAGE_PROMPT_TOKENS = "au.llm.usage.prompt_tokens"
|
||||
AU_LLM_USAGE_COMPLETION_TOKENS = "au.llm.usage.completion_tokens"
|
||||
AU_LLM_USAGE_TOTAL_TOKENS = "au.llm.usage.total_tokens"
|
||||
|
||||
# Error attributes
|
||||
AU_LLM_ERROR_TYPE = "au.llm.error.type"
|
||||
AU_LLM_ERROR_MESSAGE = "au.llm.error.message"
|
||||
|
||||
# Metric label names
|
||||
class MetricLabels:
|
||||
"""Metric label name constants."""
|
||||
ERROR_TYPE = "error_type"
|
||||
STREAMING = "streaming"
|
||||
LLM_NAME = "llm_name"
|
||||
CHANNEL_NAME = "channel_name"
|
||||
CALLER = "caller"
|
||||
```
|
||||
|
||||
@@ -22,15 +22,17 @@
|
||||
|--------|------|------|
|
||||
| `au.tool.input` | string | Tool 输入参数的 JSON 序列化 |
|
||||
| `au.tool.output` | string | Tool 输出结果的 JSON 序列化 |
|
||||
| `au.trace.caller_info` | string | 调用者信息的 JSON 序列化 |
|
||||
| `au.trace.caller_name` | string | 调用者名称 |
|
||||
| `au.trace.caller_type` | string | 调用者类型 |
|
||||
|
||||
### Token 使用属性
|
||||
|
||||
| 属性名 | 类型 | 描述 |
|
||||
|-----------------------------------|------|--------------|
|
||||
| `au.tool.usage.prompt_tokens` | int | 提示词 token 数量 |
|
||||
| `au.tool.usage.completion_tokens` | int | 生成 token 数量 |
|
||||
| `au.tool.usage.total_tokens` | int | 总 token 数量 |
|
||||
| 属性名 | 类型 | 描述 |
|
||||
|------------------------------------|------|--------------|
|
||||
| `au.tool.usage.detail_tokens` | string | token消耗明细的 JSON 序列化 |
|
||||
| `au.tool.usage.prompt_tokens` | int | 提示词消耗token|
|
||||
| `au.tool.usage.completion_tokens` | int | 结果生成消耗token|
|
||||
| `au.tool.usage.total_tokens` | int | 总消耗token|
|
||||
|
||||
### 错误属性(仅在出错时设置)
|
||||
|
||||
@@ -52,18 +54,21 @@
|
||||
|
||||
### Histogram 直方图
|
||||
|
||||
| 指标名 | 类型 | 单位 | 描述 | 标签 |
|
||||
|--------------------------|------|------|------------------------|------|
|
||||
| `tool_call_duration` | Histogram | `s` | Tool 调用持续时间分布 | `tool_name`, `caller` |
|
||||
| `tool_total_tokens` | Histogram | `1` | Tool 调用总 token 数量分布 | `tool_name`, `caller` |
|
||||
| `tool_prompt_tokens` | Histogram | `1` | Tool 调用提示词 token 数量分布 | `tool_name`, `caller` |
|
||||
| `tool_completion_tokens` | Histogram | `1` | Tool 调用完成 token 数量分布 | `tool_name`, `caller` |
|
||||
| 指标名 | 类型 | 单位 | 描述 | 标签 |
|
||||
|--------------------------|------|------|-------------------------|------|
|
||||
| `tool_call_duration` | Histogram | `s` | Tool 调用持续时间分布 | `tool_name`, `caller` |
|
||||
| `tool_total_tokens` | Histogram | `1` | Tool 调用总 token 数量分布 | `tool_name`, `caller` |
|
||||
| `tool_prompt_tokens` | Histogram | `1` | Tool 调用提示词 token 数量分布 | `tool_name`, `caller` |
|
||||
| `tool_completion_tokens` | Histogram | `1` | Tool 调用完成 token 数量分布 | `tool_name`, `caller` |
|
||||
| `tool_cached_tokens` | Histogram | `1` | Tool 调用命中缓存 token 数量分布 | `agent_name`, `caller`, `streaming` |
|
||||
| `tool_reasoning_tokens` | Histogram | `1` | Tool 调用中模型思考 token 数量分布 | `agent_name`, `caller`, `streaming` |
|
||||
|
||||
### Metric 标签说明
|
||||
|
||||
| 标签名 | 描述 | 可能值 |
|
||||
|--------|------|--------|
|
||||
| `tool_name` | Tool 的名称 | 任意字符串 |
|
||||
| `caller` | 调用来源 | `"user"`, `"agent"`, 等 |
|
||||
| `error_type` | 错误类型(仅错误指标) | 异常类名,如 `"ValueError"` |
|
||||
| `au_tool_name` | Tool 的名称 | 任意字符串 |
|
||||
| `au_trace_caller_name` | 调用来源名称 | `"xxx_tool"`, `"xxx_agent"`, 等 |
|
||||
| `au_trace_caller_type` | 调用来源类型 | `"llm"`, `"agent"`, 等 |
|
||||
| `au_tool_status`| 状态标识 | `success`或异常类名,如 `"ValueError"` |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user