Skip to content

Commit 7808836

Browse files
apollo_http_server,apollo_dashboard: propagate tracing span into tokio::spawn in add_tx_inner (#13981)
tokio::spawn does not inherit the caller's tracing span, so logs emitted inside the spawned task were orphaned from the add_tx instrument span. Fix by attaching the current span via .instrument(tracing::Span::current()). Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8d0c6c0 commit 7808836

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

crates/apollo_dashboard/resources/dev_grafana.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
"exprs": [
6464
"sum by (add_tx_failure_reason) (increase(gateway_add_tx_failure{cluster=~\"$cluster\", namespace=~\"$namespace\", pod=~\"$pod\"}[$__range])) > 0"
6565
],
66-
"extra_params": {}
66+
"extra_params": {
67+
"log_query": "\"Error while adding transaction\""
68+
}
6769
}
6870
],
6971
"collapsed": false
@@ -1081,7 +1083,9 @@
10811083
"exprs": [
10821084
"sum by (add_tx_failure_reason) (increase(gateway_add_tx_failure{cluster=~\"$cluster\", namespace=~\"$namespace\", pod=~\"$pod\"}[$__range])) > 0"
10831085
],
1084-
"extra_params": {}
1086+
"extra_params": {
1087+
"log_query": "\"Error while adding transaction\""
1088+
}
10851089
},
10861090
{
10871091
"title": "Transactions Sent to Mempool by Type",

crates/apollo_dashboard/src/panels/gateway.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub(crate) fn get_panel_gateway_add_tx_failure_by_reason() -> Panel {
9191
),
9292
PanelType::Stat,
9393
)
94+
.with_log_query("Error while adding transaction")
9495
}
9596

9697
fn get_panel_gateway_transactions_failure_rate() -> Panel {

crates/apollo_http_server/src/http_server.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use tokio::sync::watch::{channel, Receiver, Sender};
3737
use tokio::time;
3838
use tower_http::decompression::RequestDecompressionLayer;
3939
use tower_http::limit::RequestBodyLimitLayer;
40-
use tracing::{debug, info, instrument, warn};
40+
use tracing::{debug, info, instrument, warn, Instrument};
4141

4242
use crate::deprecated_gateway_transaction::DeprecatedGatewayTransactionV3;
4343
use crate::errors::{HttpServerError, HttpServerRunError};
@@ -299,14 +299,17 @@ async fn add_tx_inner(
299299
.and_then(|region| region.to_str().ok())
300300
.unwrap_or("N/A")
301301
.to_string();
302-
let add_tx_result = tokio::spawn(async move {
303-
let add_tx_result = app_state.gateway_client.add_tx(gateway_input).await.map_err(|e| {
304-
debug!("Error while adding transaction: {}", e);
305-
HttpServerError::from(Box::new(e))
306-
});
307-
record_added_transactions(&add_tx_result, &region);
308-
add_tx_result
309-
})
302+
let add_tx_result = tokio::spawn(
303+
async move {
304+
let add_tx_result = app_state.gateway_client.add_tx(gateway_input).await.map_err(|e| {
305+
debug!("Error while adding transaction: {}", e);
306+
HttpServerError::from(Box::new(e))
307+
});
308+
record_added_transactions(&add_tx_result, &region);
309+
add_tx_result
310+
}
311+
.instrument(tracing::Span::current()),
312+
)
310313
.await
311314
.expect("Should be able to get add_tx result");
312315

0 commit comments

Comments
 (0)