Quellcode durchsuchen

Fixed #TASK_QT-9810 双发送测试

Carl vor 1 Jahr
Ursprung
Commit
2bbd802353

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

@@ -4,6 +4,7 @@ import (
 	"crypto/md5"
 	"encoding/json"
 	"fmt"
+	"os"
 	"sort"
 	"strconv"
 	"strings"
@@ -139,7 +140,13 @@ func tracetransformData(sdl []tracesdk.ReadOnlySpan) []RootDataT {
 		//traceId := sd.SpanContext().TraceID().String()
 		fmt.Println("------event_num---- "+sd.Name(), "--->", len(sd.Events())) // 一次请求完整数据
 		// 构建map *RootDataT
-		rootData := initRootDataFromEvent()
+		var rootData RootDataT
+		// todo 应用注册逻辑
+		if os.Getenv("JAVA") == "1" {
+			rootData = initRootDataJava()
+		} else {
+			rootData = initRootDataFromEvent()
+		}
 		// build http入口 MapInfoT
 		buildAppMapFromEvent(&rootData, sd)
 		// 构建maps
@@ -425,6 +432,52 @@ func initRootDataFromEvent() RootDataT {
 	return data
 }
 
+func initRootDataJava() RootDataT {
+	data := RootDataT{
+		AccountId:      110,
+		AgentId:        3934815089541000, // TODO 更新 基于 ip:port + process_name + exe路径生成
+		AgentVersion:   "2.21.0",
+		AppId:          3365853273187618, // TODO 更新 基于appname生成
+		AppIdFrom:      -1,
+		AppName:        "eBPF-javaApplication", // TODO 更新 ip:port || process_name
+		CalledId:       -1,
+		ClientIp:       "",
+		CollTime:       0,
+		Cpu:            0,
+		Custom:         "",
+		HostId:         2315065183171055,
+		HostName:       "localhost",
+		HttpCode:       0,
+		HttpMethod:     "",
+		InstanceId:     1128864082033413, // TODO 更新 基于ip:port
+		InstanceIdFrom: -1,
+		Maps:           []MapInfoT{},
+		MemU:           0,
+		MemUP:          0,
+		OperType:       "",
+		Parameters:     []interface{}{},
+		ParentTaskName: 0,
+		Period:         -1,
+		RespTime:       0,
+		Sampling:       0,
+		ServiceName:    "TOMCAT",
+		ServiceType:    APP_SERVICE_TYPE,
+		Sip:            "",
+		Sn:             "",
+		SpanIdFrom:     "",
+		Sport:          0,
+		TId:            -1,
+		TName:          "",
+		TraceId:        "",
+		TransIds:       []interface{}{},
+		TypeFrom:       "",
+		Uri:            "",
+		UserDir:        0,
+		VipIds:         []interface{}{},
+	}
+	return data
+}
+
 func initMapNode(spanSd *tracepb.Span) (MapInfoT, string) {
 	mNode := MapInfoT{
 		Exception:      0,

+ 6 - 1
pkg/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/client_apm.go

@@ -10,6 +10,7 @@ import (
 	"io"
 	"net/http"
 	"net/url"
+	"os"
 	"strconv"
 )
 
@@ -106,7 +107,11 @@ func (d *client) newApmRequest(body []byte, mapLen int) (request, error) {
 
 	//r.Header.Set("Content-Type", contentTypeProto)
 	r.Header.Set("Content-Type", "text/plain;charset=utf-8")
-	r.Header.Set("routingKey", "goTopic")
+	if os.Getenv("JAVA") == "1" {
+		r.Header.Set("routingKey", "javaTopic")
+	} else {
+		r.Header.Set("routingKey", "goTopic")
+	}
 	r.Header.Set("DataCount", strconv.Itoa(mapLen))
 
 	req := request{Request: r}

+ 9 - 2
utils/id.go

@@ -108,8 +108,15 @@ func GetAppID() (int64, HashByte) {
 	//srcCode := md5.Sum([]byte(str))
 	//code := fmt.Sprintf("%x", srcCode)
 	//id_string := md5ToDec(code)
-	id_string := "5410049101545798"
-	fmt.Println(id_string)
+	// todo 应用注册逻辑 && 写入proc_conf层维护
+	var id_string string
+	fmt.Println(os.Getenv("JAVA"))
+	if os.Getenv("JAVA") == "1" {
+		id_string = "3365853273187618"
+	} else {
+		id_string = "5410049101545798"
+	}
+	fmt.Println("APPID:", id_string)
 	id, err := strconv.ParseInt(id_string, 10, 64)
 	if err != nil {
 		return 0, HashByte{}