OpenTelemetry上报协议标准

最近更新时间:2024-04-22 17:03:11

我的收藏
说明:
以下加粗字体为目前正在使用中的字段。

Span 基础字段

字段名
类型
参数说明
例子
是否必要
需要手动埋点
Name
string
调用操作
(接口名/执行语句等)
/api/v1/auth
-
TraceId
bytes
链路 ID
e4a230f901100099f3bf34faf75284c4
-
SpanId
bytes
SpanID
5053f7cfe6dc50c1
-
TraceState
string
w3标准
""
-
SpanKind
int
包括以下类型: 0(未定义 Span) 1(内部 Span) 2(服务端侧 Span) 3(客户端侧 Span) 4(生产者 Span) 5(消费者 Span)
2
-
StartTime
int64
开始时间戳
1692693930485000000
-
EndTime
int64
结束时间戳
1692693930485000000
-
Status.Code
string
包括以下类型:
Unset(未定义)
Ok(正常)
Error(异常)
Unset
-
ParentSpanId
bytes
父 Span ID
5053f7cfe6dc50c1
-
Attributes
[]KeyValue
span标签
""
-

通用标签

字段名
类型
参数说明
例子
是否必要
需要手动上报
手动埋点位置
service.name
string
当前服务名
tapm-api
1
resource.attributes
service.instance
string
当前服务实例
127.0.0.1
1
resource.attributes
component
string
组件类型
http
-
-
token
string
apm 鉴权
xxx
-
-
net.host.name
string
Host端名称
gin-demo
1
span.attributes
net.host.port
string
请求端口
8080
-
-
net.sock.peer.addr
string
远端服务端地址
::1
-
-
net.sock.peer.port
string
远端服务端口
57719
-
-
net.peer.ip
string
IPv4 地址
127.0.0.1
-
-
net.peer.port
int
当前实例端口
8080
-
-
sampling.priorty
int
采样策略
1
-
-
peer.instance
string
远端服务实例
HTTP→ip+port
-
-
peer.service
string
远端服务名
tapm-collector
-
-
peer.address
string
远端地址
127.0.0.1:8080
-
-
peer.hostname
string
远端域名
opentracing.io
-
-
peer.ipv6
string
IPv6 地址
2001:0db8:85a3:0000:0000:8a2e:0370:7334
-
-
peer.port
int
远端端口
8080
-
-

Http 服务

http.*
字段名
类型
参数说明
例子
是否必要
需要手动埋点
手动埋点位置
http.status_code
int
Http 返回状态码
200
-
-
http.scheme
string
URL 协议
https
-
-
http.flavor
string
Http 协议版本
1.0
-
-
http.method
string
Http 方法
GET
-
-
http.route
string
请求路由映射
/users
-
-
http.url
string
完整请求地址
https://domain.net/path/to?resource=here
-
-
http.target
string
请求地址 URL
/path/to?resource=here
-
-
http.host
string
请求域名 IP 地址+host
domain.net
-
-
http.user_agent
string
CERN-LineMode/2.15
-
-
http.request_content_length
int
请求体长度(压缩后)
3495
-
-
http.request_content_length_uncompressed
int
请求体长度(未压缩)
5493
-
-
http.response_content_length
int
返回体长度(压缩后)
3495
-
-
http.response_content_length_uncompressed
int
返回体长度(未压缩)
5493
-
-
http.server_name
string
服务名
example.com
-
-
http.client_ip
string
客户端地址
83.164.160.102
-
-

Rpc 服务

rpc.*
字段名
类型
参数说明
例子
是否必要
需要手动上报
手动埋点位置
rpc.method
string
接口方法名
SayHello
-
span.attributes
rpc.service
string
接口服务名
proto.HelloService
-
span.attributes
rpc.system
string
RPC 系统
gRPC
-
span.attributes
rpc.grpc.status_code
int
gRPC 调用状态码
0
-
span.attributes

数据库组件(Redis)

db.* / db.{DB.System}.*
字段名
类型
参数说明
例子
是否必要
需要手动上报
手动埋点位置
db.instance
string
数据库实例名
customers
-
span.attributes
db.statement
string
执行语句
select * from user
-
span.attributes
db.system
string
数据库类型包括:
mysql
redis mongodb memcached postgresql oracle clickhouse
mysql
-
span.attributes
db.user
string
数据库用户名
root
1
span.attributes
db.operation
string
数据库操作
SELECT
建议
1
span.attributes
db.ip
string
数据库 IP
127.0.0.1
建议
1
span.attributes
db.port
string
数据库端口号
3306
1
span.attributes

异常标签

exception.* / error.*
字段名
类型
参数说明
例子
是否必要
需要手动埋点
手动埋点位置
error.kind
string
错误类型
error
1
span.attributes
error.object
string
错误对象
java.lang.UnsupportedOperationException
1
span.attributes
error.message
string
可理解的错误信息
Could not connect to backend
1
span.attributes
error
bool
是否有异常
true
1
span.attributes
exception.type
string
错误事件类型
*net.OpError
-
span.attributes
exception.message
string
错误信息
Could not connect to backend
-
event.attributes

JSON 示例

以 rpc 为例
{
"Name": "proto.HelloService/SayHello",
"SpanContext": {
"TraceID": "e4a230f901100099f3bf34faf75284c4",
"SpanID": "316c82bffab506ba",
"TraceFlags": "01",
"TraceState": "",
"Remote": false
},
"Parent": {
"TraceID": "e4a230f901100099f3bf34faf75284c4",
"SpanID": "6f79646dd2c6832b",
"TraceFlags": "01",
"TraceState": "",
"Remote": true
},
"SpanKind": 2,
"StartTime": "2023-09-22T11:47:53.646152+08:00",
"EndTime": "2023-09-22T11:47:53.748165063+08:00",
"Attributes": [
{
"Key": "rpc.system",
"Value": {
"Type": "STRING",
"Value": "grpc"
}
},
{
"Key": "rpc.service",
"Value": {
"Type": "STRING",
"Value": "proto.HelloService"
}
},
{
"Key": "rpc.method",
"Value": {
"Type": "STRING",
"Value": "SayHello"
}
},
{
"Key": "net.peer.ip",
"Value": {
"Type": "STRING",
"Value": "127.0.0.1"
}
},
{
"Key": "net.peer.port",
"Value": {
"Type": "STRING",
"Value": "51931"
}
},
{
"Key": "rpc.grpc.status_code",
"Value": {
"Type": "INT64",
"Value": 0
}
}
],
"Events": [
{ // 自定义事件
"Name": "message",
"Attributes": [
{
"Key": "message.type",
"Value": {
"Type": "STRING",
"Value": "RECEIVED"
}
},
{
"Key": "message.id",
"Value": {
"Type": "INT64",
"Value": 1
}
},
{
"Key": "message.uncompressed_size",
"Value": {
"Type": "INT64",
"Value": 7
}
}
],
"DroppedAttributeCount": 0,
"Time": "2023-09-22T11:47:53.646168+08:00"
},
{
"Name": "message",
"Attributes": [
{
"Key": "message.type",
"Value": {
"Type": "STRING",
"Value": "SENT"
}
},
{
"Key": "message.id",
"Value": {
"Type": "INT64",
"Value": 1
}
},
{
"Key": "message.uncompressed_size",
"Value": {
"Type": "INT64",
"Value": 13
}
}
],
"DroppedAttributeCount": 0,
"Time": "2023-09-22T11:47:53.748167+08:00"
}
],
"Links": null,
"Status": {
"Code": "Unset",
"Description": ""
},
"DroppedAttributes": 0,
"DroppedEvents": 0,
"DroppedLinks": 0,
"ChildSpanCount": 1,
"Resource": [
{
"Key": "service.name",
"Value": {
"Type": "STRING",
"Value": "test-service"
}
},
{ // 上报token
"Key": "token",
"Value": {
"Type": "STRING",
"Value": "xxxxxxxxxxxxxxxxx"
}
}
],
"InstrumentationLibrary": {
"Name": "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc",
"Version": "semver:0.33.0",
"SchemaURL": ""
}
}