Skip to content

Commit

Permalink
Record errors from routines in tracing spans
Browse files Browse the repository at this point in the history
  • Loading branch information
cloneable authored and blackbeam committed Feb 14, 2023
1 parent 043d81a commit c851de7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/conn/routines/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ impl Routine<()> for ExecRoutine<'_> {
};

#[cfg(feature = "tracing")]
let fut = fut.instrument(span);
let fut = async {
fut.await.or_else(|e| {
tracing::error!(error = %e);
Err(e)
})
}
.instrument(span);

fut.boxed()
}
Expand Down
8 changes: 7 additions & 1 deletion src/conn/routines/next_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ where
};

#[cfg(feature = "tracing")]
let fut = fut.instrument(span);
let fut = async {
fut.await.or_else(|e| {
tracing::error!(error = %e);
Err(e)
})
}
.instrument(span);

fut.boxed()
}
Expand Down
8 changes: 7 additions & 1 deletion src/conn/routines/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ impl Routine<()> for PingRoutine {
};

#[cfg(feature = "tracing")]
let fut = fut.instrument(span);
let fut = async {
fut.await.or_else(|e| {
tracing::error!(error = %e);
Err(e)
})
}
.instrument(span);

fut.boxed()
}
Expand Down
9 changes: 8 additions & 1 deletion src/conn/routines/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl Routine<Arc<StmtInner>> for PrepareRoutine {

let packet = conn.read_packet().await?;
let mut inner_stmt = StmtInner::from_payload(&*packet, conn.id(), self.query.clone())?;

#[cfg(feature = "tracing")]
Span::current().record("mysql_async.statement.id", inner_stmt.id());

Expand All @@ -65,7 +66,13 @@ impl Routine<Arc<StmtInner>> for PrepareRoutine {
};

#[cfg(feature = "tracing")]
let fut = fut.instrument(span);
let fut = async {
fut.await.or_else(|e| {
tracing::error!(error = %e);
Err(e)
})
}
.instrument(span);

fut.boxed()
}
Expand Down
8 changes: 7 additions & 1 deletion src/conn/routines/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ impl<L: TracingLevel> Routine<()> for QueryRoutine<'_, L> {
};

#[cfg(feature = "tracing")]
let fut = fut.instrument(span);
let fut = async {
fut.await.or_else(|e| {
tracing::error!(error = %e);
Err(e)
})
}
.instrument(span);

fut.boxed()
}
Expand Down
8 changes: 7 additions & 1 deletion src/conn/routines/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ impl Routine<()> for ResetRoutine {
};

#[cfg(feature = "tracing")]
let fut = fut.instrument(span);
let fut = async {
fut.await.or_else(|e| {
tracing::error!(error = %e);
Err(e)
})
}
.instrument(span);

fut.boxed()
}
Expand Down

0 comments on commit c851de7

Please sign in to comment.