Skip to content

Commit

Permalink
Logging & metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Jan 26, 2024
1 parent c6a15c4 commit 2874464
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 8 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target/
.git
README.md
.env
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RUST_LOG=info
LOCAL=true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.env
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4.4.18", features = ["derive"] }
clap = { version = "4.4.18", features = ["derive", "env"] }
config = "0.13.4"
dotenv = "0.15.0"
criterion = "0.5.1"
eyre = "0.6.11"
sqlx = { version = "0.7.3", features = [
Expand All @@ -17,6 +18,8 @@ sqlx = { version = "0.7.3", features = [
telemetry-batteries = { git = "https://github.com/worldcoin/telemetry-batteries.git", rev = "c6816624415ae194da5203a5161621a9e10ad3b0" }
tokio = { version = "1.35.1", features = ["macros"] }
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
metrics = "0.21.1"

[[bin]]
name = "mpc-node"
Expand Down
41 changes: 35 additions & 6 deletions bin/mpc_node.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
use clap::Parser;
use telemetry_batteries::metrics::batteries::StatsdBattery;
use telemetry_batteries::tracing::batteries::DatadogBattery;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

pub const SERVICE_NAME: &str = "service";
pub const SERVICE_NAME: &str = "mpc-node";

pub const METRICS_HOST: &str = "localhost";
pub const METRICS_PORT: u16 = 8125;
pub const METRICS_QUEUE_SIZE: usize = 5000;
pub const METRICS_BUFFER_SIZE: usize = 1024;
pub const METRICS_PREFIX: &str = "service";
pub const METRICS_PREFIX: &str = "mpc-node";

#[derive(Parser)]
#[clap(version)]
pub struct Args {}
pub struct Args {
#[clap(short, long, env)]
local: bool,
}

#[tokio::main]
async fn main() -> eyre::Result<()> {
let _args = Args::parse();
dotenv::dotenv().ok();

let args = Args::parse();

// Initialize tracing exporter
DatadogBattery::init(None, SERVICE_NAME, None, true);
if args.local {
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer().pretty().compact())
.with(tracing_subscriber::EnvFilter::from_default_env())
.init();
} else {
DatadogBattery::init(None, SERVICE_NAME, None, true);
}

// Initalize metrics exporter
StatsdBattery::init(
Expand All @@ -30,5 +44,20 @@ async fn main() -> eyre::Result<()> {
Some(METRICS_PREFIX),
)?;

Ok(())
let mut n = 0;

loop {
foo(n).await;

n += 1;

tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
}
}

#[tracing::instrument]
async fn foo(n: usize) {
tracing::info!(n, "Foo");

metrics::gauge!("foo", n as f64);
}
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

0 comments on commit 2874464

Please sign in to comment.