Skip to content

Commit

Permalink
Clean up and improve logs and tracing span data
Browse files Browse the repository at this point in the history
  • Loading branch information
elkowar committed Feb 2, 2024
1 parent 2ad6c78 commit 058d7e5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/gateway/bridge/shard_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ impl ShardRunner {
#[cfg(feature = "collector")]
self.collectors.lock().expect("poison").retain_mut(|callback| (callback.0)(&event));

debug!(
event.name = %event.name().unwrap_or_default(),
"[ShardRunner {:?}] Dispatching event", self.shard.shard_info(),
);

dispatch_model(
event,
self.make_context(),
Expand Down
5 changes: 4 additions & 1 deletion src/gateway/shard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ impl Shard {
self.stage
}

#[cfg_attr(feature = "tracing_instrument", tracing::instrument(skip(self)))]
#[cfg_attr(feature = "tracing_instrument", tracing::instrument(
skip_all,
fields(%seq, event.data = ?event, event.name = event.name().unwrap_or_default())
))]
fn handle_gateway_dispatch(&mut self, seq: u64, event: &Event) -> Option<ShardAction> {
if seq > self.seq + 1 {
warn!("[{:?}] Sequence off; them: {}, us: {}", self.shard_info, seq, self.seq);
Expand Down
12 changes: 11 additions & 1 deletion src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4683,9 +4683,18 @@ impl Http {
/// # Ok(())
/// # }
/// ```
#[cfg_attr(feature = "tracing_instrument", tracing::instrument)]
#[cfg_attr(feature = "tracing_instrument", tracing::instrument(
skip_all,
fields(
req.route = ?req.route,
url.full = %req.route.path(),
http.request.method = req.method.reqwest_method().as_str(),
http.response.status,
)
))]
pub async fn request(&self, req: Request<'_>) -> Result<ReqwestResponse> {
let method = req.method.reqwest_method();
debug!(url.full = %req.route.path(), http.request.method = method.as_str(), "Sending request");
let response = if let Some(ratelimiter) = &self.ratelimiter {
ratelimiter.perform(req).await?
} else {
Expand All @@ -4695,6 +4704,7 @@ impl Http {
self.client.execute(request).await?
};

tracing::Span::current().record("http.response.status", response.status().as_str());
if response.status().is_success() {
Ok(response)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/http/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<'a> Request<'a> {
/// # Errors
///
/// Errors if the given proxy URL is invalid, or the token cannot be parsed into a HTTP header.
#[cfg_attr(feature = "tracing_instrument", tracing::instrument(skip(token)))]
#[cfg_attr(feature = "tracing_instrument", tracing::instrument(skip_all))]
pub fn build(
self,
client: &Client,
Expand Down

0 comments on commit 058d7e5

Please sign in to comment.