Compare commits

..

3 commits

Author SHA1 Message Date
6de14bb200
tracing: extract request info into tags
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
2024-11-26 17:55:44 +01:00
3e859b5d8c
WIP: Add otel tracing 2024-11-26 17:55:44 +01:00
9cac938fb5
WIP: Initial dropshot server
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
2024-11-26 17:50:16 +01:00

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{anyhow, Result};
use clap::Parser;
use dropshot::endpoint;
use dropshot::ApiDescription;
@ -35,7 +35,6 @@ struct Cli {}
/// Represents a project in our API.
#[derive(Serialize, JsonSchema)]
struct VersionInfo {
/// Name of the project.
name: String,
}
@ -50,7 +49,9 @@ 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<()>>,
@ -58,11 +59,13 @@ 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<(), String> {
async fn main() -> Result<()> {
let _args = Cli::parse();
let fmt_layer = tracing_subscriber::fmt::layer();
@ -81,12 +84,11 @@ async fn main() -> Result<(), String> {
.with_tonic()
.with_endpoint("https://localhost:4317")
.build()
.map_err(|e| e.to_string())?;
.map_err(|e| anyhow!("Error creating OTLP exporter: {:?}", e))?;
let resource = Resource::from_schema_url(
[
// KeyValue::new(SERVICE_NAME, env!("CARGO_PKG_NAME")),
KeyValue::new(SERVICE_NAME, "patagia-controller"),
KeyValue::new(SERVICE_NAME, env!("CARGO_PKG_NAME")),
KeyValue::new(SERVICE_VERSION, env!("CARGO_PKG_VERSION")),
],
SCHEMA_URL,
@ -106,36 +108,21 @@ async fn main() -> Result<(), String> {
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");
foo().await;
let mut api = ApiDescription::new();
api.register(api_version).map_err(|e| e.to_string())?;
let server = ServerBuilder::new(api, Arc::new(()), dropshot_logger)
api.register(api_version).unwrap();
ServerBuilder::new(api, Arc::new(()), dropshot_logger)
.config(config_dropshot)
.start()
.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",);
.map_err(|e| anyhow!("Error starting server: {:?}", e))?
.await
.map_err(|e| anyhow!(e))
}