|
|
@@ -19,6 +19,9 @@ struct grpc_client_request_t {
|
|
|
char method[MAX_SIZE];
|
|
|
char target[MAX_SIZE];
|
|
|
u32 status_code;
|
|
|
+
|
|
|
+ struct apm_span_context apm_sc;
|
|
|
+ struct apm_span_context apm_psc;
|
|
|
};
|
|
|
|
|
|
// struct hpack_header_field {
|
|
|
@@ -53,7 +56,8 @@ struct {
|
|
|
volatile const u64 clientconn_target_ptr_pos;
|
|
|
volatile const u64 httpclient_nextid_pos;
|
|
|
volatile const u64 headerFrame_streamid_pos;
|
|
|
-volatile const u64 headerFrame_hf_pos;
|
|
|
+// volatile const u64 headerFrame_hf_pos;
|
|
|
+u64 headerFrame_hf_pos = 8;
|
|
|
volatile const u64 error_status_pos;
|
|
|
volatile const u64 status_s_pos;
|
|
|
volatile const u64 status_message_pos;
|
|
|
@@ -65,6 +69,7 @@ volatile const bool write_status_supported;
|
|
|
// func (cc *ClientConn) Invoke(ctx context.Context, method string, args, reply interface{}, opts ...CallOption) error
|
|
|
SEC("uprobe/ClientConn_Invoke")
|
|
|
int uprobe_ClientConn_Invoke(struct pt_regs *ctx) {
|
|
|
+ // bpf_printk("enter the uprobe_ClientConn_Invoke \n");
|
|
|
// positions
|
|
|
u64 clientconn_pos = 1;
|
|
|
u64 method_ptr_pos = 4;
|
|
|
@@ -134,6 +139,7 @@ int uprobe_ClientConn_Invoke(struct pt_regs *ctx) {
|
|
|
// func (cc *ClientConn) Invoke(ctx context.Context, method string, args, reply interface{}, opts ...CallOption) error
|
|
|
SEC("uprobe/ClientConn_Invoke")
|
|
|
int uprobe_ClientConn_Invoke_Returns(struct pt_regs *ctx) {
|
|
|
+ // bpf_printk("enter the uprobe_ClientConn_Invoke_Returns \n");
|
|
|
void *key = (void *)GOROUTINE(ctx);
|
|
|
struct grpc_client_request_t *grpc_span = bpf_map_lookup_elem(&grpc_client_events, &key);
|
|
|
if (grpc_span == NULL) {
|
|
|
@@ -189,39 +195,85 @@ done:
|
|
|
// func (l *loopyWriter) headerHandler(h *headerFrame) error
|
|
|
SEC("uprobe/loopyWriter_headerHandler")
|
|
|
int uprobe_LoopyWriter_HeaderHandler(struct pt_regs *ctx) {
|
|
|
+ bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler \n");
|
|
|
void *headerFrame_ptr = get_argument(ctx, 2);
|
|
|
- u32 stream_id = 0;
|
|
|
- bpf_probe_read(
|
|
|
- &stream_id, sizeof(stream_id), (void *)(headerFrame_ptr + (headerFrame_streamid_pos)));
|
|
|
- void *sc_ptr = bpf_map_lookup_elem(&streamid_to_span_contexts, &stream_id);
|
|
|
- if (sc_ptr == NULL) {
|
|
|
+ // u32 stream_id = 0;
|
|
|
+ // bpf_probe_read(
|
|
|
+ // &stream_id, sizeof(stream_id), (void *)(headerFrame_ptr + (headerFrame_streamid_pos)));
|
|
|
+ // void *sc_ptr = bpf_map_lookup_elem(&streamid_to_span_contexts, &stream_id);
|
|
|
+ // if (sc_ptr == NULL) {
|
|
|
+ // return 0;
|
|
|
+ // }
|
|
|
+ bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler1111 \n");
|
|
|
+ __u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
+ __u32 tgid = pid_tgid >> 32;
|
|
|
+ struct ebpf_proc_info *proc_info =
|
|
|
+ bpf_map_lookup_elem(&proc_info_map, &tgid);
|
|
|
+ if(!proc_info)
|
|
|
+ {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- struct span_context current_span_context = {};
|
|
|
- bpf_probe_read(¤t_span_context, sizeof(current_span_context), sc_ptr);
|
|
|
+ bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler2222222\n");
|
|
|
+ // struct span_context current_span_context = {};
|
|
|
+ // bpf_probe_read(¤t_span_context, sizeof(current_span_context), sc_ptr);
|
|
|
|
|
|
- char tp_key[11] = "traceparent";
|
|
|
+ char tp_key[CW_HEADER_KEY_LENGTH] = CW_HEADER_KEY_VAL;
|
|
|
struct go_string_ot key_str = write_user_go_string(tp_key, sizeof(tp_key));
|
|
|
if (key_str.len == 0) {
|
|
|
bpf_printk("key write failed, aborting ebpf probe");
|
|
|
goto done;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler333333\n");
|
|
|
+ u32 map_id = 0;
|
|
|
+ struct grpc_client_request_t *grpcClientReq = bpf_map_lookup_elem(&grpc_client_storage_map, &map_id);
|
|
|
+ if (grpcClientReq == NULL)
|
|
|
+ {
|
|
|
+ cw_bpf_debug("uprobe_LoopyWriter_HeaderHandler: grpcClientReq is NULL");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ __builtin_memset(grpcClientReq, 0, sizeof(struct grpc_client_request_t));
|
|
|
+ grpcClientReq->start_time = bpf_ktime_get_ns();
|
|
|
+
|
|
|
+ bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler444444\n");
|
|
|
+ struct apm_span_context *cw_psc = cw_get_parent_tracking_span();
|
|
|
+ if(cw_psc){
|
|
|
+ bpf_probe_read(&grpcClientReq->apm_psc, sizeof(grpcClientReq->apm_psc), cw_psc);
|
|
|
+ copy_byte_arrays(grpcClientReq->apm_psc.trace_id, grpcClientReq->apm_sc.trace_id, APM_TRACE_ID_SIZE);
|
|
|
+ generate_random_bytes(grpcClientReq->apm_sc.span_id, APM_SPAN_ID_SIZE);
|
|
|
+ }
|
|
|
+
|
|
|
+ u32 k0 = 0;
|
|
|
+ struct trace_conf_t *trace_conf = trace_conf_map__lookup(&k0);
|
|
|
+ if (trace_conf) {
|
|
|
+ copy_byte_arrays(trace_conf->host_id, grpcClientReq->apm_sc.host_id, APM_HOST_ID_SIZE);
|
|
|
+ }
|
|
|
+
|
|
|
+ copy_byte_arrays(proc_info->instance_id, grpcClientReq->apm_sc.instance_id, APM_APP_ID_SIZE);
|
|
|
+ copy_byte_arrays(proc_info->app_id, grpcClientReq->apm_sc.app_id, APM_APP_ID_SIZE);
|
|
|
+
|
|
|
+ // set assumed_app_id
|
|
|
+ // set_assumed_app_id_arrays(httpReq->host, httpReq->apm_sc.assumed_app_id, APM_ASSUMED_APP_ID_STRING_SIZE);
|
|
|
+ cw_save_current_tracking_span(&grpcClientReq->apm_sc);
|
|
|
+
|
|
|
// Write headers
|
|
|
- char val[SPAN_CONTEXT_STRING_SIZE];
|
|
|
- span_context_to_w3c_string(¤t_span_context, val);
|
|
|
+ char val[CW_HEADER_VAL_LENGTH];
|
|
|
+ span_context_to_cw_string(&grpcClientReq->apm_sc, val);
|
|
|
struct go_string_ot val_str = write_user_go_string(val, sizeof(val));
|
|
|
if (val_str.len == 0) {
|
|
|
bpf_printk("val write failed, aborting ebpf probe");
|
|
|
goto done;
|
|
|
}
|
|
|
+ bpf_printk("enter the uprobe_LoopyWriter_HeaderHandler6666\n");
|
|
|
struct hpack_header_field hf = {};
|
|
|
hf.name = key_str;
|
|
|
hf.value = val_str;
|
|
|
append_item_to_slice(&hf, sizeof(hf), (void *)(headerFrame_ptr + (headerFrame_hf_pos)));
|
|
|
done:
|
|
|
- bpf_map_delete_elem(&streamid_to_span_contexts, &stream_id);
|
|
|
+ // bpf_map_delete_elem(&streamid_to_span_contexts, &stream_id);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -229,6 +281,7 @@ done:
|
|
|
SEC("uprobe/http2Client_NewStream")
|
|
|
// func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (*Stream, error)
|
|
|
int uprobe_http2Client_NewStream(struct pt_regs *ctx) {
|
|
|
+ // bpf_printk("enter the uprobe_http2Client_NewStream \n");
|
|
|
// struct go_iface go_context = {0};
|
|
|
// get_Go_context(ctx, 2, 0, true);
|
|
|
// void *httpclient_ptr = get_argument(ctx, 1);
|