From a6d1023d34b89e7c0f604771758bfc12602d25fe Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Sun, 15 Nov 2026 00:25:46 +0000 Subject: [PATCH] perf(telemetry): share the session's configuration across events instead of copying it Every statement event copied the session's DriverSystemConfiguration and DriverConnectionParameters (about sixty optional strings and nested structs) and formatted the same user agent. The session now holds both behind Arc, events share them, and serde (with its `rc` feature) serializes them as before. Co-authored-by: Isaac Signed-off-by: Vu Anh Phung --- Cargo.toml | 3 ++- NEXT_CHANGELOG.md | 2 ++ src/telemetry/models.rs | 15 +++++++++------ src/telemetry/runtime.rs | 30 ++++++++++++------------------ 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f428c382..00346e0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,7 +68,8 @@ webpki-roots = { version = "1.0.11", optional = true, default-features = false } tokio = { version = "1", features = ["full", "sync"] } # Serialization -serde = { version = "1", features = ["derive"] } +# `rc`: telemetry events share the session's configuration through `Arc`. +serde = { version = "1", features = ["derive", "rc"] } serde_json = "1" base64 = "0.22" hex = "0.4" # Hex encoding (binary param literals, token cache key) diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 6aa75289..05f9ff40 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -20,6 +20,8 @@ changes go in their respective binding's NEXT_CHANGELOG. with an optional partner entry from `adbc.databricks.user_agent_entry` (`adbc.spark.user_agent_entry` is a compatibility alias). `User-Agent` in `adbc.databricks.http.headers` is now rejected; use the dedicated entry option. +- Telemetry events share their session's system configuration and connection + parameters instead of copying them into every statement event. ### Updated diff --git a/src/telemetry/models.rs b/src/telemetry/models.rs index e816b053..8fbdaf1f 100644 --- a/src/telemetry/models.rs +++ b/src/telemetry/models.rs @@ -13,6 +13,7 @@ // limitations under the License. use serde::{Deserialize, Serialize}; +use std::sync::Arc; use std::time::{SystemTime, UNIX_EPOCH}; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -70,10 +71,12 @@ pub(crate) struct OssSqlDriverTelemetryLog { pub session_id: Option, #[serde(skip_serializing_if = "Option::is_none")] pub sql_statement_id: Option, + /// Shared with the session and every other event it emits. #[serde(skip_serializing_if = "Option::is_none")] - pub system_configuration: Option, + pub system_configuration: Option>, + /// Shared with the session and every other event it emits. #[serde(skip_serializing_if = "Option::is_none")] - pub driver_connection_params: Option, + pub driver_connection_params: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub auth_type: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -447,7 +450,7 @@ mod tests { let log = OssSqlDriverTelemetryLog { session_id: Some("session-1".to_string()), sql_statement_id: Some("statement-1".to_string()), - system_configuration: Some(DriverSystemConfiguration { + system_configuration: Some(Arc::new(DriverSystemConfiguration { driver_version: Some("0.2.1".to_string()), runtime_name: Some("rust".to_string()), runtime_version: Some("1.0".to_string()), @@ -460,8 +463,8 @@ mod tests { locale_name: Some("en_US".to_string()), char_set_encoding: Some("UTF-8".to_string()), process_name: Some("cargo".to_string()), - }), - driver_connection_params: Some(DriverConnectionParameters { + })), + driver_connection_params: Some(Arc::new(DriverConnectionParameters { http_path: Some("/sql/1.0/warehouses/abc".to_string()), mode: Some(DriverMode::Sea), host_info: Some(HostDetails { @@ -475,7 +478,7 @@ mod tests { async_poll_interval_millis: Some(1000), auto_commit: Some(true), ..Default::default() - }), + })), auth_type: Some("pat".to_string()), vol_operation: Some(VolumeOperationEvent { volume_operation_type: Some(VolumeOperationType::List), diff --git a/src/telemetry/runtime.rs b/src/telemetry/runtime.rs index 1b8f751b..2c305ba9 100644 --- a/src/telemetry/runtime.rs +++ b/src/telemetry/runtime.rs @@ -32,6 +32,8 @@ use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::Arc; use std::time::Duration; +const TELEMETRY_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); + pub(crate) struct TelemetryRuntime { connection: Arc, } @@ -62,8 +64,8 @@ impl TelemetryRuntime { .as_deref() .and_then(|org_id| org_id.parse::().ok()) .unwrap_or_default(), - system_configuration: build_system_configuration(system_configuration), - connection_params: build_connection_params(connection, auth), + system_configuration: Arc::new(build_system_configuration(system_configuration)), + connection_params: Arc::new(build_connection_params(connection, auth)), auth_type: auth_type(auth), }); let (exporter, bypass_cache) = exporter_for_config(config, connection, http_client); @@ -126,8 +128,8 @@ pub(crate) trait ConnectionTelemetry: Send + Sync { pub(crate) struct TelemetrySessionContext { pub session_id: String, pub workspace_id: i64, - pub system_configuration: DriverSystemConfiguration, - pub connection_params: DriverConnectionParameters, + pub system_configuration: Arc, + pub connection_params: Arc, pub auth_type: String, } @@ -179,19 +181,15 @@ impl RealConnectionTelemetry { frontend_log_event_id: format!("{}-{event_id}", self.session.session_id), context: Some(FrontendLogContext { client_context: Some(TelemetryClientContext { - user_agent: Some(format!( - "{}/{}", - env!("CARGO_PKG_NAME"), - env!("CARGO_PKG_VERSION") - )), + user_agent: Some(TELEMETRY_USER_AGENT.to_string()), }), timestamp_millis: unix_time_millis(), }), entry: Some(FrontendLogEntry { sql_driver_log: Some(OssSqlDriverTelemetryLog { session_id: Some(self.session.session_id.clone()), - system_configuration: Some(self.session.system_configuration.clone()), - driver_connection_params: Some(self.session.connection_params.clone()), + system_configuration: Some(Arc::clone(&self.session.system_configuration)), + driver_connection_params: Some(Arc::clone(&self.session.connection_params)), auth_type: Some(self.session.auth_type.clone()), sql_operation: Some(SqlExecutionEvent { operation_detail: Some(OperationDetail { @@ -233,11 +231,7 @@ impl RealConnectionTelemetry { frontend_log_event_id: format!("{}-{event_id}", self.session.session_id), context: Some(FrontendLogContext { client_context: Some(TelemetryClientContext { - user_agent: Some(format!( - "{}/{}", - env!("CARGO_PKG_NAME"), - env!("CARGO_PKG_VERSION") - )), + user_agent: Some(TELEMETRY_USER_AGENT.to_string()), }), timestamp_millis: unix_time_millis(), }), @@ -245,8 +239,8 @@ impl RealConnectionTelemetry { sql_driver_log: Some(OssSqlDriverTelemetryLog { session_id: Some(self.session.session_id.clone()), sql_statement_id: context.statement_id, - system_configuration: Some(self.session.system_configuration.clone()), - driver_connection_params: Some(self.session.connection_params.clone()), + system_configuration: Some(Arc::clone(&self.session.system_configuration)), + driver_connection_params: Some(Arc::clone(&self.session.connection_params)), auth_type: Some(self.session.auth_type.clone()), sql_operation: Some(SqlExecutionEvent { statement_type: Some(context.statement_type),