From a3c4a5b08beac06c217b720cc8766658bc7bf496 Mon Sep 17 00:00:00 2001 From: haphungw Date: Wed, 3 Jun 2026 22:35:37 +0000 Subject: [PATCH 1/2] feat(o11y): add record_polling_attributes macro --- src/lro/src/internal/tracing.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lro/src/internal/tracing.rs b/src/lro/src/internal/tracing.rs index 4d054b8bbf..48f009f80b 100644 --- a/src/lro/src/internal/tracing.rs +++ b/src/lro/src/internal/tracing.rs @@ -98,6 +98,21 @@ 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 Ok(attempt) = $crate::POLL_ATTEMPT_COUNT.try_with(|c| *c) { + $span.record("gcp.longrunning.poll_attempt_count", attempt); + $span.record("gcp.longrunning.done", false); + } + } + }; +} + /// Decorate a poller with tracing information. #[derive(Clone, Debug)] pub struct Tracing

{ From c6c4d38896b744695b7eb171b968df631ff7b884 Mon Sep 17 00:00:00 2001 From: haphungw Date: Wed, 3 Jun 2026 22:41:48 +0000 Subject: [PATCH 2/2] bind span expression to avoid multiple evaluation --- src/lro/src/internal/tracing.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lro/src/internal/tracing.rs b/src/lro/src/internal/tracing.rs index 48f009f80b..8e53398331 100644 --- a/src/lro/src/internal/tracing.rs +++ b/src/lro/src/internal/tracing.rs @@ -105,11 +105,18 @@ macro_rules! record_polling_attributes { ($span:expr) => { #[cfg(google_cloud_unstable_tracing)] { - if let Ok(attempt) = $crate::POLL_ATTEMPT_COUNT.try_with(|c| *c) { - $span.record("gcp.longrunning.poll_attempt_count", attempt); - $span.record("gcp.longrunning.done", false); + 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; + } }; }