Alanxtl commented on issue #2554: URL: https://github.com/apache/dubbo-go/issues/2554#issuecomment-3306168030
# otel ability check - all test use new api and otel http exporter - 经验证 triple/dubbo/jsonrpc 协议的otel trace能力是没问题的 ## test case ### server 端代码 ```go ins, err := dubbo.NewInstance( dubbo.WithName("dubbo_otel_server"), dubbo.WithTracing( trace.WithEnabled(), trace.WithOtlpHttpExporter(), trace.WithW3cPropagator(), trace.WithAlwaysMode(), trace.WithEndpoint("127.0.0.1:4318"), trace.WithInsecure(), ), dubbo.WithProtocol( protocol.WithTriple(), protocol.WithPort(20000)), dubbo.WithProtocol( protocol.WithDubbo(), protocol.WithPort(20001)), dubbo.WithProtocol( protocol.WithJSONRPC(), protocol.WithPort(20002)), ) if err != nil { panic(err) } //Triple srv, err := ins.NewServer() if err != nil { panic(err) } if err = greet.RegisterGreetServiceHandler(srv, &GreetMultiRPCServer{}); err != nil { panic(err) } //Dubbo & JsonRPC if err = srv.Register(&GreetProvider{}, &common.ServiceInfo{}, server.WithInterface("GreetProvider")); err != nil { panic(err) } if err = srv.Serve(); err != nil { logger.Error(err) } ``` ### client 端代码 ```go func main() { // Initialize instance ins, err := initDubboInstance() if err != nil { panic(err) } // Call services using different protocols if err = callTripleService(ins); err != nil { logger.Error(err) } time.Sleep(5 * time.Second) // wait for span exported if err = callDubboService(ins); err != nil { logger.Error(err) } time.Sleep(5 * time.Second) // wait for span exported if err = callJsonRpcService(ins); err != nil { logger.Error(err) } time.Sleep(5 * time.Second) // wait for span exported } // Initialize Dubbo instance func initDubboInstance() (*dubbo.Instance, error) { return dubbo.NewInstance( dubbo.WithName("dubbo_otel_tracing_client"), dubbo.WithTracing( trace.WithEnabled(), trace.WithOtlpHttpExporter(), trace.WithW3cPropagator(), trace.WithAlwaysMode(), trace.WithEndpoint("127.0.0.1:4318"), trace.WithInsecure(), ), ) } // Call Triple protocol service func callTripleService(ins *dubbo.Instance) error { cli, err := ins.NewClient( client.WithClientProtocolTriple(), client.WithClientURL("127.0.0.1:20000"), ) if err != nil { return fmt.Errorf("failed to create triple client: %w", err) } svc, err := greet2.NewGreetService(cli) if err != nil { return fmt.Errorf("failed to create greet service: %w", err) } resp, err := svc.Greet(context.Background(), &greet2.GreetRequest{Name: "hello world"}) if err != nil { return fmt.Errorf("triple service call failed: %w", err) } logger.Infof("Greet triple response: %s", resp.Greeting) return nil } // Call Dubbo protocol service func callDubboService(ins *dubbo.Instance) error { cli, err := ins.NewClient( client.WithClientProtocolDubbo(), client.WithClientSerialization(constant.Hessian2Serialization), client.WithClientURL("127.0.0.1:20001"), ) if err != nil { return fmt.Errorf("failed to create dubbo client: %w", err) } conn, err := cli.Dial("GreetProvider") if err != nil { return fmt.Errorf("failed to dial dubbo service: %w", err) } var resp string if err := conn.CallUnary(context.Background(), []interface{}{"hello", "new", "dubbo"}, &resp, "SayHello"); err != nil { return fmt.Errorf("dubbo service call failed: %w", err) } logger.Infof("Get dubbo Response: %s", resp) return nil } // Call JsonRPC protocol service func callJsonRpcService(ins *dubbo.Instance) error { cli, err := ins.NewClient( client.WithClientProtocolJsonRPC(), client.WithClientSerialization(constant.JSONSerialization), client.WithClientURL("127.0.0.1:20002"), ) if err != nil { return fmt.Errorf("failed to create jsonrpc client: %w", err) } conn, err := cli.Dial("GreetProvider") if err != nil { return fmt.Errorf("failed to dial jsonrpc service: %w", err) } var resp string if err := conn.CallUnary(context.Background(), []interface{}{"hello", "new", "jsonrpc"}, &resp, "SayHello"); err != nil { return fmt.Errorf("jsonrpc service call failed: %w", err) } logger.Infof("Get jsonrpc Response: %s", resp) return nil } ``` <details> <summary>triple otel trace 数据</summary> resource_spans:{resource:{attributes:{key:"service.name" value:{string_value:"dubbo_otel_server"}} attributes:{key:"service.namespace" value:{string_value:"dubbo-go"}} attributes:{key:"service.version" value:{string_value:""}}} scope_spans:{scope:{name:"go.opentelemetry.io/otel" version:"1.21.0"} spans:{trace_id:"N\xc8[\xa5s\xa6\xf0\xb2\x8a#\x97\x91\xdc\xfcj{" span_id:"̈\r\x8a\xf1K!\xe1" parent_span_id:"\xbf\xa4\xa2}\xcf|\xa3\x7f" name:"Greet" kind:SPAN_KIND_SERVER start_time_unix_nano:1758183734704787429 end_time_unix_nano:1758183734704797481 attributes:{key:"rpc.system" value:{string_value:"apache_dubbo"}} attributes:{key:"rpc.service" value:{string_value:"greet.GreetService"}} attributes:{key:"rpc.method" value:{string_value:"Greet"}} status:{code:STATUS_CODE_OK}}}} resource_spans:{resource:{attributes:{key:"service.name" value:{string_value:"dubbo_otel_client"}} attributes:{key:"service.namespace" value:{string_value:"dubbo-go"}} attributes:{key:"service.version" value:{string_value:""}}} scope_spans:{scope:{name:"go.opentelemetry.io/otel" version:"1.21.0"} spans:{trace_id:"N\xc8[\xa5s\xa6\xf0\xb2\x8a#\x97\x91\xdc\xfcj{" span_id:"\xbf\xa4\xa2}\xcf|\xa3\x7f" name:"Greet" kind:SPAN_KIND_CLIENT start_time_unix_nano:1758183734703976364 end_time_unix_nano:1758183734706607662 attributes:{key:"rpc.system" value:{string_value:"apache_dubbo"}} attributes:{key:"rpc.service" value:{string_value:"greet.GreetService"}} attributes:{key:"rpc.method" value:{string_value:"Greet"}} status:{code:STATUS_CODE_OK}}}} </details> <details> <summary>dubbo otel trace 数据</summary> resource_spans:{resource:{attributes:{key:"service.name" value:{string_value:"dubbo_otel_server"}} attributes:{key:"service.namespace" value:{string_value:"dubbo-go"}} attributes:{key:"service.version" value:{string_value:""}}} scope_spans:{scope:{name:"go.opentelemetry.io/otel" version:"1.21.0"} spans:{trace_id:"O*\xf7\xacI$\xb3\x85.\xa0%\xf8\x9b#bg" span_id:" \xfa\x85-\xc1C\x05M" name:"SayHello" kind:SPAN_KIND_SERVER start_time_unix_nano:1758183739710466413 end_time_unix_nano:1758183739710511646 attributes:{key:"rpc.system" value:{string_value:"apache_dubbo"}} attributes:{key:"rpc.service" value:{string_value:"GreetProvider"}} attributes:{key:"rpc.method" value:{string_value:"SayHello"}} status:{code:STATUS_CODE_OK}}}} resource_spans:{resource:{attributes:{key:"service.name" value:{string_value:"dubbo_otel_client"}} attributes:{key:"service.namespace" value:{string_value:"dubbo-go"}} attributes:{key:"service.version" value:{string_value:""}}} scope_spans:{scope:{name:"go.opentelemetry.io/otel" version:"1.21.0"} spans:{trace_id:"r\x85\xd8O>\xa7\xc1\xe7\x0e\x10\xe7^\xa2\xe1\xb2\xfd" span_id:"\xfc\xc75?pr\xfdR" name:"SayHello" kind:SPAN_KIND_CLIENT start_time_unix_nano:1758183739710214377 end_time_unix_nano:1758183739710646696 attributes:{key:"rpc.system" value:{string_value:"apache_dubbo"}} attributes:{key:"rpc.service" value:{string_value:"GreetProvider"}} attributes:{key:"rpc.method" value:{string_value:"SayHello"}} status:{code:STATUS_CODE_OK}}}} </details> <details> <summary>jsonrpc otel trace 数据</summary> resource_spans:{resource:{attributes:{key:"service.name" value:{string_value:"dubbo_otel_server"}} attributes:{key:"service.namespace" value:{string_value:"dubbo-go"}} attributes:{key:"service.version" value:{string_value:""}}} scope_spans:{scope:{name:"go.opentelemetry.io/otel" version:"1.21.0"} spans:{trace_id:"\x9eA&\x9dA^`\xd6\xcbM\x15\x11\x16x=@" span_id:"=J\xa7N\x02\x13\xbfX" name:"SayHello" kind:SPAN_KIND_SERVER start_time_unix_nano:1758183744711704645 end_time_unix_nano:1758183744711724089 attributes:{key:"rpc.system" value:{string_value:"apache_dubbo"}} attributes:{key:"rpc.service" value:{string_value:"GreetProvider"}} attributes:{key:"rpc.method" value:{string_value:"SayHello"}} status:{code:STATUS_CODE_OK}}}} resource_spans:{resource:{attributes:{key:"service.name" value:{string_value:"dubbo_otel_client"}} attributes:{key:"service.namespace" value:{string_value:"dubbo-go"}} attributes:{key:"service.version" value:{string_value:""}}} scope_spans:{scope:{name:"go.opentelemetry.io/otel" version:"1.21.0"} spans:{trace_id:"،\x9flk\x80\x7f*\x9a-BVg\x88Dr" span_id:"b\xfa\x8b\x1b\xba\xb7\xcbv" name:"SayHello" kind:SPAN_KIND_CLIENT start_time_unix_nano:1758183744711144947 end_time_unix_nano:1758183744711939480 attributes:{key:"rpc.system" value:{string_value:"apache_dubbo"}} attributes:{key:"rpc.service" value:{string_value:"GreetProvider"}} attributes:{key:"rpc.method" value:{string_value:"SayHello"}} status:{code:STATUS_CODE_OK}}}} </details> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For additional commands, e-mail: notifications-h...@dubbo.apache.org