diff --git a/src/lro/src/internal/discovery.rs b/src/lro/src/internal/discovery.rs index 98f65319ec..a36ca045c9 100644 --- a/src/lro/src/internal/discovery.rs +++ b/src/lro/src/internal/discovery.rs @@ -27,6 +27,7 @@ use crate::{ Poller, PollingBackoffPolicy, PollingErrorPolicy, PollingResult, Result, sealed::Poller as SealedPoller, }; +use google_cloud_gax::error::rpc::Status; use google_cloud_gax::polling_state::PollingState; use google_cloud_gax::retry_result::RetryResult; use std::sync::Arc; @@ -54,6 +55,11 @@ pub trait DiscoveryOperation { /// /// It may be `None` in which case the polling loop stops. fn name(&self) -> Option<&String>; + + /// Returns the error status of the operation, if any. + fn error(&self) -> Option { + None + } } pub fn new_discovery_poller( diff --git a/src/lro/src/internal/tracing.rs b/src/lro/src/internal/tracing.rs index 4d054b8bbf..7919111609 100644 --- a/src/lro/src/internal/tracing.rs +++ b/src/lro/src/internal/tracing.rs @@ -67,7 +67,32 @@ impl LroRecorder { pub fn attempt_count(&self) -> Option { self.attempt_count } +} + +/// Helper macro to record telemetry for Discovery LROs. +#[macro_export] +#[doc(hidden)] +macro_rules! record_discovery_polling_result { + ($span:expr, $op:expr) => { + let span = &$span; + let op = &$op; + let done = $crate::internal::DiscoveryOperation::done(op); + span.record("gcp.longrunning.done", done); + if done { + let error = $crate::internal::DiscoveryOperation::error(op); + let code = error.as_ref().map(|e| e.code as i32).unwrap_or(0); + span.record("gcp.longrunning.status_code", code); + if let Some(status) = error { + span.record("otel.status_code", "ERROR"); + span.record("otel.status_description", &status.message); + span.record("rpc.response.status_code", status.code as i32); + span.record("error.type", status.code.to_string()); + } + } + }; +} +impl LroRecorder { /// Creates a new clone of `LroRecorder` carrying the specified LRO polling attempt count. /// /// Since `LroRecorder` is immutable to guarantee thread-safety, this updates the context @@ -98,6 +123,28 @@ impl LroRecorder { } } +/// Injects LRO-specific telemetry attributes into the active span. +#[macro_export] +#[doc(hidden)] +macro_rules! record_polling_attributes { + ($span:expr) => { + #[cfg(google_cloud_unstable_tracing)] + { + if let Some(recorder) = $crate::LroRecorder::current() { + if let Some(attempt) = recorder.attempt_count() { + let span = &$span; + span.record("gcp.longrunning.poll_attempt_count", attempt); + span.record("gcp.longrunning.done", false); + } + } + } + #[cfg(not(google_cloud_unstable_tracing))] + { + let _ = &$span; + } + }; +} + /// Decorate a poller with tracing information. #[derive(Clone, Debug)] pub struct Tracing

{