Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use config.service-name in coprocessor OTLP traces #184

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/getting_started/fhevm/coprocessor/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Options:
Postgres database url. If unspecified DATABASE_URL environment variable is used
--coprocessor-private-key <COPROCESSOR_PRIVATE_KEY>
Coprocessor private key file path. Private key is in plain text 0x1234.. format [default: ./coprocessor.key]
--service-name <SERVICE_NAME>
Coprocessor service name in OTLP traces [default: coprocessor]
-h, --help
Print help
-V, --version
Expand Down
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
Loading