Ver Fonte

Feature #TASK_QT-31498 端到端新增type_from解析

Carl há 5 meses atrás
pai
commit
ca633127cf

+ 1 - 0
dist/aarch64/package_dir/bin/agentctl

@@ -135,6 +135,7 @@ startAgent() {
     export DISABLE_E2E_TRACING=false
     export DISABLE_STACK_TRACING=true
     export RUN_IN_OMNIAGENT=true
+#    export LOG_LEVEL=debug
 #    export SEND_NET_DATA=true
 #    export ENABLE_ES=true
     export SEND=1

+ 1 - 0
dist/x86_64/package_dir/bin/agentctl

@@ -135,6 +135,7 @@ startAgent() {
     export DISABLE_E2E_TRACING=false
     export DISABLE_STACK_TRACING=true
     export RUN_IN_OMNIAGENT=true
+#    export LOG_LEVEL=debug
 #    export SEND_NET_DATA=true
 #    export ENABLE_ES=true
     export SEND=1

+ 34 - 1
ebpftracer/l7/l7.go

@@ -202,6 +202,39 @@ func (s Status) Error() bool {
 	return s == StatusFailed
 }
 
+// TypeFrom represents the code type from the parent span context
+type TypeFrom string
+
+// String returns the human-readable name for the type code
+func (t TypeFrom) String() string {
+	switch string(t) {
+	case "10":
+		return "SDK"
+	case "00":
+		return "GO"
+	case "01":
+		return "JAVA"
+	case "02":
+		return "NODEJS"
+	case "03":
+		return "NGINX"
+	case "04":
+		return ".NET"
+	case "05":
+		return ".NETCORE"
+	case "06":
+		return "PHP"
+	case "07":
+		return "PYTHON"
+	case "08":
+		return "C"
+	case "09":
+		return "RUBY"
+	default:
+		return string(t)
+	}
+}
+
 type RequestData struct {
 	Protocol          Protocol
 	Pid               uint32
@@ -230,7 +263,7 @@ type RequestData struct {
 		InstanceIdFrom string
 		AppIdFrom      string
 		SpanIdFrom     string
-		TypeFrom       string
+		TypeFrom       TypeFrom
 	}
 	SysvcFrom string // cwother header value: NN:ParentServiceName:MM:ParentServiceSysTag
 	ErrorMsg  string

+ 2 - 3
ebpftracer/tracer.go

@@ -807,10 +807,9 @@ func runEventsReader(name string, r *perf.Reader, ch chan<- Event, typ perfMapTy
 				req.ParentSpanContext.InstanceIdFrom = hex.EncodeToString(v.InstanceIdFrom[:])
 				req.ParentSpanContext.AppIdFrom = hex.EncodeToString(v.AppIdFrom[:])
 				req.ParentSpanContext.SpanIdFrom = hex.EncodeToString(v.SpanIdFrom[:])
-				req.ParentSpanContext.TypeFrom = hex.EncodeToString(v.TypeFrom[:])
+				req.ParentSpanContext.TypeFrom = l7.TypeFrom(hex.EncodeToString(v.TypeFrom[:]))
 				req.SysvcFrom = utils.BytesToString(v.SysvcFrom[:])
-				fmt.Println("req.SysvcFrom")
-				fmt.Println(req.SysvcFrom)
+				klog.Debugf("cwother '%s'", req.SysvcFrom)
 				// klog.Debugf("req.ParentSpanContext.TraceIdFrom %s", req.ParentSpanContext.TraceIdFrom)
 				// klog.Debugf("req.ParentSpanContext.TypeFrom %s", req.ParentSpanContext.TypeFrom)
 				req.SAddr = ipPort(v.SAddr, v.Sport)

+ 1 - 1
pkg/go.opentelemetry.io/otel/exporters/otlp/otlptrace/apm_exporter.go

@@ -242,7 +242,7 @@ func tracetransformData(sdl []tracesdk.ReadOnlySpan) map[int][]RootDataT {
 
 	//Transform the categorized map into a slice
 	data, _ := json.Marshal(sendDataMap)
-	klog.Debug(string(data))
+	klog.Debug("data_send:", string(data))
 	//fmt.Println(len(sendData))
 	//fmt.Println("sdl len:", len(sdl))
 	return sendDataMap

+ 42 - 44
tracing/apm_tracing.go

@@ -226,46 +226,46 @@ func (t *Trace) TraceStart(method, path string, status l7.Status, duration time.
 }
 
 // Deprecated: use TraceEndEvent instead.
-func (t *Trace) TraceEnd(r *l7.RequestData) {
-	if t == nil {
-		return
-	}
-	t.span.SetAttributes(
-		semconv.HTTPStatusCode(int(r.Status)),
-		attribute.String("server.trace_id_from", r.ParentSpanContext.TraceIdFrom),
-	)
-
-	CalledId, err := strconv.ParseInt(r.ParentSpanContext.CalledId, 10, 64)
-	if err == nil && CalledId != 0 {
-		t.span.SetAttributes(attribute.Int64("server.called_id", CalledId))
-	}
-
-	InstanceIdFrom, err := strconv.ParseInt(r.ParentSpanContext.InstanceIdFrom, 10, 64)
-	if err == nil && InstanceIdFrom != 0 {
-		t.span.SetAttributes(attribute.Int64("server.instance_id_from", InstanceIdFrom))
-	}
-
-	AppIdFrom, err := strconv.ParseInt(r.ParentSpanContext.AppIdFrom, 10, 64)
-	if err == nil && AppIdFrom != 0 {
-		t.span.SetAttributes(attribute.Int64("server.app_id_from", AppIdFrom))
-	}
-	if r.ParentSpanContext.SpanIdFrom != "0000000000000000" {
-		t.span.SetAttributes(attribute.String("server.span_id_from", r.ParentSpanContext.SpanIdFrom))
-	}
-	// klog.Debugf("r.ParentSpanContext.TypeFrom tpp %s", r.ParentSpanContext.TypeFrom)
-	if r.ParentSpanContext.TypeFrom == "10" {
-		t.span.SetAttributes(attribute.String("server.type_from", "SDK"))
-		t.span.SetAttributes(attribute.String("server.app_id_from", "-1"))
-		t.span.SetAttributes(attribute.String("server.span_id_from", r.ParentSpanContext.TraceIdFrom))
-		t.span.SetAttributes(attribute.String("server.instance_id_from", "-1"))
-		t.span.SetAttributes(attribute.String("server.call_id", "-1"))
-	}
-	// for _, v := range t.stack {
-	// 	fmt.Printf("TraceEndTraceEndTraceEnd%s\n", v)
-	// }
-	//t.buildFun()
-	t.span.End(trace.WithTimestamp(time.Now()))
-}
+//func (t *Trace) TraceEnd(r *l7.RequestData) {
+//	if t == nil {
+//		return
+//	}
+//	t.span.SetAttributes(
+//		semconv.HTTPStatusCode(int(r.Status)),
+//		attribute.String("server.trace_id_from", r.ParentSpanContext.TraceIdFrom),
+//	)
+//
+//	CalledId, err := strconv.ParseInt(r.ParentSpanContext.CalledId, 10, 64)
+//	if err == nil && CalledId != 0 {
+//		t.span.SetAttributes(attribute.Int64("server.called_id", CalledId))
+//	}
+//
+//	InstanceIdFrom, err := strconv.ParseInt(r.ParentSpanContext.InstanceIdFrom, 10, 64)
+//	if err == nil && InstanceIdFrom != 0 {
+//		t.span.SetAttributes(attribute.Int64("server.instance_id_from", InstanceIdFrom))
+//	}
+//
+//	AppIdFrom, err := strconv.ParseInt(r.ParentSpanContext.AppIdFrom, 10, 64)
+//	if err == nil && AppIdFrom != 0 {
+//		t.span.SetAttributes(attribute.Int64("server.app_id_from", AppIdFrom))
+//	}
+//	if r.ParentSpanContext.SpanIdFrom != "0000000000000000" {
+//		t.span.SetAttributes(attribute.String("server.span_id_from", r.ParentSpanContext.SpanIdFrom))
+//	}
+//	// klog.Debugf("r.ParentSpanContext.TypeFrom tpp %s", r.ParentSpanContext.TypeFrom)
+//	if r.ParentSpanContext.TypeFrom == "10" {
+//		t.span.SetAttributes(attribute.String("server.type_from", "SDK"))
+//		t.span.SetAttributes(attribute.String("server.app_id_from", "-1"))
+//		t.span.SetAttributes(attribute.String("server.span_id_from", r.ParentSpanContext.TraceIdFrom))
+//		t.span.SetAttributes(attribute.String("server.instance_id_from", "-1"))
+//		t.span.SetAttributes(attribute.String("server.call_id", "-1"))
+//	}
+//	// for _, v := range t.stack {
+//	// 	fmt.Printf("TraceEndTraceEndTraceEnd%s\n", v)
+//	// }
+//	//t.buildFun()
+//	t.span.End(trace.WithTimestamp(time.Now()))
+//}
 
 // 新增结束事件
 func (t *Trace) TraceEndEvent(r *l7.RequestData) {
@@ -298,7 +298,8 @@ func (t *Trace) TraceEndEvent(r *l7.RequestData) {
 	appIdFrom, err := strconv.ParseInt(r.ParentSpanContext.AppIdFrom, 10, 64)
 	if err == nil && appIdFrom != 0 {
 		attr = append(attr, attribute.Int64("server.app_id_from", appIdFrom))
-		//t.span.SetAttributes(attribute.Int64("server.app_id_from", AppIdFrom))
+		// Add type_from attribute for all cases
+		attr = append(attr, attribute.String("server.type_from", r.ParentSpanContext.TypeFrom.String()))
 	}
 	if r.ParentSpanContext.SpanIdFrom != "0000000000000000" {
 		attr = append(attr, attribute.String("server.span_id_from", r.ParentSpanContext.SpanIdFrom))
@@ -307,13 +308,10 @@ func (t *Trace) TraceEndEvent(r *l7.RequestData) {
 
 	// klog.Debugf("r.ParentSpanContext.TypeFrom event tpp %s", r.ParentSpanContext.TypeFrom)
 	if r.ParentSpanContext.TypeFrom == "10" {
-		attr = append(attr, attribute.String("server.type_from", "SDK"))
 		attr = append(attr, attribute.String("server.app_id_from", "-1"))
 		attr = append(attr, attribute.String("server.span_id_from", r.ParentSpanContext.TraceIdFrom))
 		attr = append(attr, attribute.String("server.instance_id_from", "-1"))
 		attr = append(attr, attribute.String("server.call_id", "-1"))
-	} else if r.ParentSpanContext.TypeFrom == "02" {
-		attr = append(attr, attribute.String("server.type_from", "Nodejs"))
 	}
 
 	attr = append(attr, attribute.String("server.src_addr", r.DAddr.String()))