Pārlūkot izejas kodu

Fixed #TSB-1234 test

ilucky.si 1 gadu atpakaļ
vecāks
revīzija
aa6a19871b

+ 10 - 2
containers/container_apm.go

@@ -71,18 +71,26 @@ func (c *Container) onL7RequestApm(pid uint32, fd uint64, timestamp uint64, r *l
 			return nil
 		}
 	}
+	//if r.Protocol != l7.ProtocolHTTP {
+	//
+	//}
 	conn := c.connectionsByPidFd[PidFd{Pid: pid, Fd: fd}]
-	//fmt.Println(conn, pid, fd)
+	fmt.Println("l7.connectionsByPidFd", conn, pid, fd)
 	if conn == nil {
 		return nil
 	}
-	if timestamp != 0 && conn.Timestamp != timestamp {
+	fmt.Println("l7.timestamp", timestamp, conn.Timestamp)
+	//if r.Protocol != l7.ProtocolHTTP {
+	//
+	//}
+	if r.Protocol != l7.ProtocolHTTP && timestamp != 0 && conn.Timestamp != timestamp {
 		return nil
 	}
 	stats := c.l7Stats.get(r.Protocol, conn.Dest, conn.ActualDest)
 	trace := tracing.NewTrace(string(c.id), conn.ActualDest)
 	switch r.Protocol {
 	case l7.ProtocolHTTP:
+		fmt.Println("l7.ProtocolHTTP", r.TraceId)
 		stats.observe(r.Status.Http(), "", r.Duration)
 		method, path, hostIp, port := l7.ParseHttpHost(r.Payload)
 		//trace.HttpRequest(method, path, r.Status, r.Duration)

+ 1 - 0
ebpftracer/ebpf/include/apm_trace.h

@@ -27,6 +27,7 @@
 #define APM_SPAN_ID_SIZE 8
 
 #define CW_HEADER_LENGTH 123
+#define CW_HEADER_LENGTH2 122
 
 /***********************************************************
  * Trace struct

+ 2 - 2
ebpftracer/ebpf/include/protocol_inference.h

@@ -418,12 +418,12 @@ static __inline enum message_type infer_http_message(const char *buf,
     }
 
     if (is_http_response2(buf)) {
-        debug("[HTTP END]:%s",buf);
+//        debug("[HTTP END]:%s",buf);
         return MSG_RESPONSE;
     }
 
     if (is_http_request2(buf, count)) {
-        debug("[HTTP Start]:%s",buf);
+//        debug("[HTTP Start]:%s",buf);
         return MSG_REQUEST;
     }
 

+ 2 - 3
ebpftracer/ebpf/include/socket_trace_common.h

@@ -187,9 +187,8 @@ struct ebpf_proc_info {
 	__u64 net_TCPConn_itab;
 	__u64 crypto_tls_Conn_itab; // TLS_HTTP1,TLS_HTTP2
 	__u64 credentials_syscallConn_itab; // gRPC
-
-//	__u64 start_addr;
-//	__u64 end_addr;
+	__u64 start_addr;
+	__u64 end_addr;
 	unsigned char instance_id[APM_INSTANCE_ID_SIZE];
 
 } __attribute__((packed));

+ 1 - 2
ebpftracer/ebpf/l7/apm_trace.c

@@ -90,8 +90,7 @@ __u64 get_fd_trace_id(__u32 pid, __u32 fd) {
 
 static __inline __attribute__((__always_inline__))
 void cw_save_parent_tracking_span(struct apm_span_context *sc) {
-	struct apm_trace_key_t trace_key = get_apm_trace_key(120 * NS_PER_SEC, true);  //IK:TODO:...
-	// bpf_printk("IK...cw_save_parent_tracking_span...tgid=%s, pid=%s, goid=%s", trace_key.tgid, trace_key.pid, trace_key.goid);
+	struct apm_trace_key_t trace_key = get_apm_trace_key(120 * NS_PER_SEC, true);
 	long err = 0;
 	err = bpf_map_update_elem(&apm_parent_span_context_map, &trace_key, sc, BPF_ANY);
 	if (err != 0) {

+ 15 - 15
ebpftracer/ebpf/l7/l7.c

@@ -340,27 +340,27 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
         e->payload_size = size;
         COPY_PAYLOAD(e->payload, size, payload);
 		// psc
-	    struct apm_span_context *cw_psc = cw_get_parent_tracking_span();  // IK: 获取context上下文
+	    struct apm_span_context *cw_psc = cw_get_parent_tracking_span();
 	    if(cw_psc){
 		    cw_copy_byte_arrays(cw_psc->trace_id, e->trace_id_from, APM_TRACE_ID_SIZE);
 		    cw_copy_byte_arrays(cw_psc->assumed_app_id, e->called_id, APM_ASSUMED_APP_ID_SIZE);
 		    cw_copy_byte_arrays(cw_psc->instance_id, e->instance_id_from, APM_INSTANCE_ID_SIZE);
 		    cw_copy_byte_arrays(cw_psc->app_id, e->app_id_from, APM_APP_ID_SIZE);
 		    cw_copy_byte_arrays(cw_psc->span_id, e->span_id_from, APM_SPAN_ID_SIZE);
-		    for (int i = 0; i < APM_TRACE_ID_SIZE; i++) {
-			    bpf_printk("trace_enter_write - trace_id = %02x", e->trace_id_from[i]);
-		    }
+//		    for (int i = 0; i < APM_TRACE_ID_SIZE; i++) {
+//			    bpf_printk("trace_enter_write - trace_id = %02x", e->trace_id_from[i]);
+//		    }
 	    }
         bpf_map_delete_elem(&active_l7_requests, &k);
         bpf_perf_event_output(ctx, &l7_events, BPF_F_CURRENT_CPU, e, sizeof(*e));
         // 发送事件到用户空间 end
 //        __u64 k_version = load_filter_pid();
 //        cw_bpf_debug("filter_pid:%d", k_version);
-
-        struct test_t *ttt = bpf_map_lookup_elem(&test_heap, &zero);
-        if (!ttt) {
-            return 0;
-        }
+//
+//        struct test_t *ttt = bpf_map_lookup_elem(&test_heap, &zero);
+//        if (!ttt) {
+//            return 0;
+//        }
 
 //        struct member_fields_offset *off = bpf_map_lookup_elem(&__members_offset, &zero);
 //        if (!off) {
@@ -368,7 +368,7 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
 //        }
 
 //        cw_bpf_debug("off->task__files_offset:%x", off->task__files_offset);
-        cw_bpf_debug("e->test_id1111:%d", ttt->test_id);
+//        cw_bpf_debug("e->test_id1111:%d", ttt->test_id);
         cw_bpf_debug("HTTP_END");
         return 0;
     }
@@ -526,7 +526,7 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
     }
 
     int zero = 0;
-    char* payload = args->buf;   // IK: 解析payload....
+    char* payload = args->buf;
     if (args->iovlen) {
         payload = bpf_map_lookup_elem(&iovec_buf_heap, &zero);
         if (!payload) {
@@ -538,7 +538,7 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
         }
     }
 
-    struct l7_event *e = bpf_map_lookup_elem(&l7_event_heap, &zero);  // IK:TODO: 取出从入口放进去的l7_event...
+    struct l7_event *e = bpf_map_lookup_elem(&l7_event_heap, &zero);
     if (!e) {
         return 0;
     }
@@ -677,9 +677,9 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
 	    if (sc) {
 		    cw_copy_byte_arrays(sc->assumed_app_id, e->assumed_app_id, APM_ASSUMED_APP_ID_SIZE);
 		    cw_copy_byte_arrays(sc->span_id, e->span_id, APM_SPAN_ID_SIZE);
-		    for (int i = 0; i < APM_ASSUMED_APP_ID_SIZE; i++) {
-			    bpf_printk("assumed_app_id-assumed_app_id[%d] = %02x", i, sc->assumed_app_id[i]);
-		    }
+//		    for (int i = 0; i < APM_ASSUMED_APP_ID_SIZE; i++) {
+//			    bpf_printk("assumed_app_id-assumed_app_id[%d] = %02x", i, sc->assumed_app_id[i]);
+//		    }
 	    }
 		//        cw_bpf_debug("[Response][HTTP222]:thread_id:%d|type:%s|FD:%d\n",k.pid,"",k.fd);
 //        cw_bpf_debug("[Response][HTTP222] trace_id:%llu", trace_id);

+ 15 - 6
ebpftracer/ebpf/utrace/go/include/alloc.h

@@ -35,7 +35,7 @@ struct
 //    __uint(pinning, LIBBPF_PIN_BY_NAME);
 } alloc_map SEC(".maps");
 
-static __always_inline u64 get_area_start()
+static __always_inline u64 get_area_start(u64 start_addr,u64 end_addr)
 {
     s64 partition_size = (end_addr - start_addr) / total_cpus;
     u32 current_cpu = bpf_get_smp_processor_id();
@@ -53,7 +53,7 @@ static __always_inline u64 get_area_start()
     }
 }
 
-static __always_inline u64 get_area_end(u64 start)
+static __always_inline u64 get_area_end(u64 start,u64 start_addr,u64 end_addr)
 {
     s64 partition_size = (end_addr - start_addr) / total_cpus;
     s32 end_index = 1;
@@ -89,15 +89,24 @@ static __always_inline void *write_target_data(void *data, s32 size)
     {
         return NULL;
     }
+	u64 start_from_proc;
+	u64 end_from_proc;
+	__u32 tgid = (__u32)(bpf_get_current_pid_tgid() >> 32);
+	struct ebpf_proc_info *info = bpf_map_lookup_elem(&proc_info_map, &tgid);
+	if (!info) {
+		return NULL;
+	}
+	start_from_proc = info->start_addr;
+	end_from_proc = info->end_addr;
 
-    u64 start = get_area_start();
-    u64 end = get_area_end(start);
+	u64 start = get_area_start(start_from_proc, end_from_proc);
+    u64 end = get_area_end(start,start_from_proc,end_from_proc);
     if (end - start < size)
     {
         bpf_printk("reached end of CPU memory block, going to the start again");
         s32 start_index = 0;
         bpf_map_delete_elem(&alloc_map, &start_index);
-        start = get_area_start();
+        start = get_area_start(start_from_proc, end_from_proc);
     }
 
     void *target = (void *)start;
@@ -109,7 +118,7 @@ static __always_inline void *write_target_data(void *data, s32 size)
         target += dist_to_next_page;
     }
     u64 target_u = (u64)target;
-    if (target_u > end_addr || target_u < start_addr) {
+    if (target_u > end_from_proc || target_u < start_from_proc) {
         bpf_printk("TARGET ADDRESS IS OUT OF BOUNDS: 0x%llx", target);
         return NULL;
     }

+ 19 - 27
ebpftracer/ebpf/utrace/go/include/arguments.h

@@ -23,44 +23,39 @@
 // Injected in init
 volatile const bool is_registers_abi;
 
-static __always_inline void *get_argument_by_reg(struct pt_regs *ctx, int index)
-{
-    switch (index)
-    {
+static __always_inline void *get_argument_by_reg(struct pt_regs *ctx, int index) {
+	switch (index) {
     case 1:
-        return (void *)PT_GO_REGS_PARM1(ctx);
+			return (void *) PT_GO_REGS_PARM1(ctx);
     case 2:
-        return (void *)PT_GO_REGS_PARM2(ctx);
+			return (void *) PT_GO_REGS_PARM2(ctx);
     case 3:
-        return (void *)PT_GO_REGS_PARM3(ctx);
+			return (void *) PT_GO_REGS_PARM3(ctx);
     case 4:
-        return (void *)PT_GO_REGS_PARM4(ctx);
+			return (void *) PT_GO_REGS_PARM4(ctx);
     case 5:
-        return (void *)PT_GO_REGS_PARM5(ctx);
+			return (void *) PT_GO_REGS_PARM5(ctx);
     case 6:
-        return (void *)PT_GO_REGS_PARM6(ctx);
+			return (void *) PT_GO_REGS_PARM6(ctx);
     case 7:
-        return (void *)PT_GO_REGS_PARM7(ctx);
+			return (void *) PT_GO_REGS_PARM7(ctx);
     case 8:
-        return (void *)PT_GO_REGS_PARM8(ctx);
+			return (void *) PT_GO_REGS_PARM8(ctx);
     case 9:
-        return (void *)PT_GO_REGS_PARM9(ctx);
+			return (void *) PT_GO_REGS_PARM9(ctx);
     default:
         return NULL;
     }
 }
 
-static __always_inline void *get_argument_by_stack(struct pt_regs *ctx, int index)
-{
+static __always_inline void *get_argument_by_stack(struct pt_regs *ctx, int index) {
     void *ptr = 0;
-    bpf_probe_read(&ptr, sizeof(ptr), (void *)(PT_REGS_SP(ctx) + (index * 8)));
+	bpf_probe_read(&ptr, sizeof(ptr), (void *) (PT_REGS_SP(ctx) + (index * 8)));
     return ptr;
 }
 
-static __always_inline void *get_argument(struct pt_regs *ctx, int index)
-{
-    if (is_registers_abi)
-    {
+static __always_inline void *get_argument(struct pt_regs *ctx, int index) {
+	if (is_registers_abi) {
         return get_argument_by_reg(ctx, index);
     }
 
@@ -73,18 +68,15 @@ static __always_inline void *get_argument(struct pt_regs *ctx, int index)
 // Consistent key is used as a key for that map.
 // For Go < 1.17: consistent key is the address of context.Context.
 // For Go >= 1.17: consistent key is the goroutine address.
-static __always_inline void *get_consistent_key(struct pt_regs *ctx, void *contextContext)
-{
-    if (is_registers_abi)
-    {
-	    return (void *)GOROUTINE(ctx);
+static __always_inline void *get_consistent_key(struct pt_regs *ctx, void *contextContext) {
+	if (is_registers_abi) {
+		return (void *) GOROUTINE(ctx);
     }
 
     return contextContext;
 }
 
-static __always_inline bool is_register_abi()
-{
+static __always_inline bool is_register_abi() {
     return is_registers_abi;
 }
 

+ 0 - 2
ebpftracer/ebpf/utrace/go/include/go_context.h

@@ -60,7 +60,6 @@ static __always_inline void *get_parent_go_context(void *ctx, void *map) {
     {
         if (data == NULL)
         {
-            bpf_printk("data is null");
             break;
         }
     
@@ -69,7 +68,6 @@ static __always_inline void *get_parent_go_context(void *ctx, void *map) {
         {
             return data;
         }
-        bpf_printk("data is null2");
         // We assume context.Context implementation contains Parent context.Context member
         // Since the parent is also an interface, we need to read the data part of it
         bpf_probe_read(&data, sizeof(data), data + 8);

+ 69 - 0
ebpftracer/ebpf/utrace/go/include/span_context.h

@@ -127,6 +127,75 @@ static __always_inline void span_context_to_cw_string(struct apm_span_context *c
 //	*out = '1';
 }
 
+static __always_inline void span_context_to_cw_string2(struct apm_span_context *ctx, char *buff) {
+	// W3C format: version (2 chars) - trace id (32 chars) - span id (16 chars) - sampled (2 chars)
+	//	[type_from]:[sample]:[host_id]:[app_id]:[instance_id]:[trace_id]:[assumed_app_i d]:[span_id]
+	//	2           2         16        16      16            32         16                16
+	char *out = buff;
+
+	// Write type_from
+	*out++ = 'G';
+	*out++ = 'O';
+	*out++ = ':';
+
+	// Write sample
+//	*out++ = '0';
+	*out++ = '0';
+	*out++ = ':';
+
+	// Write host_id
+	bytes_to_hex_string(ctx->host_id, APM_HOST_ID_SIZE, out);
+	out += APM_HOST_ID_STRING_SIZE;
+	*out++ = ':';
+
+	// Write app_id
+	bytes_to_hex_string(ctx->app_id, APM_APP_ID_SIZE, out);
+	out += APM_APP_ID_STRING_SIZE;
+	*out++ = ':';
+
+
+	// Write instance_id
+	bytes_to_hex_string(ctx->instance_id, APM_INSTANCE_ID_SIZE, out);
+	out += APM_INSTANCE_ID_STRING_SIZE;
+	*out++ = ':';
+
+	// Write trace_id
+	bytes_to_hex_string(ctx->trace_id, APM_TRACE_ID_SIZE, out);
+	out += APM_TRACE_ID_STRING_SIZE;
+	*out++ = ':';
+	// Write assumed_app_id
+	bytes_to_hex_string(ctx->assumed_app_id, APM_ASSUMED_APP_ID_SIZE, out);
+	out += APM_ASSUMED_APP_ID_STRING_SIZE;
+	*out++ = ':';
+
+	// Write span_id
+	bytes_to_hex_string(ctx->span_id, APM_SPAN_ID_SIZE, out);
+	out += APM_SPAN_ID_STRING_SIZE;
+//	*out++ = ':';
+
+//	// Write trace id
+//	bytes_to_hex_string(ctx->TraceID, TRACE_ID_SIZE, out);
+//	out += TRACE_ID_STRING_SIZE;
+//	*out++ = '-';
+//	// Write trace id
+//	bytes_to_hex_string(ctx->TraceID, TRACE_ID_SIZE, out);
+//	out += TRACE_ID_STRING_SIZE;
+//	*out++ = '-';
+//	// Write trace id
+//	bytes_to_hex_string(ctx->TraceID, TRACE_ID_SIZE, out);
+//	out += TRACE_ID_STRING_SIZE;
+//	*out++ = '-';
+//
+//	// Write span id
+//	bytes_to_hex_string(ctx->SpanID, SPAN_ID_SIZE, out);
+//	out += SPAN_ID_STRING_SIZE;
+//	*out++ = '-';
+
+	// Write sampled
+//	*out++ = '0';
+//	*out = '1';
+}
+
 #define MAX_SIZE 120
 #define MAX_TOKENS 8
 

+ 112 - 6
ebpftracer/ebpf/utrace/go/net/client.probe.bpf.c

@@ -91,7 +91,7 @@ static __always_inline long inject_header(void* headers_ptr, struct span_context
         // No key-value pairs in the Go map, need to "allocate" memory for the user
         bucket_ptr = write_target_data(bucket_map_value, sizeof(struct map_bucket));
         if (bucket_ptr == NULL) {
-            bpf_printk("inject_header: Failed to write bucket to user");  // IK:TODO: inject_header: Failed to write bucket to user
+            bpf_printk("inject_header: Failed to write bucket to user");
             return -1;
         }
         // Update the buckets pointer in the hmap struct to point to newly allocated bucket
@@ -191,7 +191,7 @@ static __always_inline long cw_inject_header(void* headers_ptr, struct apm_span_
 
     if (curr_keyvalue_count == 0) {
         // No key-value pairs in the Go map, need to "allocate" memory for the user
-        bucket_ptr = write_target_data(bucket_map_value, sizeof(struct map_bucket));  // IK:ERROR: TARGET ADDRESS IS OUT OF BOUNDS: 0x7efd8a506000
+        bucket_ptr = write_target_data(bucket_map_value, sizeof(struct map_bucket));
         if (bucket_ptr == NULL) {
             bpf_printk("inject_header: Failed to write bucket to user");
             return -1;
@@ -264,6 +264,108 @@ static __always_inline long cw_inject_header(void* headers_ptr, struct apm_span_
     return 0;
 }
 
+// 00:00:1015481350055581:5450531005555981:5610250100539899:304775019cd3218a304775019cd3218a:1001025098564810:140acc88cde8773f
+static __always_inline long cw_inject_header2(void* headers_ptr, struct apm_span_context* propagated_ctx) {
+    // Read the key-value count - this field must be the first one in the hmap struct as documented in src/runtime/map.go
+    u64 curr_keyvalue_count = 0;
+    long res = bpf_probe_read_user(&curr_keyvalue_count, sizeof(curr_keyvalue_count), headers_ptr);
+
+    if (res < 0) {
+        bpf_printk("Couldn't read map key-value count from user");
+        return -1;
+    }
+
+    if (curr_keyvalue_count >= 8) {
+        bpf_printk("Map size is bigger than 8, skipping context propagation");
+        return -1;
+    }
+
+    // Get pointer to temp bucket struct we store in a map (avoiding large local variable on the stack)
+    // Performing read-modify-write on the bucket
+    u32 map_id = 0;
+    struct map_bucket *bucket_map_value = bpf_map_lookup_elem(&golang_mapbucket_storage_map, &map_id);
+    if (!bucket_map_value) {
+        return -1;
+    }
+
+    void *buckets_ptr_ptr = (void*) (headers_ptr + buckets_ptr_pos);
+    void *bucket_ptr = 0; // The actual pointer to the buckets
+
+    if (curr_keyvalue_count == 0) {
+        // No key-value pairs in the Go map, need to "allocate" memory for the user
+        bucket_ptr = write_target_data(bucket_map_value, sizeof(struct map_bucket));
+        if (bucket_ptr == NULL) {
+            bpf_printk("inject_header: Failed to write bucket to user");
+            return -1;
+        }
+        // Update the buckets pointer in the hmap struct to point to newly allocated bucket
+        res = bpf_probe_write_user(buckets_ptr_ptr, &bucket_ptr, sizeof(bucket_ptr));
+        if (res < 0) {
+            bpf_printk("Failed to update the map bucket pointer for the user");
+            return -1;
+        }
+    } else {
+        // There is at least 1 key-value pair, hence the bucket pointer from the user is valid
+        // Read the bucket pointer
+        res = bpf_probe_read_user(&bucket_ptr, sizeof(bucket_ptr), buckets_ptr_ptr);
+        // Read the user's bucket to the eBPF map entry
+        bpf_probe_read_user(bucket_map_value, sizeof(struct map_bucket), bucket_ptr);
+    }
+
+    u8 bucket_index = curr_keyvalue_count & 0x7;
+
+    char traceparent_tophash = 0xee;
+    bucket_map_value->tophash[bucket_index] = traceparent_tophash;
+
+    // Prepare the key string for the user
+    char key[9] = "CLOUDWISE";
+    void *ptr = write_target_data(key, 9);
+    if (ptr == NULL) {
+        bpf_printk("inject_header: Failed to write key to user");
+        return -1;
+    }
+    bucket_map_value->keys[bucket_index] = (struct go_string_ot) {.len = 9, .str = ptr};
+
+    // Prepare the value string slice
+    // First the value string which constains the span context
+    char val[CW_HEADER_LENGTH2];
+	span_context_to_cw_string2(propagated_ctx, val);
+    ptr = write_target_data(val, sizeof(val));
+    if(ptr == NULL) {
+        bpf_printk("inject_header: Failed to write value to user");
+        return -1;
+    }
+
+    // The go string pointing to the above val
+    struct go_string_ot header_value = {.len = CW_HEADER_LENGTH2, .str = ptr};
+    ptr = write_target_data((void*)&header_value, sizeof(header_value));
+    if(ptr == NULL) {
+        bpf_printk("inject_header: Failed to write go_string to user");
+        return -1;
+    }
+
+    // Last, go_slice pointing to the above go_string
+    bucket_map_value->values[bucket_index] = (struct go_slice_ot) {.array = ptr, .cap = 1, .len = 1};
+
+    // Update the map header count field
+    curr_keyvalue_count += 1;
+    res = bpf_probe_write_user(headers_ptr, &curr_keyvalue_count, sizeof(curr_keyvalue_count));
+    if (res < 0) {
+        bpf_printk("Failed to update key-value count in map header");
+        return -1;
+    }
+
+    // Update the bucket
+    res = bpf_probe_write_user(bucket_ptr, bucket_map_value, sizeof(struct map_bucket));
+    if (res < 0) {
+        bpf_printk("Failed to update bucket content");
+        return -1;
+    }
+
+    bpf_memset((unsigned char *)bucket_map_value, sizeof(struct map_bucket), 0);
+    return 0;
+}
+
 // This instrumentation attaches uprobe to the following function:
 // func net/http/transport.roundTrip(req *Request) (*Response, error)
 SEC("uprobe/Transport_roundTrip")
@@ -408,15 +510,19 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
     bpf_printk("IK2...uprobe_Transport_roundTrip...cw_inject_header...");
     // get headers from Request
     void *headers_ptr = 0;
-    bpf_probe_read(&headers_ptr, sizeof(headers_ptr), (void *)(req_ptr+headers_ptr_pos));  // IK:DEBUG: bpf_probe_read获取header...
+    bpf_probe_read(&headers_ptr, sizeof(headers_ptr), (void *)(req_ptr+headers_ptr_pos));
 //    long res = inject_header(headers_ptr, &httpReq->sc);
-    long res = cw_inject_header(headers_ptr, &httpReq->apm_sc);  // IK: 将端到端信息写入context中...
-    if (res < 0) {
+//    long res = cw_inject_header(headers_ptr, &httpReq->apm_sc);
+//    if (res < 0) {
+//        bpf_printk("uprobe_Transport_roundTrip: Failed to inject header");
+//    }
+	long res2 = cw_inject_header2(headers_ptr, &httpReq->apm_sc);
+	if (res2 < 0) {
         bpf_printk("uprobe_Transport_roundTrip: Failed to inject header");
     }
 
     // Write event
-//    bpf_map_update_elem(&http_events, &key, httpReq, 0);
+    bpf_map_update_elem(&http_events, &key, httpReq, 0);
 //    start_tracking_span(context_ptr_val, &httpReq->sc);
     return 0;
 }

+ 1 - 1
ebpftracer/ebpf/utrace/go/net/server.probe.bpf.c

@@ -443,7 +443,7 @@ int uprobe_HandlerFunc_ServeHTTP_Returns(struct pt_regs *ctx) {
 	// status code
 	bpf_probe_read(&http_server_span->status_code, sizeof(http_server_span->status_code),
 	               (void *) (resp_ptr + status_code_pos));
-    // IK:
+
 	bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, http_server_span, sizeof(*http_server_span));
 	stop_tracking_span(&http_server_span->sc, &http_server_span->psc);
 

+ 13 - 1
ebpftracer/tls.go

@@ -221,7 +221,19 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID) []link.Link {
 			info.CryptoTLSConnItab = uint64(0)
 			info.CredentialsSyscallConnItab = uint64(0)
 			info.InstanceId = insID.HashtVal
-			_, err = tracer.UpdateProcInfoToMap(t.collection, pid, info) // IK: 向内核传输数据...
+			// 获取内存地址
+			allocDetails, err := tracer.Allocate(int(pid))
+			if err == nil && allocDetails != nil {
+				info.StartAddr = allocDetails.StartAddr
+				info.EndAddr = allocDetails.EndAddr
+			}
+			klog.Infoln("Major:", major)
+			klog.Infoln("Minor:", minor)
+			klog.Infoln("Revision:", revision)
+			klog.Infoln("goVersion", goVersion)
+			klog.Infoln("info.StartAddr", info.StartAddr)
+			klog.Infoln("info.EndAddr", info.EndAddr)
+			_, err = tracer.UpdateProcInfoToMap(t.collection, pid, info)
 			if err != nil {
 				klog.Error("failed to update program info", err)
 			}

+ 2 - 3
ebpftracer/tracer.go

@@ -136,7 +136,7 @@ func NewTracer(kernelVersion string, disableL7Tracing bool) *Tracer {
 		kernelVersion:    kernelVersion,
 		disableL7Tracing: disableL7Tracing,
 
-		readers: map[string]*perf.Reader{}, // IK: readers和uprobes有什么区别...
+		readers: map[string]*perf.Reader{},
 		uprobes: map[string]*ebpf.Program{},
 	}
 }
@@ -630,7 +630,7 @@ func runEventsReader(name string, r *perf.Reader, ch chan<- Event, typ perfMapTy
 			//continue
 		case perfMapTypeL7Events: // IK: 重点哈...rawsample里面已经放进去了context...
 			v := &l7Event{}
-			reader := bytes.NewBuffer(rec.RawSample) //
+			reader := bytes.NewBuffer(rec.RawSample)
 			if err := binary.Read(reader, binary.LittleEndian, v); err != nil {
 				klog.Warningln("failed to read msg:", err)
 				continue
@@ -706,7 +706,6 @@ func runEventsReader(name string, r *perf.Reader, ch chan<- Event, typ perfMapTy
 			continue
 		}
 
-		fmt.Println(event.Pid)
 		ch <- event
 	}
 }

+ 82 - 0
ebpftracer/tracer/allocate.go

@@ -0,0 +1,82 @@
+package tracer
+
+import (
+	"fmt"
+	"github.com/coroot/coroot-node-agent/ebpftracer/tracer/ptrace"
+	"k8s.io/klog/v2"
+	"math"
+	"os"
+	"runtime"
+)
+
+type AllocationDetails struct {
+	StartAddr uint64
+	EndAddr   uint64
+	//NumCPU    uint64
+}
+
+func Allocate(pid int) (*AllocationDetails, error) {
+	// nCPU, err := utils.GetCPUCount()
+
+	//if err != nil {
+	//	return nil, err
+	//}
+	nCPU := 8
+	mapSize := uint64(os.Getpagesize() * nCPU * 8)
+
+	addr, err := remoteAllocate(pid, mapSize)
+	if err != nil {
+		return nil, err
+	}
+	return &AllocationDetails{
+		StartAddr: addr,
+		EndAddr:   addr + mapSize,
+		//NumCPU:    uint64(nCPU),
+	}, nil
+}
+
+func remoteAllocate(pid int, mapSize uint64) (uint64, error) {
+	runtime.LockOSThread()
+	defer runtime.UnlockOSThread()
+	program, err := ptrace.NewTracedProgram(pid)
+	if err != nil {
+		return 0, err
+	}
+
+	defer func() {
+		klog.Info("Detaching from process", "pid", pid)
+		err := program.Detach()
+		if err != nil {
+			klog.Error(err, "Failed to detach ptrace", "pid", pid)
+		}
+	}()
+
+	if err := program.SetMemLockInfinity(); err != nil {
+		klog.Error(err, "Failed to set memlock on process")
+	} else {
+		klog.Info("Set memlock on process successfully")
+	}
+
+	fd := -1
+	addr, err := program.Mmap(mapSize, uint64(fd))
+	if err != nil {
+		return 0, err
+	}
+	if addr == math.MaxUint64 {
+		// On success, mmap() returns a pointer to the mapped area.
+		// On error, the value MAP_FAILED (that is, (void *) -1) is returned
+		return 0, fmt.Errorf("mmap MAP_FAILED")
+	}
+
+	err = program.Madvise(addr, mapSize)
+	if err != nil {
+		return 0, err
+	}
+
+	err = program.Mlock(addr, mapSize)
+	if err != nil {
+		return 0, err
+	}
+
+	return addr, nil
+}

+ 2 - 0
ebpftracer/tracer/common.go

@@ -157,6 +157,8 @@ type EbpfProcInfo struct {
 	NetTCPConnItab             uint64
 	CryptoTLSConnItab          uint64 // TLS_HTTP1,TLS_HTTP2
 	CredentialsSyscallConnItab uint64 // gRPC
+	StartAddr                  uint64
+	EndAddr                    uint64
 	InstanceId                 utils.HashByte
 }
 

+ 260 - 0
ebpftracer/tracer/ptrace/ptrace_linux.go

@@ -0,0 +1,260 @@
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package ptrace
+
+import (
+	"fmt"
+	"k8s.io/klog/v2"
+	"os"
+	"strconv"
+	"strings"
+	"syscall"
+
+	"golang.org/x/sys/unix"
+
+	"github.com/go-logr/logr"
+	"github.com/pkg/errors"
+)
+
+const waitPidErrorMessage = "waitpid ret value: %d"
+
+const (
+	// MADV_POPULATE_READ.
+	MadvisePopulateRead = 0x16
+	// MADV_POPULATE_WRITE.
+	MadvisePopulateWrite = 0x17
+)
+
+var threadRetryLimit = 10
+
+// TracedProgram is a program traced by ptrace.
+type TracedProgram struct {
+	pid  int
+	tids []int
+
+	backupRegs *syscall.PtraceRegs
+	backupCode []byte
+
+	logger logr.Logger
+}
+
+// Pid return the pid of traced program.
+func (p *TracedProgram) Pid() int {
+	return p.pid
+}
+
+func waitPid(pid int) error {
+	ret, err := unix.Wait4(pid, nil, unix.WALL, nil)
+	if err != nil {
+		return err
+	}
+	if ret == pid {
+		return nil
+	}
+
+	return errors.Errorf(waitPidErrorMessage, ret)
+}
+
+// NewTracedProgram ptrace all threads of a process.
+func NewTracedProgram(pid int) (*TracedProgram, error) {
+	tidMap := make(map[int]bool)
+	retryCount := make(map[int]int)
+
+	// iterate over the thread group, until it doens't change
+	//
+	// we have tried several ways to ensure that we have stopped all the tasks:
+	// 1. iterating over and over again to make sure all of them are tracee
+	// 2. send `SIGSTOP` signal
+	// ...
+	// only the first way finally worked for every situations
+	for {
+		threads, err := os.ReadDir(fmt.Sprintf("/proc/%d/task", pid))
+		if err != nil {
+			return nil, errors.WithStack(err)
+		}
+
+		// judge whether `threads` is a subset of `tidMap`
+		subset := true
+
+		tids := make(map[int]bool)
+		for _, thread := range threads {
+			tid64, err := strconv.ParseInt(thread.Name(), 10, 32)
+			if err != nil {
+				return nil, errors.WithStack(err)
+			}
+			tid := int(tid64)
+
+			_, ok := tidMap[tid]
+			if ok {
+				tids[tid] = true
+				continue
+			}
+			subset = false
+
+			err = syscall.PtraceAttach(tid)
+			if err != nil {
+				_, ok := retryCount[tid]
+				if !ok {
+					retryCount[tid] = 1
+				} else {
+					retryCount[tid]++
+				}
+				if retryCount[tid] < threadRetryLimit {
+					klog.Info("retry attaching thread", "tid", tid, "retryCount", retryCount[tid], "limit", threadRetryLimit)
+					continue
+				}
+
+				if !strings.Contains(err.Error(), "no such process") {
+					return nil, errors.WithStack(err)
+				}
+				continue
+			}
+
+			err = waitPid(tid)
+			if err != nil {
+				e := syscall.PtraceDetach(tid)
+				if e != nil && !strings.Contains(e.Error(), "no such process") {
+					klog.Error(e, "detach failed", "tid", tid)
+				}
+				return nil, errors.WithStack(err)
+			}
+
+			klog.Info("attach successfully", "tid", tid)
+			tids[tid] = true
+			tidMap[tid] = true
+		}
+
+		if subset {
+			tidMap = tids
+			break
+		}
+	}
+
+	var tids []int
+	for key := range tidMap {
+		tids = append(tids, key)
+	}
+
+	program := &TracedProgram{
+		pid:        pid,
+		tids:       tids,
+		backupRegs: &syscall.PtraceRegs{},
+		backupCode: make([]byte, syscallInstrSize),
+	}
+
+	return program, nil
+}
+
+// Detach detaches from all threads of the processes.
+func (p *TracedProgram) Detach() error {
+	for _, tid := range p.tids {
+		err := syscall.PtraceDetach(tid)
+		if err != nil {
+			if !strings.Contains(err.Error(), "no such process") {
+				return errors.WithStack(err)
+			}
+		}
+	}
+
+	return nil
+}
+
+// Protect will backup regs and rip into fields.
+func (p *TracedProgram) Protect() error {
+	err := getRegs(p.pid, p.backupRegs)
+	if err != nil {
+		return errors.WithStack(err)
+	}
+
+	_, err = syscall.PtracePeekData(p.pid, getIP(p.backupRegs), p.backupCode)
+	if err != nil {
+		return errors.WithStack(err)
+	}
+
+	return nil
+}
+
+// Restore will restore regs and rip from fields.
+func (p *TracedProgram) Restore() error {
+	err := setRegs(p.pid, p.backupRegs)
+	if err != nil {
+		return errors.WithStack(err)
+	}
+
+	_, err = syscall.PtracePokeData(p.pid, getIP(p.backupRegs), p.backupCode)
+	if err != nil {
+		return errors.WithStack(err)
+	}
+
+	return nil
+}
+
+// Wait waits until the process stops.
+func (p *TracedProgram) Wait() error {
+	_, err := syscall.Wait4(p.pid, nil, 0, nil)
+	return err
+}
+
+// Step moves one step forward.
+func (p *TracedProgram) Step() error {
+	err := syscall.PtraceSingleStep(p.pid)
+	if err != nil {
+		return errors.WithStack(err)
+	}
+
+	return p.Wait()
+}
+
+// SetMemLockInfinity sets the memlock rlimit to infinity.
+func (p *TracedProgram) SetMemLockInfinity() error {
+	// Requires CAP_SYS_RESOURCE.
+	newLimit := unix.Rlimit{Cur: unix.RLIM_INFINITY, Max: unix.RLIM_INFINITY}
+	if err := unix.Prlimit(p.pid, unix.RLIMIT_MEMLOCK, &newLimit, nil); err != nil {
+		return fmt.Errorf("failed to set memlock rlimit: %w", err)
+	}
+
+	return nil
+}
+
+// Mmap runs mmap syscall.
+func (p *TracedProgram) Mmap(length uint64, fd uint64) (uint64, error) {
+	return p.Syscall(syscall.SYS_MMAP, 0, length, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE|syscall.MAP_POPULATE|syscall.MAP_LOCKED, fd, 0)
+}
+
+// Madvise runs madvise syscall.
+func (p *TracedProgram) Madvise(addr uint64, length uint64) error {
+	//advice := uint64(syscall.MADV_WILLNEED)
+	//ver, err := utils.GetLinuxKernelVersion()
+	//if err != nil {
+	//	return errors.WithStack(err)
+	//}
+	//
+	//minVersion := version.Must(version.NewVersion("5.14"))
+	//p.logger.Info("Detected linux kernel version", "version", ver)
+	//if ver.GreaterThanOrEqual(minVersion) {
+	//	advice = syscall.MADV_WILLNEED | MadvisePopulateRead | MadvisePopulateWrite
+	//}
+	//
+	//_, err = p.Syscall(syscall.SYS_MADVISE, addr, length, advice, 0, 0, 0)
+	//return err
+	return nil
+}
+
+// Mlock runs mlock syscall.
+func (p *TracedProgram) Mlock(addr uint64, length uint64) error {
+	ret, err := p.Syscall(syscall.SYS_MLOCK, addr, length, 0, 0, 0, 0)
+	p.logger.Info("mlock ret", "ret", ret)
+	return err
+}

+ 115 - 0
ebpftracer/tracer/ptrace/ptrace_linux_amd64.go

@@ -0,0 +1,115 @@
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package ptrace
+
+import (
+	"encoding/binary"
+	"syscall"
+
+	"github.com/pkg/errors"
+)
+
+const syscallInstrSize = 2
+
+func getIP(regs *syscall.PtraceRegs) uintptr {
+	return uintptr(regs.Rip)
+}
+
+func getRegs(pid int, regsout *syscall.PtraceRegs) error {
+	err := syscall.PtraceGetRegs(pid, regsout)
+	if err != nil {
+		return errors.Wrapf(err, "get registers of process %d", pid)
+	}
+
+	return nil
+}
+
+func setRegs(pid int, regs *syscall.PtraceRegs) error {
+	err := syscall.PtraceSetRegs(pid, regs)
+	if err != nil {
+		return errors.Wrapf(err, "set registers of process %d", pid)
+	}
+
+	return nil
+}
+
+// Syscall runs a syscall at main thread of process.
+func (p *TracedProgram) Syscall(number uint64, args ...uint64) (uint64, error) {
+	// save the original registers and the current instructions
+	err := p.Protect()
+	if err != nil {
+		return 0, err
+	}
+
+	var regs syscall.PtraceRegs
+
+	err = getRegs(p.pid, &regs)
+	if err != nil {
+		return 0, err
+	}
+	// set the registers according to the syscall convention. Learn more about
+	// it in `man 2 syscall`. In x86_64 the syscall nr is stored in rax
+	// register, and the arguments are stored in rdi, rsi, rdx, r10, r8, r9 in
+	// order
+	regs.Rax = number
+	for index, arg := range args {
+		// All these registers are hard coded for x86 platform
+		if index == 0 {
+			regs.Rdi = arg
+		} else if index == 1 {
+			regs.Rsi = arg
+		} else if index == 2 {
+			regs.Rdx = arg
+		} else if index == 3 {
+			regs.R10 = arg
+		} else if index == 4 {
+			regs.R8 = arg
+		} else if index == 5 {
+			regs.R9 = arg
+		} else {
+			return 0, errors.New("too many arguments for a syscall")
+		}
+	}
+	err = setRegs(p.pid, &regs)
+	if err != nil {
+		return 0, err
+	}
+
+	instruction := make([]byte, syscallInstrSize)
+	ip := getIP(p.backupRegs)
+
+	// set the current instruction (the ip register points to) to the `syscall`
+	// instruction. In x86_64, the `syscall` instruction is 0x050f.
+	binary.LittleEndian.PutUint16(instruction, 0x050f)
+	_, err = syscall.PtracePokeData(p.pid, ip, instruction)
+	if err != nil {
+		return 0, errors.Wrapf(err, "writing data %v to %x", instruction, ip)
+	}
+
+	// run one instruction, and stop
+	err = p.Step()
+	if err != nil {
+		return 0, err
+	}
+
+	// read registers, the return value of syscall is stored inside rax register
+	err = getRegs(p.pid, &regs)
+	if err != nil {
+		return 0, err
+	}
+
+	// restore the state saved at beginning.
+	return regs.Rax, p.Restore()
+}

+ 105 - 0
ebpftracer/tracer/ptrace/ptrace_linux_arm64.go

@@ -0,0 +1,105 @@
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package ptrace
+
+import (
+	"encoding/binary"
+	"syscall"
+
+	"github.com/pkg/errors"
+	"golang.org/x/sys/unix"
+)
+
+var endian = binary.LittleEndian
+
+const syscallInstrSize = 4
+
+// see kernel source /include/uapi/linux/elf.h.
+const nrPRStatus = 1
+
+func getIP(regs *syscall.PtraceRegs) uintptr {
+	return uintptr(regs.Pc)
+}
+
+func getRegs(pid int, regsout *syscall.PtraceRegs) error {
+	err := unix.PtraceGetRegSetArm64(pid, nrPRStatus, (*unix.PtraceRegsArm64)(regsout))
+	if err != nil {
+		return errors.Wrapf(err, "get registers of process %d", pid)
+	}
+	return nil
+}
+
+func setRegs(pid int, regs *syscall.PtraceRegs) error {
+	err := unix.PtraceSetRegSetArm64(pid, nrPRStatus, (*unix.PtraceRegsArm64)(regs))
+	if err != nil {
+		return errors.Wrapf(err, "set registers of process %d", pid)
+	}
+	return nil
+}
+
+// Syscall runs a syscall at main thread of process.
+func (p *TracedProgram) Syscall(number uint64, args ...uint64) (uint64, error) {
+	if len(args) > 7 {
+		return 0, errors.New("too many arguments for a syscall")
+	}
+
+	// save the original registers and the current instructions
+	err := p.Protect()
+	if err != nil {
+		return 0, err
+	}
+
+	var regs syscall.PtraceRegs
+
+	err = getRegs(p.pid, &regs)
+	if err != nil {
+		return 0, err
+	}
+	// set the registers according to the syscall convention. Learn more about
+	// it in `man 2 syscall`. In aarch64 the syscall nr is stored in w8, and the
+	// arguments are stored in x0, x1, x2, x3, x4, x5 in order
+	regs.Regs[8] = number
+	copy(regs.Regs[:len(args)], args)
+
+	err = setRegs(p.pid, &regs)
+	if err != nil {
+		return 0, err
+	}
+
+	instruction := make([]byte, syscallInstrSize)
+	ip := getIP(p.backupRegs)
+
+	// most aarch64 devices are little endian
+	// 0xd4000001 is `svc #0` to call the system call
+	endian.PutUint32(instruction, 0xd4000001)
+	_, err = syscall.PtracePokeData(p.pid, ip, instruction)
+	if err != nil {
+		return 0, errors.Wrapf(err, "writing data %v to %x", instruction, ip)
+	}
+
+	// run one instruction, and stop
+	err = p.Step()
+	if err != nil {
+		return 0, err
+	}
+
+	// read registers, the return value of syscall is stored inside x0 register
+	err = getRegs(p.pid, &regs)
+	if err != nil {
+		return 0, err
+	}
+
+	return regs.Regs[0], p.Restore()
+}

+ 6 - 6
ebpftracer/tracer/socket.go

@@ -326,6 +326,8 @@ func update_offsets_table(collectionSpec *ebpf.CollectionSpec, opts *ebpf.Collec
 }
 
 func SetConstants(collectionSpec *ebpf.CollectionSpec) {
+	//nCPU, err := utils.GetCPUCount()
+	nCPU := 8
 	consts := map[string]interface{}{
 		// TODO go Process
 		"buckets_ptr_pos":  int64(16),
@@ -341,16 +343,14 @@ func SetConstants(collectionSpec *ebpf.CollectionSpec) {
 		"req_ptr_pos":      int64(8),
 		"status_code_pos":  int64(120),
 		"url_ptr_pos":      int64(16),
-		// TODO in process ***
-		"start_addr": int64(139627412217856),
-		"end_addr":   int64(139627412283392),
 
 		// TODO 全局 ***
-		"total_cpus": int64(2),
+		"total_cpus": int64(nCPU),
 		//"apm_app_id":  int64(0),
 		//"apm_host_id": int64(0),
 	}
 	err := collectionSpec.RewriteConstants(consts)
-	fmt.Println("err----------------", err)
-	fmt.Println("err", consts)
+	if err != nil {
+		fmt.Println("err", err, consts)
+	}
 }

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

@@ -112,6 +112,7 @@ func init() {
 }
 
 func tracetransformData(sdl []tracesdk.ReadOnlySpan) []RootDataT {
+	fmt.Println("len sdl", len(sdl))
 	if len(sdl) == 0 {
 		return nil
 	}
@@ -143,8 +144,8 @@ func tracetransformData(sdl []tracesdk.ReadOnlySpan) []RootDataT {
 	aa, err := json.Marshal(sendData)
 	fmt.Println(err)
 	fmt.Println(string(aa))
-	//fmt.Println(len(sendData))
-	//fmt.Println(len(TraceRootMap))
+	fmt.Println(len(sendData))
+	fmt.Println(len(sdl))
 	return sendData
 }
 

+ 6 - 7
pkg/go.opentelemetry.io/otel/exporters/otlp/otlptrace/exporter.go

@@ -17,7 +17,6 @@ package otlptrace // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace"
 import (
 	"context"
 	"errors"
-	"fmt"
 	"sync"
 
 	"go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform"
@@ -45,12 +44,12 @@ func (e *Exporter) ExportSpans(ctx context.Context, ss []tracesdk.ReadOnlySpan)
 	if len(protoSpans) == 0 {
 		return nil
 	}
-	sendData := tracetransformData(ss)
-	//tracetransformData(ss)
-	err := e.client.UploadApmTraces(ctx, sendData)
-	if err != nil {
-		return fmt.Errorf("traces export: %w", err)
-	}
+	//sendData := tracetransformData(ss)
+	tracetransformData(ss)
+	//err := e.client.UploadApmTraces(ctx, sendData)
+	//if err != nil {
+	//	return fmt.Errorf("traces export: %w", err)
+	//}
 	return nil
 }
 

+ 1 - 0
tracing/apm_tracing.go

@@ -124,6 +124,7 @@ func (t *Trace) RedisTraceQuery(cmd, args string, error bool, duration time.Dura
 }
 
 func (t *Trace) HttpTraceRequest(method, path, ip string, port uint16, r *l7.RequestData) {
+	fmt.Println("HttpTraceRequest:", method, path, ip, port)
 	if t == nil || method == "" {
 		return
 	}

+ 1 - 1
utils/id.go

@@ -133,7 +133,7 @@ func GetAppID(appid string) (int64, HashByte) {
 	if strings.TrimSpace(appid) == "" {
 		appid = "5410049101545798"
 	}
-	fmt.Println(appid)
+	// fmt.Println(appid)
 	id, err := strconv.ParseInt(appid, 10, 64)
 	if err != nil {
 		return 0, HashByte{}