[model-gateway][tracing]: implement request tracing using OpenTelemetry with trace context propagation (HTTP) (#13897)

This commit is contained in:
Feng Su
2025-12-06 21:59:04 +08:00
committed by GitHub
parent 6d41791823
commit e12c6b320f
19 changed files with 814 additions and 35 deletions

View File

@@ -224,6 +224,8 @@ struct Router {
client_cert_path: Option<String>,
client_key_path: Option<String>,
ca_cert_paths: Vec<String>,
enable_trace: bool,
otlp_traces_endpoint: String,
}
impl Router {
@@ -309,6 +311,11 @@ impl Router {
_ => None,
};
let trace_config = Some(config::TraceConfig {
enable_trace: self.enable_trace,
otlp_traces_endpoint: self.otlp_traces_endpoint.clone(),
});
let history_backend = match self.history_backend {
HistoryBackendType::Memory => config::HistoryBackend::Memory,
HistoryBackendType::None => config::HistoryBackend::None,
@@ -376,6 +383,7 @@ impl Router {
.maybe_api_key(self.api_key.as_ref())
.maybe_discovery(discovery)
.maybe_metrics(metrics)
.maybe_trace(trace_config)
.maybe_log_dir(self.log_dir.as_ref())
.maybe_log_level(self.log_level.as_ref())
.maybe_request_id_headers(self.request_id_headers.clone())
@@ -477,6 +485,8 @@ impl Router {
client_cert_path = None,
client_key_path = None,
ca_cert_paths = vec![],
enable_trace = false,
otlp_traces_endpoint = String::from("localhost:4317"),
))]
#[allow(clippy::too_many_arguments)]
fn new(
@@ -552,6 +562,8 @@ impl Router {
client_cert_path: Option<String>,
client_key_path: Option<String>,
ca_cert_paths: Vec<String>,
enable_trace: bool,
otlp_traces_endpoint: String,
) -> PyResult<Self> {
let mut all_urls = worker_urls.clone();
@@ -641,6 +653,8 @@ impl Router {
client_cert_path,
client_key_path,
ca_cert_paths,
enable_trace,
otlp_traces_endpoint,
})
}