Skip to content

Commit 9b46cbc

Browse files
committed
feat(o11y): add error extraction to DiscoveryOperation
1 parent c6c4d38 commit 9b46cbc

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/lro/src/internal/discovery.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::{
2727
Poller, PollingBackoffPolicy, PollingErrorPolicy, PollingResult, Result,
2828
sealed::Poller as SealedPoller,
2929
};
30+
use google_cloud_gax::error::rpc::Status;
3031
use google_cloud_gax::polling_state::PollingState;
3132
use google_cloud_gax::retry_result::RetryResult;
3233
use std::sync::Arc;
@@ -54,6 +55,11 @@ pub trait DiscoveryOperation {
5455
///
5556
/// It may be `None` in which case the polling loop stops.
5657
fn name(&self) -> Option<&String>;
58+
59+
/// Returns the error status of the operation, if any.
60+
fn error(&self) -> Option<Status> {
61+
None
62+
}
5763
}
5864

5965
pub fn new_discovery_poller<S, SF, Q, QF, O>(

src/lro/src/internal/tracing.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,32 @@ 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 span = &$span;
78+
let op = &$op;
79+
let done = $crate::internal::DiscoveryOperation::done(op);
80+
span.record("gcp.longrunning.done", done);
81+
if done {
82+
let error = $crate::internal::DiscoveryOperation::error(op);
83+
let code = error.as_ref().map(|e| e.code as i32).unwrap_or(0);
84+
span.record("gcp.longrunning.status_code", code);
85+
if let Some(status) = error {
86+
span.record("otel.status_code", "ERROR");
87+
span.record("otel.status_description", &status.message);
88+
span.record("rpc.response.status_code", status.code as i32);
89+
span.record("error.type", status.code.to_string());
90+
}
91+
}
92+
};
93+
}
94+
95+
impl LroRecorder {
7196
/// Creates a new clone of `LroRecorder` carrying the specified LRO polling attempt count.
7297
///
7398
/// Since `LroRecorder` is immutable to guarantee thread-safety, this updates the context

0 commit comments

Comments
 (0)