sogou / srpc

RPC framework based on C++ Workflow. Supports SRPC, Baidu bRPC, Tencent tRPC, thrift protocols.
Apache License 2.0
1.95k stars 386 forks source link

Add trans_info through trpc protocol. #327

Closed holmes1412 closed 1 year ago

holmes1412 commented 1 year ago

1. 修改内容

更改rpc_module和trpc协议:

  1. 增加trpc协议中对trans_info的透传;
  2. 更新RPCTraceFilter使其可派生;
  3. 修复调用get_meta_module_data()和serialize_meta()的时机;

2. 参考资料

trans_info作为kv表格,内容参考:https://www.w3.org/TR/trace-context/#traceparent-header-field-values

已支持

待支持

3. 上报示例

resource_spans {
  resource {
    attributes {
      key: "rpc.method"
      value {
        string_value: "/trpc.test.helloworld.Greeter/SayHello"
      }
    }
    attributes {
      key: "service.name"
      value {
        string_value: "MyPlatformName.MyAppName.MyServiceName.demo"
      }
    }
    attributes {
      key: "target"
      value {
        string_value: "MyPlatformName.MyAppName.MyServiceName"
      }
    }
    attributes {
      key: "rpc.service"
      value {
        string_value: "trpc.test.helloworld.Greeter"
      }
    }
  }
  instrumentation_library_spans {
    spans {
      trace_id: "00101950c6435d2702101950c6435d27"
      span_id: "00606157c6435d27"
      parent_span_id: "fe3a8157941acc5e"
      name: "/trpc.test.helloworld.Greeter/SayHello"
      kind: SPAN_KIND_SERVER
      start_time_unix_nano: 1690208728466126450
      end_time_unix_nano: 1690208728466358808
      attributes {
        key: "rpc.system"
        value {
          string_value: "srpc"
        }
      }
      attributes {
        key: "affinity_attribute"
        value {
          string_value: "/-trpc.test.helloworld.Greeter/SayHello"
        }
      }
      attributes {
        key: "framework_ret"
        value {
          string_value: "1"
        }
      }
      attributes {
        key: "net.peer.ip"
        value {
          string_value: "127.0.0.1"
        }
      }
      attributes {
        key: "net.peer.port"
        value {
          int_value: 57526
        }
      }
      attributes {
        key: "rpc.method"
        value {
          string_value: "/trpc.test.helloworld.Greeter/SayHello"
        }
      }
      attributes {
        key: "rpc.service"
        value {
          string_value: "trpc.test.helloworld.Greeter"
        }
      }
      attributes {
        key: "server.address"
        value {
          string_value: "127.0.0.1"
        }
      }
      attributes {
        key: "server.port"
        value {
          int_value: 57526
        }
      }
      attributes {
        key: "status_type"
        value {
          string_value: "success"
        }
      }
      status {
        code: STATUS_CODE_OK
      }
    }
  }
}