From 1f1da88ba97fdc6e48df1357d134fc9a7ced6c19 Mon Sep 17 00:00:00 2001 From: siyuan0322 Date: Mon, 20 May 2024 11:04:18 +0800 Subject: [PATCH] add metadata for rust otel exporting --- .../executor/engine/pegasus/server/Cargo.toml | 8 +++---- .../executor/engine/pegasus/server/src/rpc.rs | 24 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/interactive_engine/executor/engine/pegasus/server/Cargo.toml b/interactive_engine/executor/engine/pegasus/server/Cargo.toml index 355799ae2ad8..e20698754059 100644 --- a/interactive_engine/executor/engine/pegasus/server/Cargo.toml +++ b/interactive_engine/executor/engine/pegasus/server/Cargo.toml @@ -2,7 +2,7 @@ name = "pegasus_server" version = "0.1.0" authors = ["chenqiang.mcq "] -edition = "2018" +edition = "2021" [dependencies] pegasus_common = { path = "../common" } @@ -12,8 +12,8 @@ pegasus = { path = "../pegasus" } log = "0.4" crossbeam-utils = "0.8.14" #crossbeam-channel = "0.5.6" -tonic = "0.8" -prost = "0.11" +tonic = "0.11" +prost = "0.12" tokio = { version = "1.24", features = ["macros", "sync", "rt-multi-thread"] } tokio-stream = "0.1.11" toml = "0.5" @@ -30,7 +30,7 @@ opentelemetry-otlp = { version = "0.15.0", features = ["trace", "metrics", "grpc structopt = "0.3" [build-dependencies] -tonic-build = "0.8" +tonic-build = "0.11" [features] default = [] diff --git a/interactive_engine/executor/engine/pegasus/server/src/rpc.rs b/interactive_engine/executor/engine/pegasus/server/src/rpc.rs index f5011fafd8cf..5eb0056cf3ef 100644 --- a/interactive_engine/executor/engine/pegasus/server/src/rpc.rs +++ b/interactive_engine/executor/engine/pegasus/server/src/rpc.rs @@ -392,14 +392,14 @@ fn init_otel() -> Result> { return Ok(true); } - // let mut metadata = tonic::metadata::MetadataMap::with_capacity(1); - // let dsn = std::env::var("UPTRACE_DSN").unwrap_or_default(); - // if !dsn.is_empty() { - // metadata.insert("uptrace-dsn", dsn.parse().unwrap()); - // info!("using DSN: {}", dsn); - // } else { - // warn!("Error: UPTRACE_DSN not found."); - // } + let mut metadata = tonic::metadata::MetadataMap::with_capacity(1); + let dsn = std::env::var("UPTRACE_DSN").unwrap_or_default(); + if !dsn.is_empty() { + metadata.insert("uptrace-dsn", dsn.parse().unwrap()); + info!("using DSN: {}", dsn); + } else { + warn!("Error: UPTRACE_DSN not found."); + } let default_endpoint = "http://localhost:4317".to_string(); let endpoint = std::env::var("OTEL_EXPORTER_OTLP_ENDPOINT").unwrap_or(default_endpoint); @@ -416,15 +416,15 @@ fn init_otel() -> Result> { let exporter = opentelemetry_otlp::new_exporter() .tonic() .with_timeout(Duration::from_secs(5)) - .with_endpoint(endpoint.clone()); - // .with_metadata(metadata.clone()); + .with_endpoint(endpoint.clone()) + .with_metadata(metadata.clone()); let _tracer = init_tracer(resource.clone(), exporter)?; let exporter = opentelemetry_otlp::new_exporter() .tonic() .with_timeout(Duration::from_secs(5)) - .with_endpoint(endpoint); - // .with_metadata(metadata); + .with_endpoint(endpoint) + .with_metadata(metadata); let _meter = init_meter_provider(resource, exporter)?; global::set_meter_provider(_meter);