From a922bafa0395a220c695ded7fa73bb6b10733008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Rodon?= Date: Sun, 28 Dec 2025 23:37:17 +0100 Subject: [PATCH 1/2] Feat: For the AWS EMF and XRay exporters, changing their respective 'region' argument so that, if unset, it tries to use AWS_REGION and AWS_DEFAULT_REGION (in that order) before defaulting to us-east-1. Rationnal: from an AWS user perpective, it is expected that the default behavior is to use whatever default region the user has set, if any. All changes: - Implemented Default on the exporters::shared::aws::Region struct - Implemented core::str::FromStr on the Region struct so we can parse strings in a more controlled maner - Defered the previous From impl to str::parse() - Removed the clap::value_enum flag on the XRay/EMF arguments because the clap::ValueEnum trait is not implemented on Region anyway - Updated the documentation of both configuration arg to reflect the change --- README.md | 4 ++-- src/exporters/shared/aws.rs | 36 +++++++++++++++++++++++++++++++----- src/init/awsemf_exporter.rs | 5 ++--- src/init/xray_exporter.rs | 14 ++------------ 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index e3242b88..827c0829 100644 --- a/README.md +++ b/README.md @@ -254,7 +254,7 @@ X-Ray exporter. | Option | Default | Options | |------------------------------------|-----------|------------------| -| --awsxray-exporter-region | us-east-1 | aws region codes | +| --awsxray-exporter-region | `AWS_REGION` env-var if set, then `AWS_DEFAULT_REGION`, then `us-east-1` | aws region codes | | --awsxray-exporter-custom-endpoint | | | For a list of available AWS X-Ray region codes here: https://docs.aws.amazon.com/general/latest/gr/xray.html @@ -272,7 +272,7 @@ exporter. | Option | Default | Options | |--------------------------------------------------------|------------------|------------------| -| --awsemf-exporter-region | us-east-1 | aws region codes | +| --awsemf-exporter-region | `AWS_REGION` env-var if set, then `AWS_DEFAULT_REGION`, then `us-east-1` | aws region codes | | --awsemf-exporter-custom-endpoint | | | | --awsemf-exporter-log-group-name | /metrics/default | | | --awsemf-exporter-log-stream-name | otel-stream | | diff --git a/src/exporters/shared/aws.rs b/src/exporters/shared/aws.rs index 480f6d8c..1b47d42b 100644 --- a/src/exporters/shared/aws.rs +++ b/src/exporters/shared/aws.rs @@ -79,9 +79,11 @@ impl Display for Region { } } -impl From for Region { - fn from(s: String) -> Self { - match s.as_str() { +impl core::str::FromStr for Region { + type Err = String; + + fn from_str(s: &str) -> Result { + Ok(match s { "us-east-1" => Region::UsEast1, "us-east-2" => Region::UsEast2, "us-west-1" => Region::UsWest1, @@ -114,7 +116,31 @@ impl From for Region { "me-south-1" => Region::MeSouth1, "me-central-1" => Region::MeCentral1, "sa-east-1" => Region::SaEast1, - _ => panic!("Unknown region: {}", s), - } + _ => return Err(format!("Unknown region: {}", s)), + }) + } +} + +impl From for Region { + fn from(s: String) -> Self { + s.parse().unwrap() + } +} + +impl Default for Region { + fn default() -> Self { + use std::env; + // Try to read AWS_REGION + env::var("AWS_REGION") + // Else, try to read AWS_DEFAULT_REGION + .or_else(|_| env::var("AWS_DEFAULT_REGION")) + // Discard the error + .ok() + // Parse the value and discard the error + .map(|s| s.parse().ok()) + // Flatten the result + .flatten() + // Unwrap it or fallback on us-east-1 + .unwrap_or_else(|| Region::UsEast1) } } diff --git a/src/init/awsemf_exporter.rs b/src/init/awsemf_exporter.rs index 1d56ca03..e10d876b 100644 --- a/src/init/awsemf_exporter.rs +++ b/src/init/awsemf_exporter.rs @@ -9,10 +9,9 @@ pub struct AwsEmfExporterArgs { /// AWS EMF Exporter Region #[arg( id("AWSEMF_REGION"), - value_enum, long("awsemf-exporter-region"), env = "ROTEL_AWSEMF_EXPORTER_REGION", - default_value = "us-east-1" + default_value_t )] pub region: Region, @@ -82,7 +81,7 @@ pub struct AwsEmfExporterArgs { impl Default for AwsEmfExporterArgs { fn default() -> Self { Self { - region: Region::UsEast1, + region: Region::default(), custom_endpoint: None, log_group_name: "/metrics/default".to_string(), log_stream_name: "otel-stream".to_string(), diff --git a/src/init/xray_exporter.rs b/src/init/xray_exporter.rs index cc753147..f3962ab3 100644 --- a/src/init/xray_exporter.rs +++ b/src/init/xray_exporter.rs @@ -3,15 +3,14 @@ use serde::Deserialize; use crate::exporters::shared::aws::Region; -#[derive(Debug, Clone, Args, Deserialize)] +#[derive(Debug, Default, Clone, Args, Deserialize)] #[serde(default)] pub struct XRayExporterArgs { /// AWS X-Ray Exporter Region #[arg( - value_enum, long("awsxray-exporter-region"), env = "ROTEL_AWSXRAY_EXPORTER_REGION", - default_value = "us-east-1" + default_value_t )] pub region: Region, @@ -22,12 +21,3 @@ pub struct XRayExporterArgs { )] pub custom_endpoint: Option, } - -impl Default for XRayExporterArgs { - fn default() -> Self { - Self { - region: Region::UsEast1, - custom_endpoint: None, - } - } -} From 624614c6393fbd47de0eaf3e5e8792be15f60a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Rodon?= Date: Sat, 3 Jan 2026 21:15:10 +0100 Subject: [PATCH 2/2] Forgot to change the Default impl of XRayExporterConfigBuilder (though I'm not sure it is really used in practice I suppose it is more coherent to include it in the change) --- src/exporters/xray/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exporters/xray/mod.rs b/src/exporters/xray/mod.rs index 44c39ed9..ce3dff7e 100644 --- a/src/exporters/xray/mod.rs +++ b/src/exporters/xray/mod.rs @@ -70,7 +70,7 @@ pub struct XRayExporterConfigBuilder { impl Default for XRayExporterConfigBuilder { fn default() -> Self { Self { - region: Region::UsEast1, + region: Default::default(), custom_endpoint: None, retry_config: Default::default(), }