tools: add setup_tracing (#248)

This commit is contained in:
Kirill Fomichev 2023-12-06 21:53:03 -05:00 committed by GitHub
parent 760f189ba4
commit ceac499c8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 32 deletions

View File

@ -20,7 +20,11 @@
"endpoint": "http://127.0.0.1:10000",
"x_token": null,
"request": {
"slots": ["client"],
"slots": {
"client": {
"filter_by_commitment": null
}
},
"blocks": {
"client": {
"account_include": [],

View File

@ -6,11 +6,6 @@ use {
std::{net::SocketAddr, time::Duration},
tokio::{task::JoinSet, time::sleep},
tracing::{info, warn},
tracing_subscriber::{
filter::{EnvFilter, LevelFilter},
layer::SubscriberExt,
util::SubscriberInitExt,
},
yellowstone_grpc_client::GeyserGrpcClient,
yellowstone_grpc_proto::{
prelude::{subscribe_update::UpdateOneof, SubscribeUpdate},
@ -24,6 +19,7 @@ use {
prom,
},
prom::{run_server as prometheus_run_server, GprcMessageKind},
setup_tracing,
},
};
@ -259,16 +255,7 @@ impl ArgsAction {
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Setup tracing
let is_atty = atty::is(atty::Stream::Stdout) && atty::is(atty::Stream::Stderr);
let io_layer = tracing_subscriber::fmt::layer().with_ansi(is_atty);
let level_layer = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy();
tracing_subscriber::registry()
.with(io_layer)
.with(level_layer)
.try_init()?;
setup_tracing()?;
// Parse args
let args = Args::parse();

View File

@ -7,11 +7,6 @@ use {
std::{net::SocketAddr, sync::Arc, time::Duration},
tokio::task::JoinSet,
tracing::{debug, trace, warn},
tracing_subscriber::{
filter::{EnvFilter, LevelFilter},
layer::SubscriberExt,
util::SubscriberInitExt,
},
yellowstone_grpc_client::GeyserGrpcClient,
yellowstone_grpc_proto::{
prelude::{subscribe_update::UpdateOneof, SubscribeUpdate},
@ -27,6 +22,7 @@ use {
prom,
},
prom::{run_server as prometheus_run_server, GprcMessageKind},
setup_tracing,
},
};
@ -392,16 +388,7 @@ impl ArgsAction {
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Setup tracing
let is_atty = atty::is(atty::Stream::Stdout) && atty::is(atty::Stream::Stderr);
let io_layer = tracing_subscriber::fmt::layer().with_ansi(is_atty);
let level_layer = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy();
tracing_subscriber::registry()
.with(io_layer)
.with(level_layer)
.try_init()?;
setup_tracing()?;
// Parse args
let args = Args::parse();

View File

@ -184,9 +184,10 @@ impl GrpcRequestToProto<SubscribeRequestFilterBlocks> for ConfigGrpcRequestBlock
}
}
#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
#[derive(Debug, Default, Clone, Copy, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum ConfigGrpcRequestCommitment {
#[default]
Processed,
Confirmed,
Finalized,

View File

@ -13,8 +13,26 @@ pub mod version;
use {
futures::future::{BoxFuture, FutureExt},
tokio::signal::unix::{signal, SignalKind},
tracing_subscriber::{
filter::{EnvFilter, LevelFilter},
layer::SubscriberExt,
util::SubscriberInitExt,
},
};
pub fn setup_tracing() -> anyhow::Result<()> {
let is_atty = atty::is(atty::Stream::Stdout) && atty::is(atty::Stream::Stderr);
let io_layer = tracing_subscriber::fmt::layer().with_ansi(is_atty);
let level_layer = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy();
tracing_subscriber::registry()
.with(io_layer)
.with(level_layer)
.try_init()?;
Ok(())
}
pub fn create_shutdown() -> anyhow::Result<BoxFuture<'static, ()>> {
let mut sigint = signal(SignalKind::interrupt())?;
let mut sigterm = signal(SignalKind::terminate())?;