Skip to content

Commit abf31c0

Browse files
SilverSoldierprashantgupta24
authored andcommitted
Add distributed open telemetry tracing (#6)
We would like to add distributed open-telemetry tracing to the fmaas-router. This requires 3 changes on the fmaas-router: 1. Enabling open-telemetry tracing in the fmaas-router (this is done by the `init_logging` function in the newly created `tracing.rs` file. 2. Propagating trace context information in the GRPC metadata to the TGIS router. This is done with helper functions `inject_context_span` etc. defined in the same file and used in the `server.rs` file for the `/generate`, `/generateStream` and `/tokenize` endpoints. Span tags have been added following the [Semantic Convention for RPC calls](https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/) 3. Receives trace context information from wx-inference-proxy. This is done with helper function `extract_context_spa Co-authored-by: Kavya <[email protected]>
1 parent 8efd754 commit abf31c0

File tree

6 files changed

+388
-29
lines changed

6 files changed

+388
-29
lines changed

Cargo.lock

Lines changed: 220 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fmaas-router/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ prost = "^0.12.3"
2727
prost-types = "^0.12.3"
2828
serde_yaml = "^0.9.33"
2929
serde = { version = "^1.0.197", features = ["derive"] }
30+
opentelemetry = { version = "0.22", features = ["trace"] }
31+
opentelemetry_sdk = {version = "0.22", features = ["rt-tokio"]}
32+
opentelemetry-otlp = "0.15.0"
33+
tracing-opentelemetry = "0.23.0"
3034

3135
mio = "^0.8.11" # Override to address CVE-2024-27308
3236
rustls-webpki = "^0.102.2" # Override to address WS-2023-0305, CVE-2018-16875

fmaas-router/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use tracing::info;
1111
mod pb;
1212
pub mod rpc;
1313
pub mod server;
14+
pub mod tracing_utils;
1415

1516
#[derive(Debug, Clone, Deserialize)]
1617
pub struct ServiceAddr {
@@ -118,4 +119,4 @@ async fn create_clients<C>(
118119
.expect("Error creating upstream service clients")
119120
.into_iter()
120121
.collect()
121-
}
122+
}

fmaas-router/src/main.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
22

33
use clap::Parser;
4-
use fmaas_router::{server, ModelMap};
5-
use tracing_subscriber::EnvFilter;
4+
use fmaas_router::{server, tracing_utils::init_logging, ModelMap};
65

76
/// App Configuration
87
#[derive(Parser, Debug)]
@@ -28,30 +27,16 @@ struct Args {
2827
upstream_tls: bool,
2928
#[clap(long, env)]
3029
upstream_tls_ca_cert_path: Option<String>,
30+
#[clap(long, env = "OTEL_EXPORTER_OTLP_ENDPOINT")]
31+
otlp_endpoint: Option<String>,
32+
#[clap(long, env = "OTEL_SERVICE_NAME", default_value = "fmaas-router")]
33+
otlp_service_name: String,
3134
}
3235

3336
fn main() -> Result<(), std::io::Error> {
3437
//Get args
3538
let args = Args::parse();
3639

37-
// Configure log level; use info by default
38-
let filter_layer = EnvFilter::try_from_default_env()
39-
.or_else(|_| EnvFilter::try_new("info"))
40-
.unwrap();
41-
42-
if args.json_output {
43-
tracing_subscriber::fmt()
44-
.json()
45-
.with_env_filter(filter_layer)
46-
.with_current_span(false)
47-
.init();
48-
} else {
49-
tracing_subscriber::fmt()
50-
.compact()
51-
.with_env_filter(filter_layer)
52-
.init();
53-
}
54-
5540
if args.tls_key_path.is_some() != args.tls_cert_path.is_some() {
5641
panic!("tls: must provide both cert and key")
5742
}
@@ -71,6 +56,8 @@ fn main() -> Result<(), std::io::Error> {
7156
let grpc_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), args.grpc_port);
7257
let http_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), args.probe_port);
7358

59+
init_logging(args.otlp_service_name, args.json_output, args.otlp_endpoint);
60+
7461
server::run(
7562
grpc_addr,
7663
http_addr,

0 commit comments

Comments
 (0)