Skip to content

Commit 3b6197d

Browse files
committed
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 1d57bc8 commit 3b6197d

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.
@@ -486,7 +490,7 @@ impl ProxyOptions {
486490
let public_key = &server_config.validator.public_key;
487491
linera_base::tracing::init_with_opentelemetry(
488492
&format!("validator-{public_key}-proxy"),
489-
None,
493+
self.otlp_exporter_endpoint.as_deref(),
490494
);
491495

492496
let store_config = self

linera-service/src/server.rs

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

355355
/// Common storage options.
356356
#[command(flatten)]
357-
common_storage_options: CommonStorageOptions,
357+
common_storage_options: Box<CommonStorageOptions>,
358358

359359
/// Configuration for cross-chain requests
360360
#[command(flatten)]
@@ -393,6 +393,10 @@ enum ServerCommand {
393393
env = "LINERA_SERVER_CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES",
394394
)]
395395
chain_info_max_received_log_entries: usize,
396+
397+
/// OpenTelemetry OTLP exporter endpoint (requires opentelemetry feature).
398+
#[arg(long, env = "LINERA_OTLP_EXPORTER_ENDPOINT")]
399+
otlp_exporter_endpoint: Option<String>,
396400
},
397401

398402
/// Act as a trusted third-party and generate all server configurations
@@ -469,6 +473,16 @@ fn main() {
469473
}
470474

471475
/// Returns the log file name to use based on the [`ServerCommand`] that will run.
476+
fn otlp_exporter_endpoint_for(command: &ServerCommand) -> Option<&str> {
477+
match command {
478+
ServerCommand::Run {
479+
otlp_exporter_endpoint,
480+
..
481+
} => otlp_exporter_endpoint.as_deref(),
482+
ServerCommand::Generate { .. } | ServerCommand::EditShards { .. } => None,
483+
}
484+
}
485+
472486
fn log_file_name_for(command: &ServerCommand) -> Cow<'static, str> {
473487
match command {
474488
ServerCommand::Run {
@@ -492,7 +506,10 @@ fn log_file_name_for(command: &ServerCommand) -> Cow<'static, str> {
492506
}
493507

494508
async fn run(options: ServerOptions) {
495-
linera_base::tracing::init_with_opentelemetry(&log_file_name_for(&options.command), None);
509+
linera_base::tracing::init_with_opentelemetry(
510+
&log_file_name_for(&options.command),
511+
otlp_exporter_endpoint_for(&options.command),
512+
);
496513

497514
match options.command {
498515
ServerCommand::Run {
@@ -506,6 +523,7 @@ async fn run(options: ServerOptions) {
506523
wasm_runtime,
507524
chain_worker_ttl,
508525
chain_info_max_received_log_entries,
526+
otlp_exporter_endpoint: _,
509527
} => {
510528
linera_version::VERSION_INFO.log();
511529

0 commit comments

Comments
 (0)