ANW-37 Telemetry: request metrics + selective traces over OTLP
Optional OTLP export of request-level metrics (request and response-byte counters keyed by route/status/conditional-GET, a duration histogram out to 600s) plus server spans for slow or 5xx requests, nested under the incoming W3C trace context. Off unless an OTLP endpoint or uptrace DSN is configured; a config-less server is byte-for-byte unchanged.
This commit is contained in:
parent
b271d57cbb
commit
23ce90e103
9 changed files with 2014 additions and 55 deletions
26
src/main.rs
26
src/main.rs
|
|
@ -5,9 +5,12 @@
|
|||
|
||||
mod cli;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use anwesen::app::Anwesen;
|
||||
use anwesen::doctor;
|
||||
use anwesen::merge;
|
||||
use anwesen::telemetry::{self, RawTelemetryArgs, TelemetryConfig};
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use hydra::Application;
|
||||
|
|
@ -15,21 +18,36 @@ use hydra::Application;
|
|||
use crate::cli::{Cli, Command};
|
||||
|
||||
// Result is retained at the binary boundary per [[ADR-001 Language and
|
||||
// Foundation Libraries]] (anyhow at main); current stubs do not yet
|
||||
// surface errors.
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
// Foundation Libraries]] (anyhow at main); telemetry config resolution and
|
||||
// exporter setup surface startup errors through it.
|
||||
fn main() -> Result<()> {
|
||||
let cli = Cli::parse();
|
||||
match cli.command {
|
||||
Command::Serve(args) => {
|
||||
init_logging(args.log_level);
|
||||
// Resolve telemetry config before the supervisor starts; an
|
||||
// unset endpoint leaves it `None` (export off, behaves as today).
|
||||
let telemetry = match TelemetryConfig::resolve(RawTelemetryArgs {
|
||||
uptrace_dsn: args.uptrace_dsn,
|
||||
otlp_endpoint: args.otlp_endpoint,
|
||||
otlp_headers: args.otlp_headers,
|
||||
slow_request_ms: args.otlp_slow_request_ms,
|
||||
})? {
|
||||
Some(cfg) => Some(Arc::new(telemetry::init(cfg)?)),
|
||||
None => None,
|
||||
};
|
||||
tracing::info!(
|
||||
vault = %args.vault.display(),
|
||||
bind = %args.bind,
|
||||
telemetry = telemetry.is_some(),
|
||||
"anwesen serve: starting supervisor tree"
|
||||
);
|
||||
// Blocks until the supervisor exits (SIGTERM / SIGINT / crash).
|
||||
Anwesen::new(args.vault, args.bind).run();
|
||||
Anwesen::new(args.vault, args.bind, telemetry.clone()).run();
|
||||
// Flush and shut down exporters after the server loop returns.
|
||||
if let Some(telemetry) = telemetry {
|
||||
telemetry.shutdown();
|
||||
}
|
||||
}
|
||||
Command::Doctor(args) => {
|
||||
init_logging(args.log_level);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue