Skip to content

Commit

Permalink
v1.16: tools: add setup_tracing (backport of #248) (#256)
Browse files Browse the repository at this point in the history
(cherry picked from commit ceac499)

Co-authored-by: Kirill Fomichev <[email protected]>
  • Loading branch information
mergify[bot] and fanatid authored Dec 7, 2023
1 parent 5523b59 commit 715dd2f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 32 deletions.
6 changes: 5 additions & 1 deletion yellowstone-grpc-tools/config-kafka.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
17 changes: 2 additions & 15 deletions yellowstone-grpc-tools/src/bin/grpc-google-pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -24,6 +19,7 @@ use {
prom,
},
prom::{run_server as prometheus_run_server, GprcMessageKind},
setup_tracing,
},
};

Expand Down Expand Up @@ -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();
Expand Down
17 changes: 2 additions & 15 deletions yellowstone-grpc-tools/src/bin/grpc-kafka.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -27,6 +22,7 @@ use {
prom,
},
prom::{run_server as prometheus_run_server, GprcMessageKind},
setup_tracing,
},
};

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion yellowstone-grpc-tools/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions yellowstone-grpc-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;
Expand Down

0 comments on commit 715dd2f

Please sign in to comment.