Server tools to backfill, tail, mirror, and verify PLC logs
1mod instrumentation;
2
3use reqwest::Url;
4use tracing_subscriber::layer::SubscriberExt;
5
6#[derive(Debug, Clone, clap::Args)]
7pub struct GlobalArgs {
8 /// Upstream PLC server
9 #[arg(short, long, global = true, env = "ALLEGEDLY_UPSTREAM")]
10 #[clap(default_value = "https://plc.directory")]
11 pub upstream: Url,
12 /// Self-rate-limit upstream request interval
13 ///
14 /// plc.directory's rate limiting is 500 requests per 5 mins (600ms)
15 #[arg(long, global = true, env = "ALLEGEDLY_UPSTREAM_THROTTLE_MS")]
16 #[clap(default_value = "600")]
17 pub upstream_throttle_ms: u64,
18}
19
20#[derive(Debug, Default, Clone, clap::Args)]
21pub struct InstrumentationArgs {
22 /// Export traces to an OTLP collector
23 ///
24 /// Configure the colletctor via standard env vars:
25 /// - `OTEL_EXPORTER_OTLP_ENDPOINT` eg "https://api.honeycomb.io/"
26 /// - `OTEL_EXPORTER_OTLP_HEADERS` eg "x-honeycomb-team=supersecret"
27 /// - `OTEL_SERVICE_NAME` eg "my-app"
28 #[arg(long, action, global = true, env = "ALLEGEDLY_ENABLE_OTEL")]
29 pub enable_opentelemetry: bool,
30}
31
32pub fn bin_init(enable_otlp: bool) {
33 let filter = tracing_subscriber::EnvFilter::builder()
34 .with_default_directive(tracing_subscriber::filter::LevelFilter::INFO.into())
35 .from_env_lossy();
36
37 let stderr_log = tracing_subscriber::fmt::layer()
38 .with_writer(std::io::stderr)
39 .pretty();
40
41 let otel = if enable_otlp {
42 Some(instrumentation::otel_layer())
43 } else {
44 None
45 };
46
47 let subscriber = tracing_subscriber::Registry::default()
48 .with(filter)
49 .with(stderr_log)
50 .with(otel);
51
52 tracing::subscriber::set_global_default(subscriber).expect("to set global tracing subscriber");
53}
54
55#[allow(dead_code)]
56fn main() {
57 panic!("this is not actually a module")
58}