Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lro/src/internal/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Status> {
None
}
}

pub fn new_discovery_poller<S, SF, Q, QF, O>(
Expand Down
47 changes: 47 additions & 0 deletions src/lro/src/internal/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,32 @@ impl LroRecorder {
pub fn attempt_count(&self) -> Option<u32> {
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());
}
}
};
}
Comment thread
haphungw marked this conversation as resolved.

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
Expand Down Expand Up @@ -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<P> {
Expand Down
Loading