@@ -67,7 +67,30 @@ impl LroRecorder {
6767 pub fn attempt_count ( & self ) -> Option < u32 > {
6868 self . attempt_count
6969 }
70+ }
7071
72+ /// Helper macro to record telemetry for Discovery LROs.
73+ #[ macro_export]
74+ #[ doc( hidden) ]
75+ macro_rules! record_discovery_polling_result {
76+ ( $span: expr, $op: expr) => {
77+ let done = $crate:: internal:: DiscoveryOperation :: done( $op) ;
78+ $span. record( "gcp.longrunning.done" , done) ;
79+ if done {
80+ let error = $crate:: internal:: DiscoveryOperation :: error( $op) ;
81+ let code = error. as_ref( ) . map( |e| e. code as i32 ) . unwrap_or( 0 ) ;
82+ $span. record( "gcp.longrunning.status_code" , code) ;
83+ if let Some ( status) = error {
84+ $span. record( "otel.status_code" , "ERROR" ) ;
85+ $span. record( "otel.status_description" , & status. message) ;
86+ $span. record( "rpc.response.status_code" , status. code as i32 ) ;
87+ $span. record( "error.type" , status. code. to_string( ) ) ;
88+ }
89+ }
90+ } ;
91+ }
92+
93+ impl LroRecorder {
7194 /// Creates a new clone of `LroRecorder` carrying the specified LRO polling attempt count.
7295 ///
7396 /// Since `LroRecorder` is immutable to guarantee thread-safety, this updates the context
@@ -105,10 +128,12 @@ macro_rules! record_polling_attributes {
105128 ( $span: expr) => {
106129 #[ cfg( google_cloud_unstable_tracing) ]
107130 {
108- if let Ok ( attempt) = $crate:: POLL_ATTEMPT_COUNT . try_with( |c| * c) {
109- let span = & $span;
110- span. record( "gcp.longrunning.poll_attempt_count" , attempt) ;
111- span. record( "gcp.longrunning.done" , false ) ;
131+ if let Some ( recorder) = $crate:: LroRecorder :: current( ) {
132+ if let Some ( attempt) = recorder. attempt_count( ) {
133+ let span = & $span;
134+ span. record( "gcp.longrunning.poll_attempt_count" , attempt) ;
135+ span. record( "gcp.longrunning.done" , false ) ;
136+ }
112137 }
113138 }
114139 #[ cfg( not( google_cloud_unstable_tracing) ) ]
0 commit comments