Skip to content

Commit df074a1

Browse files
authored
Add otlp_exporter_endpoint option to proxy/server as well (#4829)
## Motivation Currently, only the client supports the `--otlp-exporter-endpoint` flag and `LINERA_OTLP_EXPORTER_ENDPOINT` environment variable for OpenTelemetry configuration. The proxy and server binaries always default to checking the environment variable but don't expose the command-line option, which is inconsistent with the client. ## Proposal This PR adds the `otlp_exporter_endpoint` option to both proxy and server for consistency: - **Proxy** (`linera-service/src/proxy/main.rs`): - Added `otlp_exporter_endpoint: Option<String>` field to `ProxyOptions` - Updated `init_with_opentelemetry` call to pass the endpoint instead of `None` - **Server** (`linera-service/src/server.rs`): - Added `otlp_exporter_endpoint: Option<String>` field to `ServerCommand::Run` variant - Created helper function `otlp_exporter_endpoint_for()` to extract endpoint from command - Updated `init_with_opentelemetry` call to use the helper function - Boxed `CommonStorageOptions` in `ServerCommand::Run` to fix clippy `large_enum_variant` warning (the `Run` variant became too large after adding the new field) Both binaries now consistently accept `--otlp-exporter-endpoint` flag and `LINERA_OTLP_EXPORTER_ENDPOINT` environment variable, matching the client's behavior. ## Test Plan - Verified clippy passes with all features - Verified clippy passes with no default features - Confirmed both binaries compile successfully ## Release Plan - Nothing to do / These changes follow the usual release cycle.
1 parent a67d545 commit df074a1

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

linera-service/src/proxy/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ pub struct ProxyOptions {
9696
/// Runs a specific proxy instance.
9797
#[arg(long)]
9898
id: Option<usize>,
99+
100+
/// OpenTelemetry OTLP exporter endpoint (requires opentelemetry feature).
101+
#[arg(long, env = "LINERA_OTLP_EXPORTER_ENDPOINT")]
102+
otlp_exporter_endpoint: Option<String>,
99103
}
100104

101105
/// A Linera Proxy, either gRPC or over 'Simple Transport', meaning TCP or UDP.
@@ -496,7 +500,7 @@ impl ProxyOptions {
496500
let public_key = &server_config.validator.public_key;
497501
linera_base::tracing::init_with_opentelemetry(
498502
&format!("validator-{public_key}-proxy"),
499-
None,
503+
self.otlp_exporter_endpoint.as_deref(),
500504
);
501505

502506
let store_config = self

linera-service/src/server.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ enum ServerCommand {
370370

371371
/// Common storage options.
372372
#[command(flatten)]
373-
common_storage_options: CommonStorageOptions,
373+
common_storage_options: Box<CommonStorageOptions>,
374374

375375
/// Configuration for cross-chain requests
376376
#[command(flatten)]
@@ -409,6 +409,10 @@ enum ServerCommand {
409409
env = "LINERA_SERVER_CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES",
410410
)]
411411
chain_info_max_received_log_entries: usize,
412+
413+
/// OpenTelemetry OTLP exporter endpoint (requires opentelemetry feature).
414+
#[arg(long, env = "LINERA_OTLP_EXPORTER_ENDPOINT")]
415+
otlp_exporter_endpoint: Option<String>,
412416
},
413417

414418
/// Act as a trusted third-party and generate all server configurations
@@ -485,6 +489,16 @@ fn main() {
485489
}
486490

487491
/// Returns the log file name to use based on the [`ServerCommand`] that will run.
492+
fn otlp_exporter_endpoint_for(command: &ServerCommand) -> Option<&str> {
493+
match command {
494+
ServerCommand::Run {
495+
otlp_exporter_endpoint,
496+
..
497+
} => otlp_exporter_endpoint.as_deref(),
498+
ServerCommand::Generate { .. } | ServerCommand::EditShards { .. } => None,
499+
}
500+
}
501+
488502
fn log_file_name_for(command: &ServerCommand) -> Cow<'static, str> {
489503
match command {
490504
ServerCommand::Run {
@@ -508,7 +522,10 @@ fn log_file_name_for(command: &ServerCommand) -> Cow<'static, str> {
508522
}
509523

510524
async fn run(options: ServerOptions) {
511-
linera_base::tracing::init_with_opentelemetry(&log_file_name_for(&options.command), None);
525+
linera_base::tracing::init_with_opentelemetry(
526+
&log_file_name_for(&options.command),
527+
otlp_exporter_endpoint_for(&options.command),
528+
);
512529

513530
match options.command {
514531
ServerCommand::Run {
@@ -522,6 +539,7 @@ async fn run(options: ServerOptions) {
522539
wasm_runtime,
523540
chain_worker_ttl,
524541
chain_info_max_received_log_entries,
542+
otlp_exporter_endpoint: _,
525543
} => {
526544
linera_version::VERSION_INFO.log();
527545

0 commit comments

Comments
 (0)