Skip to content

Commit 46eaa77

Browse files
committed
Added classes required for telemetry
Signed-off-by: Sai Shree Pradhan <saishree.pradhan@databricks.com>
1 parent 48746d1 commit 46eaa77

20 files changed

+334
-0
lines changed

src/databricks/sql/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ def read(self) -> Optional[OAuthToken]:
234234
server_hostname, **kwargs
235235
)
236236

237+
self.server_telemetry_enabled = True
238+
self.client_telemetry_enabled = kwargs.get("enable_telemetry", False)
239+
self.telemetry_enabled = (
240+
self.client_telemetry_enabled and self.server_telemetry_enabled
241+
)
242+
telemetry_batch_size = kwargs.get("telemetry_batch_size", 200)
243+
237244
user_agent_entry = kwargs.get("user_agent_entry")
238245
if user_agent_entry is None:
239246
user_agent_entry = kwargs.get("_user_agent_entry")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import json
2+
from dataclasses import dataclass, asdict
3+
from databricks.sql.telemetry.HostDetails import HostDetails
4+
from databricks.sql.telemetry.enums.AuthMech import AuthMech
5+
from databricks.sql.telemetry.enums.AuthFlow import AuthFlow
6+
from databricks.sql.telemetry.enums.DatabricksClientType import DatabricksClientType
7+
8+
9+
@dataclass
10+
class DriverConnectionParameters:
11+
http_path: str
12+
driver_mode: DatabricksClientType
13+
host_details: HostDetails
14+
auth_mech: AuthMech
15+
auth_flow: AuthFlow
16+
auth_scope: str
17+
discovery_url: str
18+
allowed_volume_ingestion_paths: str
19+
azure_tenant_id: str
20+
socket_timeout: int
21+
22+
def to_json(self):
23+
return json.dumps(asdict(self))
24+
25+
26+
# Part of TelemetryEvent
27+
# DriverConnectionParameters connectionParams = new DriverConnectionParameters(
28+
# httpPath = " /sql/1.0/endpoints/1234567890abcdef",
29+
# driverMode = "THRIFT",
30+
# hostDetails = new HostDetails(
31+
# hostUrl = "https://my-workspace.cloud.databricks.com",
32+
# port = 443
33+
# ),
34+
# authMech = "OAUTH",
35+
# authFlow = "AZURE_MANAGED_IDENTITIES",
36+
# authScope = "sql",
37+
# discoveryUrl = "https://example-url",
38+
# allowedVolumeIngestionPaths = "[]",
39+
# azureTenantId = "1234567890abcdef",
40+
# socketTimeout = 10000
41+
# )
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json
2+
from dataclasses import dataclass, asdict
3+
4+
5+
@dataclass
6+
class DriverErrorInfo:
7+
error_name: str
8+
stack_trace: str
9+
10+
def to_json(self):
11+
return json.dumps(asdict(self))
12+
13+
14+
# Required for ErrorLogs
15+
# DriverErrorInfo errorInfo = new DriverErrorInfo(
16+
# errorName="CONNECTION_ERROR",
17+
# stackTrace="Connection failure while using the Databricks SQL Python connector. Failed to connect to server: https://my-workspace.cloud.databricks.com\n" +
18+
# "databricks.sql.exc.OperationalError: Connection refused: connect\n" +
19+
# "at databricks.sql.thrift_backend.ThriftBackend.make_request(ThriftBackend.py:329)\n" +
20+
# "at databricks.sql.thrift_backend.ThriftBackend.attempt_request(ThriftBackend.py:366)\n" +
21+
# "at databricks.sql.thrift_backend.ThriftBackend.open_session(ThriftBackend.py:575)\n" +
22+
# "at databricks.sql.client.Connection.__init__(client.py:69)\n" +
23+
# "at databricks.sql.client.connect(connection.py:123)")
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import json
2+
from dataclasses import dataclass, asdict
3+
from databricks.sql import __version__
4+
5+
6+
@dataclass
7+
class DriverSystemConfiguration:
8+
driver_version: str
9+
os_name: str
10+
os_version: str
11+
os_arch: str
12+
runtime_name: str
13+
runtime_version: str
14+
runtime_vendor: str
15+
client_app_name: str
16+
locale_name: str
17+
driver_name: str
18+
char_set_encoding: str
19+
20+
def to_json(self):
21+
return json.dumps(asdict(self))
22+
23+
24+
# Part of TelemetryEvent
25+
# DriverSystemConfiguration systemConfig = new DriverSystemConfiguration(
26+
# driver_version = "2.9.3",
27+
# os_name = "Darwin",
28+
# os_version = "24.4.0",
29+
# os_arch = "arm64",
30+
# runtime_name = "CPython",
31+
# runtime_version = "3.13.3",
32+
# runtime_vendor = "cpython",
33+
# client_app_name = "databricks-sql-python",
34+
# locale_name = "en_US",
35+
# driver_name = "databricks-sql-python",
36+
# char_set_encoding = "UTF-8"
37+
# )
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import json
2+
from dataclasses import dataclass, asdict
3+
from databricks.sql.telemetry.enums.DriverVolumeOperationType import (
4+
DriverVolumeOperationType,
5+
)
6+
7+
8+
@dataclass
9+
class DriverVolumeOperation:
10+
volume_operation_type: DriverVolumeOperationType
11+
volume_path: str
12+
13+
def to_json(self):
14+
return json.dumps(asdict(self))
15+
16+
17+
# Part of TelemetryEvent
18+
# DriverVolumeOperation volumeOperation = new DriverVolumeOperation(
19+
# volumeOperationType = "LIST",
20+
# volumePath = "/path/to/volume"
21+
# )
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import json
2+
from dataclasses import dataclass, asdict
3+
from databricks.sql.telemetry.TelemetryClientContext import TelemetryClientContext
4+
5+
6+
@dataclass
7+
class FrontendLogContext:
8+
client_context: TelemetryClientContext
9+
10+
def to_json(self):
11+
return json.dumps(asdict(self))
12+
13+
14+
# used in TelemetryFrontendLog
15+
# FrontendLogContext frontendLogContext = new FrontendLogContext(
16+
# clientContext = new TelemetryClientContext(
17+
# timestampMillis = 1716489600000,
18+
# userAgent = "databricks-sql-python-test"
19+
# )
20+
# )
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import json
2+
from dataclasses import dataclass, asdict
3+
from databricks.sql.telemetry.TelemetryEvent import TelemetryEvent
4+
5+
6+
@dataclass
7+
class FrontendLogEntry:
8+
sql_driver_log: TelemetryEvent
9+
10+
def to_json(self):
11+
return json.dumps(asdict(self))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import json
2+
from dataclasses import dataclass, asdict
3+
4+
5+
@dataclass
6+
class HostDetails:
7+
host_url: str
8+
port: int
9+
10+
def to_json(self):
11+
return json.dumps(asdict(self))
12+
13+
14+
# Part of DriverConnectionParameters
15+
# HostDetails hostDetails = new HostDetails(
16+
# hostUrl = "https://my-workspace.cloud.databricks.com",
17+
# port = 443
18+
# )
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import json
2+
from dataclasses import dataclass, asdict
3+
from databricks.sql.telemetry.enums.StatementType import StatementType
4+
from databricks.sql.telemetry.enums.ExecutionResultFormat import ExecutionResultFormat
5+
6+
7+
@dataclass
8+
class SqlExecutionEvent:
9+
statement_type: StatementType
10+
is_compressed: bool
11+
execution_result: ExecutionResultFormat
12+
retry_count: int
13+
14+
def to_json(self):
15+
return json.dumps(asdict(self))
16+
17+
18+
# Part of TelemetryEvent
19+
# SqlExecutionEvent sqlExecutionEvent = new SqlExecutionEvent(
20+
# statementType = "QUERY",
21+
# isCompressed = true,
22+
# executionResult = "INLINE_ARROW",
23+
# retryCount = 0
24+
# )
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from dataclasses import dataclass, asdict
2+
import json
3+
4+
5+
@dataclass
6+
class TelemetryClientContext:
7+
timestamp_millis: int
8+
user_agent: str
9+
10+
def to_json(self):
11+
return json.dumps(asdict(self))
12+
13+
14+
# used in FrontendLogContext
15+
# TelemetryClientContext clientContext = new TelemetryClientContext(
16+
# timestampMillis = 1716489600000,
17+
# userAgent = "databricks-sql-python-test"
18+
# )

0 commit comments

Comments
 (0)