Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 9 additions & 6 deletions src/telemetry/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -70,10 +71,12 @@ pub(crate) struct OssSqlDriverTelemetryLog {
pub session_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sql_statement_id: Option<String>,
/// Shared with the session and every other event it emits.
#[serde(skip_serializing_if = "Option::is_none")]
pub system_configuration: Option<DriverSystemConfiguration>,
pub system_configuration: Option<Arc<DriverSystemConfiguration>>,
/// Shared with the session and every other event it emits.
#[serde(skip_serializing_if = "Option::is_none")]
pub driver_connection_params: Option<DriverConnectionParameters>,
pub driver_connection_params: Option<Arc<DriverConnectionParameters>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub auth_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -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()),
Expand All @@ -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 {
Expand All @@ -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),
Expand Down
30 changes: 12 additions & 18 deletions src/telemetry/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn ConnectionTelemetry>,
}
Expand Down Expand Up @@ -62,8 +64,8 @@ impl TelemetryRuntime {
.as_deref()
.and_then(|org_id| org_id.parse::<i64>().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);
Expand Down Expand Up @@ -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<DriverSystemConfiguration>,
pub connection_params: Arc<DriverConnectionParameters>,
pub auth_type: String,
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -233,20 +231,16 @@ 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()),
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),
Expand Down
Loading