Skip to content

Commit b7547ed

Browse files
committed
feat: integrate Sentry with tracing to capture warn/error logs
- Add sentry-tracing integration - Filter events to send only WARN and ERROR to Sentry - Initialize tracing with Sentry layer before other logging
1 parent 71ae88a commit b7547ed

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bins/validator-node/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ sha2 = { workspace = true }
5353
rand = { workspace = true }
5454

5555
# Error tracking
56-
sentry = "0.46"
56+
sentry = { version = "0.46", features = ["tracing"] }
57+
sentry-tracing = "0.46"

bins/validator-node/src/main.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -264,30 +264,19 @@ impl std::fmt::Debug for Args {
264264

265265
#[tokio::main]
266266
async fn main() -> Result<()> {
267-
tracing_subscriber::fmt()
268-
.with_env_filter(
269-
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
270-
"info,validator_node=debug,platform_p2p_consensus=debug".into()
271-
}),
272-
)
273-
.init();
274-
275267
let args = Args::parse();
276268

277-
info!("Starting decentralized validator");
278-
info!("SudoOwner: {}", SUDO_KEY_SS58);
279-
280-
// Load keypair
269+
// Load keypair first to get hotkey for Sentry
281270
let keypair = load_keypair(&args)?;
282271
let validator_hotkey = keypair.ss58_address();
283-
info!("Validator hotkey: {}", validator_hotkey);
284272

285-
// Initialize Sentry for error tracking with validator hotkey as identifier
273+
// Initialize Sentry for error tracking (captures warn/error/panic)
286274
let _sentry_guard = sentry::init((
287275
"https://fb4324072ce6cfa8cb8a772ca37d1b19@o4510579978272768.ingest.us.sentry.io/4510934791094272",
288276
sentry::ClientOptions {
289277
release: sentry::release_name!(),
290278
send_default_pii: true,
279+
traces_sample_rate: 0.1,
291280
..Default::default()
292281
},
293282
));
@@ -300,6 +289,30 @@ async fn main() -> Result<()> {
300289
scope.set_tag("validator_hotkey", &validator_hotkey);
301290
});
302291

292+
// Initialize tracing with Sentry layer to capture warn/error logs
293+
use tracing_subscriber::prelude::*;
294+
tracing_subscriber::registry()
295+
.with(tracing_subscriber::fmt::layer().with_filter(
296+
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
297+
"info,validator_node=debug,platform_p2p_consensus=debug".into()
298+
}),
299+
))
300+
.with(sentry_tracing::layer().event_filter(|meta| {
301+
// Send warn and error events to Sentry
302+
match meta.level() {
303+
&tracing::Level::ERROR | &tracing::Level::WARN => {
304+
sentry_tracing::EventFilter::Event
305+
}
306+
_ => sentry_tracing::EventFilter::Ignore,
307+
}
308+
}))
309+
.init();
310+
311+
info!("Starting decentralized validator");
312+
info!("SudoOwner: {}", SUDO_KEY_SS58);
313+
info!("Validator hotkey: {}", validator_hotkey);
314+
info!("Sentry initialized - errors and warnings will be reported");
315+
303316
// Create data directory
304317
std::fs::create_dir_all(&args.data_dir)?;
305318
let data_dir = std::fs::canonicalize(&args.data_dir)?;

0 commit comments

Comments
 (0)