Skip to content

Commit

Permalink
feat: add init and init tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
smorihira committed Sep 11, 2024
1 parent e1075b9 commit 50eb8e2
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions rust/bin/meta/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use opentelemetry::global;
use opentelemetry::propagation::Extractor;
use tonic::transport::Server;
use tonic::Request;
use observability::{config::Config, observability::{Observability, ObservabilityImpl}};

struct MetadataMap<'a>(&'a tonic::metadata::MetadataMap);

Expand Down Expand Up @@ -48,18 +49,37 @@ fn intercept(mut req: Request<()>) -> Result<Request<()>, tonic::Status> {

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// TODO: initialize tracer
// TODO: yaml is given from outside
// let config_yaml = r#"enabled: false
// endpoint: ""
// attributes: []
// tracer:
// enabled: false
// meter:
// enabled: false
// export_duration:
// secs: 60
// nanos: 0
// export_timeout_duration:
// secs: 30
// nanos: 0
// "#;
//
// decode config yaml
// let observability_cfg = serde_yaml::from_str(config_yaml).unwrap();
let observability_cfg = Config::default();
let mut observability = ObservabilityImpl::new(observability_cfg)?;

let addr = "[::1]:8081".parse()?;
let cfg_path = "/var/lib/meta/database"; // TODO: set the appropriate path
let meta = handler::Meta::new(cfg_path).expect("Failed to initialize Meta service");
let meta = handler::Meta::new(cfg_path)?;

// the interceptor given here is implicitly executed for each request
Server::builder()
.add_service(proto::meta::v1::meta_server::MetaServer::with_interceptor(meta, intercept))
.serve(addr)
.await?;

// TODO: shutdown tracer
observability.shutdown()?;
Ok(())
}

0 comments on commit 50eb8e2

Please sign in to comment.