Skip to content

Commit

Permalink
feat: use config.service-name in coprocessor OTLP traces
Browse files Browse the repository at this point in the history
  • Loading branch information
goshawk-3 committed Dec 12, 2024
1 parent 7c2ff2c commit 2b27a70
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions fhevm-engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fhevm-engine/coprocessor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lru = "0.12.3"
opentelemetry = "0.25.0"
opentelemetry-otlp = "0.25.0"
opentelemetry_sdk = { version = "0.25.0", features = ["rt-tokio"] }
opentelemetry-semantic-conventions = "0.27.0"
regex = "1.10.5"
serde_json = "1.0"
strum = { version = "0.26", features = ["derive"] }
Expand Down
4 changes: 4 additions & 0 deletions fhevm-engine/coprocessor/src/daemon_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ pub struct Args {
/// Private key is in plain text 0x1234.. format.
#[arg(long, default_value = "./coprocessor.key")]
pub coprocessor_private_key: String,

/// Coprocessor service name in OTLP traces
#[arg(long, default_value = "coprocessor")]
pub service_name: String,
}

pub fn parse_args() -> Args {
Expand Down
4 changes: 3 additions & 1 deletion fhevm-engine/coprocessor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ pub async fn async_main(
tracing_subscriber::fmt().json().with_level(true).init();
});

if let Err(err) = tracing::setup_tracing() {
info!(target: "async_main", "Starting runtime with args: {:?}", args);

if let Err(err) = tracing::setup_tracing(&args.service_name) {
panic!("Error while initializing tracing: {:?}", err);
}

Expand Down
1 change: 1 addition & 0 deletions fhevm-engine/coprocessor/src/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ async fn start_coprocessor(rx: Receiver<bool>, app_port: u16, db_url: &str) {
database_url: Some(db_url.to_string()),
maximimum_compact_inputs_upload: 10,
coprocessor_private_key: "./coprocessor.key".to_string(),
service_name: "coprocessor".to_string(),
};

std::thread::spawn(move || {
Expand Down
12 changes: 11 additions & 1 deletion fhevm-engine/coprocessor/src/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
pub fn setup_tracing() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
use opentelemetry::KeyValue;
use opentelemetry_sdk::Resource;

pub fn setup_tracing(service_name: &str) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
let otlp_exporter = opentelemetry_otlp::new_exporter().tonic();

let trace_provider = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(otlp_exporter)
.with_trace_config(
opentelemetry_sdk::trace::Config::default()
.with_resource(Resource::new(vec![KeyValue::new(
opentelemetry_semantic_conventions::resource::SERVICE_NAME.to_string(),
service_name.to_string(),
)])),
)
.install_batch(opentelemetry_sdk::runtime::Tokio)?;

opentelemetry::global::set_tracer_provider(trace_provider);
Expand Down

0 comments on commit 2b27a70

Please sign in to comment.