查询 LLM span 列表
更新时间:2026-06-26
DescribeLLMSpans
查询LLM Span列表,支持按时间范围、过滤条件和排序方式获取Span数据,支持翻页。
API Explorer
去调试
您可以在 API Explorer 中直接运行该接口,免去您计算签名的困扰。运行成功后,API Explorer 可以自动生成 SDK 代码示例。
请求结构
Plain Text
1POST /v1/apm/query?action=DescribeLLMSpans HTTP/1.1
2Host: apm.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "beginDatetime": "20241011T10:10:10Z",
7 "endDatetime": "20241011T10:25:10Z",
8 "parseLLMInputOutput": false,
9 "filters": [
10 {
11 "key": "service",
12 "op": "=",
13 "value": "mall-gateway",
14 "values": []
15 }
16 ],
17 "orderBy": "startTime",
18 "order": "desc",
19 "marker": ""
20}
请求头域
除公共头域外,无其他特殊头域
请求参数
| 参数名称 | 类型 | 是否必需 | 参数位置 | 描述 |
|---|---|---|---|---|
| version | String | 是 | URL参数 | API版本号,当前取值为v1 |
| beginDatetime | String | 是 | RequestBody参数 | 开始时间,UTC时间 |
| endDatetime | String | 是 | RequestBody参数 | 结束时间,UTC时间 |
| parseLLMInputOutput | Boolean | 否 | RequestBody参数 | 是否填充gen_ai.input和gen_ai.output字段,默认false |
| filters | List<Filter> | 否 | RequestBody参数 | 过滤项列表。支持的过滤字段:service(应用名称)、host(实例名称)、duration(响应时间,单位us)、traceId(TraceID)、statusCode(Span状态码)、hasException(是否存在异常)、exception.type(异常类型)、attributes.apm.operation(接口)、attributes.apm.component(请求类型)、attributes.gen_ai.kind(span类型)、attributes.gen_ai.response.model(模型名称) |
| orderBy | String | 否 | RequestBody参数 | 排序字段,默认值:startTime,可选项:startTime(开始时间) |
| order | String | 否 | RequestBody参数 | 排序方向,可选值:asc(升序)、desc(降序) |
| marker | String | 否 | RequestBody参数 | 翻页游标。请求第一页时填空,请求后续页时使用上一页返回的nextMarker值 |
返回状态码
成功返回200,失败返回见错误码
返回头域
除公共头域外,无其他特殊头域
返回参数
| 参数名称 | 类型 | 描述 |
|---|---|---|
| success | Boolean | 请求是否成功 |
| code | String | 状态码 |
| message | String | 错误信息 |
| spans | List<LLMSpan> | Span列表 |
| nextMarker | String | 翻页游标,用于填充下一页请求中的marker参数 |
| isTruncated | Boolean | 是否还有下一页,true表示还有下一页,false表示已是最后一页 |
请求示例
Plain Text
1POST /v1/apm/query?action=DescribeLLMSpans HTTP/1.1
2HOST apm.bj.baidubce.com
3Authorization bce-auth-v1/...
4
5{
6 "beginDatetime": "20241011T10:10:10Z",
7 "endDatetime": "20241011T10:25:10Z",
8 "parseLLMInputOutput": false,
9 "filters": [
10 {
11 "key": "service",
12 "op": "=",
13 "value": "mall-gateway"
14 }
15 ],
16 "orderBy": "startTime",
17 "order": "desc",
18 "marker": ""
19}
响应示例
Plain Text
1HTTP/1.1 200 OK
2x-bce-request-id: request-id-example
3Date: Wed, 08 Jan 2025 03:25:48 GMT
4Transfer-Encoding: chunked
5Content-Type: application/json;charset=UTF-8
6Server: BWS
7
8{
9 "success": true,
10 "code": "OK",
11 "message": "",
12 "spans": [
13 {
14 "traceId": "255e69731af9f35845d453d0c321e42e",
15 "spanId": "90c0800ffbf8a363",
16 "parentSpanId": "59568a6558c9aae8",
17 "name": "ChatOpenAI.chat",
18 "service": "chatApp",
19 "start": 1737098708489438,
20 "end": 1737098708492651,
21 "duration": 3213,
22 "host": "192.168.0.1",
23 "statusCode": "STATUS_CODE_OK",
24 "kind": "SPAN_KIND_SERVER",
25 "input": {
26 "content": "",
27 "contentRef": ["attributes", "traceloop.entity.input", "inputs"]
28 },
29 "output": {
30 "content": "",
31 "contentRef": ["attributes", "traceloop.entity.output", "outputs"]
32 },
33 "attributes": {
34 "apm.component": "http",
35 "apm.operation": "GET /images/products/SolarFilter.jpg",
36 "gen_ai.kind": "workflow",
37 "gen_ai.response.model": "ernie-4.0-turbo-128k",
38 "llm.usage.total_tokens": 7039,
39 "gen_ai.usage.prompt_tokens": 6988,
40 "gen_ai.usage.completion_tokens": 51
41 },
42 "resource": {
43 "host.arch": "arm64",
44 "os.type": "linux"
45 },
46 "events": [
47 {
48 "name": "exception",
49 "timestamp": 1739845445753267500,
50 "attributes": {
51 "exception.type": "com.netflix.HystrixBadRequestException",
52 "exception.message": "Retrieve Nova for vm detail information failed",
53 "exception.stacktrace": "com.netflix.HystrixBadRequestException: Retrieve ..."
54 }
55 }
56 ]
57 }
58 ],
59 "nextMarker": "diVSUvI4/p9d+6xR4/+YQDJ18ojyOP6X",
60 "isTruncated": true
61}
评价此篇文章
