@@ -13,7 +13,7 @@ fn init_tracer() -> sdktrace::SdkTracerProvider {
13
13
global:: set_text_map_propagator ( TraceContextPropagator :: new ( ) ) ;
14
14
// Install stdout exporter pipeline to be able to retrieve the collected spans.
15
15
let provider = sdktrace:: SdkTracerProvider :: builder ( )
16
- . with_batch_exporter ( SpanExporter :: default ( ) )
16
+ . with_simple_exporter ( SpanExporter :: default ( ) )
17
17
. build ( ) ;
18
18
19
19
global:: set_tracer_provider ( provider. clone ( ) ) ;
@@ -43,10 +43,14 @@ async fn greet() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static
43
43
let span = tracer
44
44
. span_builder ( "Greeter/client" )
45
45
. 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
+ ] )
47
51
. start ( & tracer) ;
48
52
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 ?;
50
54
51
55
let mut request = tonic:: Request :: new ( HelloRequest {
52
56
name : "Tonic" . into ( ) ,
@@ -58,16 +62,23 @@ async fn greet() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static
58
62
59
63
let response = client. say_hello ( request) . await ;
60
64
65
+ let span = cx. span ( ) ;
61
66
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
+ }
63
71
Err ( status) => {
64
72
// Access the status code
65
73
let status_code = status. code ( ) ;
74
+ span. set_attribute ( KeyValue :: new (
75
+ "response_code_desc" ,
76
+ status_code. description ( ) ,
77
+ ) ) ;
66
78
status_code. to_string ( )
67
79
}
68
80
} ;
69
- cx. span ( )
70
- . add_event ( "Got response!" , vec ! [ KeyValue :: new( "status" , status) ] ) ;
81
+ span. add_event ( "Got response!" , vec ! [ KeyValue :: new( "status" , status) ] ) ;
71
82
72
83
Ok ( ( ) )
73
84
}
0 commit comments