Skip to content

Commit 287dd86

Browse files
authored
Merge pull request #230 from cloneable/issue223-record-errors-spans
Record errors from routines in tracing spans
2 parents 043d81a + 9effa91 commit 287dd86

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

src/conn/routines/exec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use futures_core::future::BoxFuture;
44
use futures_util::FutureExt;
55
use mysql_common::{packets::ComStmtExecuteRequestBuilder, params::Params};
66
#[cfg(feature = "tracing")]
7-
use tracing::{field, info_span, Instrument, Level, Span};
7+
use tracing::{field, info_span, Level, Span};
88

99
use crate::{BinaryProtocol, Conn, DriverError, Statement};
1010

@@ -104,7 +104,7 @@ impl Routine<()> for ExecRoutine<'_> {
104104
};
105105

106106
#[cfg(feature = "tracing")]
107-
let fut = fut.instrument(span);
107+
let fut = instrument_result!(fut, span);
108108

109109
fut.boxed()
110110
}

src/conn/routines/next_set.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::marker::PhantomData;
33
use futures_core::future::BoxFuture;
44
use futures_util::FutureExt;
55
#[cfg(feature = "tracing")]
6-
use tracing::{debug_span, Instrument};
6+
use tracing::debug_span;
77

88
use crate::{queryable::Protocol, Conn};
99

@@ -36,7 +36,7 @@ where
3636
};
3737

3838
#[cfg(feature = "tracing")]
39-
let fut = fut.instrument(span);
39+
let fut = instrument_result!(fut, span);
4040

4141
fut.boxed()
4242
}

src/conn/routines/ping.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use futures_core::future::BoxFuture;
22
use futures_util::FutureExt;
33
use mysql_common::constants::Command;
44
#[cfg(feature = "tracing")]
5-
use tracing::{debug_span, Instrument};
5+
use tracing::debug_span;
66

77
use crate::Conn;
88

@@ -24,7 +24,7 @@ impl Routine<()> for PingRoutine {
2424
};
2525

2626
#[cfg(feature = "tracing")]
27-
let fut = fut.instrument(span);
27+
let fut = instrument_result!(fut, span);
2828

2929
fut.boxed()
3030
}

src/conn/routines/prepare.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use futures_core::future::BoxFuture;
44
use futures_util::FutureExt;
55
use mysql_common::constants::Command;
66
#[cfg(feature = "tracing")]
7-
use tracing::{field, info_span, Instrument, Level, Span};
7+
use tracing::{field, info_span, Level, Span};
88

99
use crate::{queryable::stmt::StmtInner, Conn};
1010

@@ -48,6 +48,7 @@ impl Routine<Arc<StmtInner>> for PrepareRoutine {
4848

4949
let packet = conn.read_packet().await?;
5050
let mut inner_stmt = StmtInner::from_payload(&*packet, conn.id(), self.query.clone())?;
51+
5152
#[cfg(feature = "tracing")]
5253
Span::current().record("mysql_async.statement.id", inner_stmt.id());
5354

@@ -65,7 +66,7 @@ impl Routine<Arc<StmtInner>> for PrepareRoutine {
6566
};
6667

6768
#[cfg(feature = "tracing")]
68-
let fut = fut.instrument(span);
69+
let fut = instrument_result!(fut, span);
6970

7071
fut.boxed()
7172
}

src/conn/routines/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use futures_core::future::BoxFuture;
44
use futures_util::FutureExt;
55
use mysql_common::constants::Command;
66
#[cfg(feature = "tracing")]
7-
use tracing::{field, span_enabled, Instrument, Level};
7+
use tracing::{field, span_enabled, Level};
88

99
use crate::tracing_utils::TracingLevel;
1010
use crate::{Conn, TextProtocol};
@@ -54,7 +54,7 @@ impl<L: TracingLevel> Routine<()> for QueryRoutine<'_, L> {
5454
};
5555

5656
#[cfg(feature = "tracing")]
57-
let fut = fut.instrument(span);
57+
let fut = instrument_result!(fut, span);
5858

5959
fut.boxed()
6060
}

src/conn/routines/reset.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use futures_core::future::BoxFuture;
22
use futures_util::FutureExt;
33
use mysql_common::constants::Command;
44
#[cfg(feature = "tracing")]
5-
use tracing::{debug_span, Instrument};
5+
use tracing::debug_span;
66

77
use crate::Conn;
88

@@ -25,7 +25,7 @@ impl Routine<()> for ResetRoutine {
2525
};
2626

2727
#[cfg(feature = "tracing")]
28-
let fut = fut.instrument(span);
28+
let fut = instrument_result!(fut, span);
2929

3030
fut.boxed()
3131
}

src/tracing_utils.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,16 @@ macro_rules! create_span {
3838
}
3939
}
4040
}
41+
42+
#[cfg(feature = "tracing")]
43+
macro_rules! instrument_result {
44+
($fut:expr, $span:expr) => {{
45+
let fut = async {
46+
$fut.await.or_else(|e| {
47+
tracing::error!(error = %e);
48+
Err(e)
49+
})
50+
};
51+
<_ as tracing::Instrument>::instrument(fut, $span)
52+
}};
53+
}

0 commit comments

Comments
 (0)