diff --git a/controller/src/main.rs b/controller/src/main.rs index b9e7226..9893e85 100644 --- a/controller/src/main.rs +++ b/controller/src/main.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Result}; +use anyhow::Result; use clap::Parser; use dropshot::endpoint; use dropshot::ApiDescription; @@ -35,6 +35,7 @@ struct Cli {} /// Represents a project in our API. #[derive(Serialize, JsonSchema)] struct VersionInfo { + /// Name of the project. name: String, } @@ -49,9 +50,7 @@ struct VersionInfo { http.method=rqctx.request.method().as_str(), http.path=rqctx.request.uri().path(), http.remote_ip=rqctx.request.remote_addr().ip().to_string(), - request_id = rqctx.request_id, - ), - err(Debug), + ) )] async fn api_version( rqctx: RequestContext<Arc<()>>, @@ -59,13 +58,11 @@ async fn api_version( let ver = VersionInfo { name: String::from("patagia-controller"), }; - - tracing::info!("Someone made a request to /version"); Ok(HttpResponseOk(ver)) } #[tokio::main] -async fn main() -> Result<()> { +async fn main() -> Result<(), String> { let _args = Cli::parse(); let fmt_layer = tracing_subscriber::fmt::layer(); @@ -84,11 +81,12 @@ async fn main() -> Result<()> { .with_tonic() .with_endpoint("https://localhost:4317") .build() - .map_err(|e| anyhow!("Error creating OTLP exporter: {:?}", e))?; + .map_err(|e| e.to_string())?; let resource = Resource::from_schema_url( [ - KeyValue::new(SERVICE_NAME, env!("CARGO_PKG_NAME")), + // KeyValue::new(SERVICE_NAME, env!("CARGO_PKG_NAME")), + KeyValue::new(SERVICE_NAME, "patagia-controller"), KeyValue::new(SERVICE_VERSION, env!("CARGO_PKG_VERSION")), ], SCHEMA_URL, @@ -108,21 +106,36 @@ async fn main() -> Result<()> { let tracer = tracer_provider.tracer("patagia-controller"); + // let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); + tracing_subscriber::registry() .with(tracing_subscriber::EnvFilter::from_default_env()) .with(fmt_layer) + // .with(telemetry) .with(OpenTelemetryLayer::new(tracer)) .init(); tracing::info!("Patagia Controller"); - let mut api = ApiDescription::new(); - api.register(api_version).unwrap(); + foo().await; - ServerBuilder::new(api, Arc::new(()), dropshot_logger) + let mut api = ApiDescription::new(); + api.register(api_version).map_err(|e| e.to_string())?; + let server = ServerBuilder::new(api, Arc::new(()), dropshot_logger) .config(config_dropshot) .start() - .map_err(|e| anyhow!("Error starting server: {:?}", e))? - .await - .map_err(|e| anyhow!(e)) + .map_err(|e| e.to_string())?; + server.await +} + +#[tracing::instrument] +async fn foo() { + tracing::info!( + monotonic_counter.foo = 1_u64, + key_1 = "bar", + key_2 = 10, + "This is the Foo!", + ); + + tracing::info!(histogram.baz = 10, "histogram example",); }