|
|
@@ -557,7 +557,7 @@ func (t *Trace) RedisTraceQueryEvent(cmd, args string, r *l7.RequestData, destin
|
|
|
t.createTraceEvent(l7.ProtocolRedis.String(), ebpftracer.EventTypeL7Request.Int(), l7.ProtocolRedis.Int(), attr...)
|
|
|
}
|
|
|
|
|
|
-func (t *Trace) GrpcServerTraceQueryEvent(r *l7.RequestData) {
|
|
|
+func (t *Trace) GrpcServerTraceQueryEvent(r *l7.RequestData, appInfo AppInfo) {
|
|
|
if t == nil {
|
|
|
return
|
|
|
}
|
|
|
@@ -578,8 +578,8 @@ func (t *Trace) GrpcServerTraceQueryEvent(r *l7.RequestData) {
|
|
|
attribute.String("rpc.schema", "grpc"),
|
|
|
attribute.Int64("rpc.assumed_app_id", assumedAppID),
|
|
|
attribute.String("rpc.span_id", r.SpanId),
|
|
|
- attribute.Int("rpc.port", int(1023)),
|
|
|
- attribute.String("rpc.ip", "127.0.0.1"),
|
|
|
+ attribute.Int("rpc.port", appInfo.Sport),
|
|
|
+ attribute.String("rpc.ip", appInfo.Sn),
|
|
|
attribute.String("rpc.oper_type", "PROVIDER"),
|
|
|
attribute.String("rpc.method", "test_method"),
|
|
|
)
|
|
|
@@ -602,16 +602,52 @@ func (t *Trace) GrpcClientTraceQueryEvent(r *l7.RequestData) {
|
|
|
assumedAppID = 0
|
|
|
}
|
|
|
|
|
|
+ // 解析 RPCTarget 字符串,格式为 "ip:port"
|
|
|
+ klog.Infof("r.RPCTarget is %s", r.RPCTarget)
|
|
|
+ var rpcIP, rpcPort string
|
|
|
+ if r.RPCTarget != "" {
|
|
|
+ // 清理空字节,只保留有效字符
|
|
|
+ cleanTarget := strings.TrimRight(r.RPCTarget, "\x00")
|
|
|
+ cleanTarget = strings.TrimSpace(cleanTarget)
|
|
|
+ klog.Infof("cleanTarget is %s", cleanTarget)
|
|
|
+
|
|
|
+ if colonIndex := strings.LastIndex(cleanTarget, ":"); colonIndex != -1 {
|
|
|
+ rpcIP = cleanTarget[:colonIndex]
|
|
|
+ rpcPort = cleanTarget[colonIndex+1:]
|
|
|
+ klog.Infof("rpcIP is %s, rpcPort is %s", rpcIP, rpcPort)
|
|
|
+ } else {
|
|
|
+ // 如果没有找到冒号,可能是只有IP或只有端口
|
|
|
+ rpcIP = cleanTarget
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置默认值
|
|
|
+ if rpcIP == "" {
|
|
|
+ rpcIP = "127.0.0.1"
|
|
|
+ }
|
|
|
+ if rpcPort == "" {
|
|
|
+ rpcPort = "80"
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换端口为整数
|
|
|
+ portInt, err := strconv.Atoi(rpcPort)
|
|
|
+ if err != nil {
|
|
|
+ klog.Infof("r.RPCTarget convert port err is %s", err)
|
|
|
+ portInt = 80 // 默认端口
|
|
|
+ } else {
|
|
|
+ klog.Infof("r.RPCTarget convert port success, portInt is %d", portInt)
|
|
|
+ }
|
|
|
+
|
|
|
var attr []attribute.KeyValue
|
|
|
attr = append(attr,
|
|
|
semconv.RPCSystemGRPC,
|
|
|
- attribute.String("rpc.uri", "selectone"),
|
|
|
+ attribute.String("rpc.uri", string(r.Payload)),
|
|
|
attribute.String("rpc.schema", "grpc"),
|
|
|
attribute.Int64("rpc.assumed_app_id", assumedAppID),
|
|
|
attribute.String("rpc.span_id", r.SpanId),
|
|
|
- attribute.Int("rpc.port", int(1023)),
|
|
|
- attribute.String("rpc.ip", "127.0.0.1"),
|
|
|
- attribute.String("rpc.oper_type", "consumer"),
|
|
|
+ attribute.Int("rpc.port", portInt),
|
|
|
+ attribute.String("rpc.ip", rpcIP),
|
|
|
+ attribute.String("rpc.oper_type", "CONSUMER"),
|
|
|
attribute.String("rpc.method", "test_method"),
|
|
|
)
|
|
|
|