Pārlūkot izejas kodu

Feature #TASK_QT-18250 1、sql下dbn为ip:port;2,解决streamid_to_span_contexts无删除语句的场景

rock 7 mēneši atpakaļ
vecāks
revīzija
13f79ad3e8

+ 4 - 1
ebpftracer/ebpf/utrace/go/net/grpc.client.probe.bpf.c

@@ -405,6 +405,7 @@ int uprobe_LoopyWriter_HeaderHandler(struct pt_regs *ctx) {
         &stream_id, sizeof(stream_id), (void *)(headerFrame_ptr + (headerFrame_streamid_pos)));
     struct apm_trace_key_t *sc_ptr = bpf_map_lookup_elem(&streamid_to_span_contexts, &stream_id);
     if (sc_ptr == NULL) {
+        bpf_map_delete_elem(&streamid_to_span_contexts, &stream_id);
         return 0;
     }
     
@@ -412,6 +413,7 @@ int uprobe_LoopyWriter_HeaderHandler(struct pt_regs *ctx) {
     u32 zero = 0;
     struct header_handler_storage *storage = bpf_map_lookup_elem(&header_handler_storage_map, &zero);
     if (!storage) {
+        bpf_map_delete_elem(&streamid_to_span_contexts, &stream_id);
         bpf_printk("Failed to get header handler storage\n");
         return 0;
     }
@@ -425,6 +427,7 @@ int uprobe_LoopyWriter_HeaderHandler(struct pt_regs *ctx) {
     struct grpc_client_request_t *grpcClientReq = bpf_map_lookup_elem(&grpc_client_storage_map, &map_id);
     if (grpcClientReq == NULL)
     {
+        bpf_map_delete_elem(&streamid_to_span_contexts, &stream_id);
         cw_bpf_debug("uprobe_LoopyWriter_HeaderHandler: grpcClientReq is NULL");
         return 0;
     }
@@ -441,7 +444,7 @@ int uprobe_LoopyWriter_HeaderHandler(struct pt_regs *ctx) {
 		generate_random_bytes(grpcClientReq->apm_sc.span_id, APM_SPAN_ID_SIZE);
         copy_byte_arrays(grpcClientReq->apm_psc.assumed_app_id, grpcClientReq->apm_sc.assumed_app_id, APM_ASSUMED_APP_ID_SIZE);
 	}
-
+    bpf_map_delete_elem(&streamid_to_span_contexts, &stream_id);
     u32 k0 = 0;
 	struct trace_conf_t *trace_conf = trace_conf_map__lookup(&k0);
 	if (trace_conf) {

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

@@ -966,6 +966,8 @@ func buildSQLMapEvent(mNode *MapInfoT, event tracesdk.Event) {
 			mNode.SrcAddr = attr.Value.AsString()
 		case "sql.destination_addr":
 			mNode.DestinationAddr = attr.Value.AsString()
+		case "sql.dbn":
+			mNode.Dbn = attr.Value.AsString()
 		}
 	}
 }

+ 4 - 0
tracing/apm_tracing.go

@@ -425,6 +425,9 @@ func (t *Trace) SQLTraceQueryEvent(l7Type l7.Protocol, semconvVal attribute.KeyV
 		return
 	}
 
+	// 拼接 destination 的 IP 和端口为 ip:port 格式
+	destAddr := fmt.Sprintf("%s:%d", destination.IP().String(), destination.Port())
+	
 	var attr []attribute.KeyValue
 	attr = append(attr,
 		semconvVal,
@@ -433,6 +436,7 @@ func (t *Trace) SQLTraceQueryEvent(l7Type l7.Protocol, semconvVal attribute.KeyV
 		semconv.NetPeerPort(int(destination.Port())),
 		attribute.String("sql.src_addr", r.ComponentSAddr.String()),
 		attribute.String("sql.destination_addr", r.ComponentDAddr.String()),
+		attribute.String("sql.dbn", destAddr),
 	)
 	t.appendTimestamp(&attr, r.StartAt, r.EndAt, r.Duration.Nanoseconds())