Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cctdaniel committed Jul 16, 2024
1 parent a159099 commit a7ddefe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
18 changes: 18 additions & 0 deletions src/agent/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct Config {
pub metrics_server: metrics::Config,
#[serde(default)]
pub remote_keypair_loader: services::keypairs::Config,
#[serde(default)]
pub opentelemetry: OpenTelemetryConfig,
}

impl Config {
Expand Down Expand Up @@ -83,3 +85,19 @@ impl Default for ChannelCapacities {
}
}
}


#[derive(Deserialize, Debug)]
pub struct OpenTelemetryConfig {
pub exporter_timeout_secs: u64,
pub exporter_endpoint: String,
}

impl Default for OpenTelemetryConfig {
fn default() -> Self {
Self {
exporter_timeout_secs: 3,
exporter_endpoint: "http://127.0.0.1:4317".to_string(),
}
}
}
28 changes: 15 additions & 13 deletions src/bin/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,31 @@ struct Arguments {

#[tokio::main]
async fn main() -> Result<()> {
let args = Arguments::parse();

if !args.config.as_path().exists() {
return Err(anyhow!("No config found under {:?}", args.config.to_str()));
}

println!("Loading config from {:?}", args.config.display());

// Parse config early for logging channel capacity
let config = Config::new(args.config).context("Could not parse config")?;

// Initialize a Tracing Subscriber
let fmt_layer = tracing_subscriber::fmt::layer()
.with_file(false)
.with_line_number(true)
.with_thread_ids(true)
.with_target(true)
.with_ansi(std::io::stderr().is_terminal());

// Set up the OpenTelemetry exporter, defaults to 127.0.0.1:4317
let otlp_exporter = opentelemetry_otlp::new_exporter()
.tonic()
.with_timeout(Duration::from_secs(3));
.with_endpoint(&config.opentelemetry.exporter_endpoint)
.with_timeout(Duration::from_secs(
config.opentelemetry.exporter_timeout_secs,
));

// Set up the OpenTelemetry tracer
let tracer = opentelemetry_otlp::new_pipeline()
Expand All @@ -69,17 +82,6 @@ async fn main() -> Result<()> {
registry.with(fmt_layer.json()).init();
}

let args = Arguments::parse();

if !args.config.as_path().exists() {
return Err(anyhow!("No config found under {:?}", args.config.to_str()));
}

println!("Loading config from {:?}", args.config.display());

// Parse config early for logging channel capacity
let config = Config::new(args.config).context("Could not parse config")?;

// Launch the application. If it fails, print the full backtrace and exit. RUST_BACKTRACE
// should be set to 1 for this otherwise it will only print the top-level error.
if let Err(err) = start(config).await {
Expand Down

0 comments on commit a7ddefe

Please sign in to comment.