@@ -13,7 +13,7 @@ fn init_tracer() -> sdktrace::SdkTracerProvider {
1313 global:: set_text_map_propagator ( TraceContextPropagator :: new ( ) ) ;
1414 // Install stdout exporter pipeline to be able to retrieve the collected spans.
1515 let provider = sdktrace:: SdkTracerProvider :: builder ( )
16- . with_batch_exporter ( SpanExporter :: default ( ) )
16+ . with_simple_exporter ( SpanExporter :: default ( ) )
1717 . build ( ) ;
1818
1919 global:: set_tracer_provider ( provider. clone ( ) ) ;
@@ -43,10 +43,14 @@ async fn greet() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static
4343 let span = tracer
4444 . span_builder ( "Greeter/client" )
4545 . with_kind ( SpanKind :: Client )
46- . with_attributes ( [ KeyValue :: new ( "component" , "grpc" ) ] )
46+ . with_attributes ( [
47+ KeyValue :: new ( "rpc.system" , "grpc" ) ,
48+ KeyValue :: new ( "server.port" , 50052 ) ,
49+ KeyValue :: new ( "rpc.method" , "say_hello" ) ,
50+ ] )
4751 . start ( & tracer) ;
4852 let cx = Context :: current_with_span ( span) ;
49- let mut client = GreeterClient :: connect ( "http://[::1]:50051 " ) . await ?;
53+ let mut client = GreeterClient :: connect ( "http://[::1]:50052 " ) . await ?;
5054
5155 let mut request = tonic:: Request :: new ( HelloRequest {
5256 name : "Tonic" . into ( ) ,
@@ -58,16 +62,23 @@ async fn greet() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static
5862
5963 let response = client. say_hello ( request) . await ;
6064
65+ let span = cx. span ( ) ;
6166 let status = match response {
62- Ok ( _res) => "OK" . to_string ( ) ,
67+ Ok ( _res) => {
68+ span. set_attribute ( KeyValue :: new ( "response" , "OK" ) ) ;
69+ "OK" . to_string ( )
70+ }
6371 Err ( status) => {
6472 // Access the status code
6573 let status_code = status. code ( ) ;
74+ span. set_attribute ( KeyValue :: new (
75+ "response_code_desc" ,
76+ status_code. description ( ) ,
77+ ) ) ;
6678 status_code. to_string ( )
6779 }
6880 } ;
69- cx. span ( )
70- . add_event ( "Got response!" , vec ! [ KeyValue :: new( "status" , status) ] ) ;
81+ span. add_event ( "Got response!" , vec ! [ KeyValue :: new( "status" , status) ] ) ;
7182
7283 Ok ( ( ) )
7384}
0 commit comments