Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
9 changes: 9 additions & 0 deletions opentelemetry-exporter-geneva/geneva-uploader/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ pub struct GenevaClientConfig {
pub role_instance: String,
/// Maximum number of concurrent uploads. If None, defaults to number of CPU cores.
pub max_concurrent_uploads: Option<usize>,
/// User agent for the application. Will be formatted as "<application> (RustGenevaClient/0.1)".
/// If None, defaults to "RustGenevaClient/0.1".
///
/// Examples:
/// - None: "RustGenevaClient/0.1"
/// - Some("MyApp/2.1.0"): "MyApp/2.1.0 (RustGenevaClient/0.1)"
/// - Some("ProductionService-1.0"): "ProductionService-1.0 (RustGenevaClient/0.1)"
pub user_agent_suffix: Option<&'static str>,
// Add event name/version here if constant, or per-upload if you want them per call.
}

Expand All @@ -47,6 +55,7 @@ impl GenevaClient {
region: cfg.region,
config_major_version: cfg.config_major_version,
auth_method: cfg.auth_method,
user_agent_suffix: cfg.user_agent_suffix,
};
let config_client = Arc::new(
GenevaConfigClient::new(config_client_config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,15 @@ pub(crate) struct GenevaConfigClientConfig {
pub(crate) namespace: String,
pub(crate) region: String,
pub(crate) config_major_version: u32,
pub(crate) auth_method: AuthMethod, // agent_identity and agent_version are hardcoded for now
pub(crate) auth_method: AuthMethod,
/// User agent for the application. Will be formatted as "<application> (RustGenevaClient/0.1)".
/// If None, defaults to "RustGenevaClient/0.1".
///
/// Examples:
/// - None: "RustGenevaClient/0.1"
/// - Some("MyApp/2.1.0"): "MyApp/2.1.0 (RustGenevaClient/0.1)"
/// - Some("ProductionService-1.0"): "ProductionService-1.0 (RustGenevaClient/0.1)"
pub(crate) user_agent_suffix: Option<&'static str>,
}

#[allow(dead_code)]
Expand Down Expand Up @@ -259,9 +267,11 @@ impl GenevaConfigClient {
}
}

let agent_identity = "GenevaUploader";
let agent_identity = "RustGenevaClient";
let agent_version = "0.1";
let static_headers = Self::build_static_headers(agent_identity, agent_version);
let user_agent_suffix = config.user_agent_suffix.as_deref().unwrap_or("");
let static_headers =
Self::build_static_headers(agent_identity, agent_version, user_agent_suffix);

let identity = format!("Tenant=Default/Role=GcsClient/RoleInstance={agent_identity}");

Expand Down Expand Up @@ -302,9 +312,17 @@ impl GenevaConfigClient {
.map(|dt| dt.with_timezone(&Utc))
}

fn build_static_headers(agent_identity: &str, agent_version: &str) -> HeaderMap {
fn build_static_headers(
agent_identity: &str,
agent_version: &str,
user_agent_suffix: &str,
) -> HeaderMap {
let mut headers = HeaderMap::new();
let user_agent = format!("{agent_identity}-{agent_version}");
let user_agent = if user_agent_suffix.is_empty() {
format!("{}/{}", agent_identity, agent_version)
} else {
format!("{} ({}/{})", user_agent_suffix, agent_identity, agent_version)
};
headers.insert(USER_AGENT, HeaderValue::from_str(&user_agent).unwrap());
headers.insert(ACCEPT, HeaderValue::from_static("application/json"));
headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod tests {
region: "region".to_string(),
config_major_version: 1,
auth_method: AuthMethod::ManagedIdentity,
user_agent_suffix: Some("TestApp/1.0"),
};

assert_eq!(config.environment, "env");
Expand Down Expand Up @@ -107,6 +108,7 @@ mod tests {
path: PathBuf::from(temp_p12_file.path().to_string_lossy().to_string()),
password,
},
user_agent_suffix: Some("MockClient/1.0"),
};

let client = GenevaConfigClient::new(config).unwrap();
Expand Down Expand Up @@ -152,6 +154,7 @@ mod tests {
path: PathBuf::from(temp_p12_file.path().to_string_lossy().to_string()),
password,
},
user_agent_suffix: Some("ErrorTestApp/1.0"),
};

let client = GenevaConfigClient::new(config).unwrap();
Expand Down Expand Up @@ -200,6 +203,7 @@ mod tests {
path: PathBuf::from(temp_p12_file.path().to_string_lossy().to_string()),
password,
},
user_agent_suffix: Some("MissingInfoTestApp/1.0"),
};

let client = GenevaConfigClient::new(config).unwrap();
Expand Down Expand Up @@ -231,6 +235,7 @@ mod tests {
path: PathBuf::from("/nonexistent/path.p12".to_string()),
password: "test".to_string(),
},
user_agent_suffix: Some("InvalidCertTestApp/1.0"),
};

let result = GenevaConfigClient::new(config);
Expand Down Expand Up @@ -294,6 +299,7 @@ mod tests {
path: PathBuf::from(cert_path),
password: cert_password,
},
user_agent_suffix: Some("RealServerTestApp/1.0"),
};

println!("Connecting to real Geneva Config service...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ mod tests {
path: cert_path,
password: cert_password,
},
user_agent_suffix: Some("TestUploader".to_string()),
};

// Build client and uploader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async fn main() {
role_name,
role_instance,
max_concurrent_uploads: None, // Use default
user_agent_suffix: Some("BasicExample".to_string()),
};

let geneva_client = GenevaClient::new(config)
Expand Down
Loading