77 SqlExecutionEvent ,
88)
99from databricks .sql .telemetry .models .enums import ExecutionResultFormat , StatementType
10- from databricks .sql .utils import ColumnQueue , CloudFetchQueue , ArrowQueue
1110from uuid import UUID
1211
1312logger = logging .getLogger (__name__ )
@@ -42,6 +41,9 @@ def get_execution_result(self):
4241 def get_retry_count (self ):
4342 pass
4443
44+ def get_chunk_id (self ):
45+ pass
46+
4547
4648class CursorExtractor (TelemetryExtractor ):
4749 """
@@ -63,7 +65,8 @@ def get_is_compressed(self) -> bool:
6365 def get_execution_result (self ) -> ExecutionResultFormat :
6466 if self .active_result_set is None :
6567 return ExecutionResultFormat .FORMAT_UNSPECIFIED
66-
68+
69+ from databricks .sql .utils import ColumnQueue , CloudFetchQueue , ArrowQueue
6770 if isinstance (self .active_result_set .results , ColumnQueue ):
6871 return ExecutionResultFormat .COLUMNAR_INLINE
6972 elif isinstance (self .active_result_set .results , CloudFetchQueue ):
@@ -74,11 +77,14 @@ def get_execution_result(self) -> ExecutionResultFormat:
7477
7578 def get_retry_count (self ) -> int :
7679 if (
77- hasattr (self .thrift_backend , "retry_policy" )
78- and self .thrift_backend .retry_policy
80+ hasattr (self .backend , "retry_policy" )
81+ and self .backend .retry_policy
7982 ):
80- return len (self .thrift_backend .retry_policy .history )
83+ return len (self .backend .retry_policy .history )
8184 return 0
85+
86+ def get_chunk_id (self ):
87+ return None
8288
8389
8490class ResultSetExtractor (TelemetryExtractor ):
@@ -101,6 +107,7 @@ def get_is_compressed(self) -> bool:
101107 return self .lz4_compressed
102108
103109 def get_execution_result (self ) -> ExecutionResultFormat :
110+ from databricks .sql .utils import ColumnQueue , CloudFetchQueue , ArrowQueue
104111 if isinstance (self .results , ColumnQueue ):
105112 return ExecutionResultFormat .COLUMNAR_INLINE
106113 elif isinstance (self .results , CloudFetchQueue ):
@@ -116,7 +123,34 @@ def get_retry_count(self) -> int:
116123 ):
117124 return len (self .thrift_backend .retry_policy .history )
118125 return 0
126+
127+ def get_chunk_id (self ):
128+ return None
129+
130+
131+ class ResultSetDownloadHandlerExtractor (TelemetryExtractor ):
132+ """
133+ Telemetry extractor specialized for ResultSetDownloadHandler objects.
134+ """
135+ def get_session_id_hex (self ) -> Optional [str ]:
136+ return self ._obj .session_id_hex
137+
138+ def get_statement_id (self ) -> Optional [str ]:
139+ return self ._obj .statement_id
140+
141+ def get_is_compressed (self ) -> bool :
142+ return self ._obj .settings .is_lz4_compressed
143+
144+ def get_execution_result (self ) -> ExecutionResultFormat :
145+ return ExecutionResultFormat .EXTERNAL_LINKS
146+
147+ def get_retry_count (self ) -> Optional [int ]:
148+ # standard requests and urllib3 libraries don't expose retry count
149+ return None
119150
151+ def get_chunk_id (self ) -> Optional [int ]:
152+ return self ._obj .chunk_id
153+
120154
121155def get_extractor (obj ):
122156 """
@@ -133,12 +167,15 @@ def get_extractor(obj):
133167 TelemetryExtractor: A specialized extractor instance:
134168 - CursorExtractor for Cursor objects
135169 - ResultSetExtractor for ResultSet objects
170+ - ResultSetDownloadHandlerExtractor for ResultSetDownloadHandler objects
136171 - None for all other objects
137172 """
138173 if obj .__class__ .__name__ == "Cursor" :
139174 return CursorExtractor (obj )
140175 elif obj .__class__ .__name__ == "ResultSet" :
141176 return ResultSetExtractor (obj )
177+ elif obj .__class__ .__name__ == "ResultSetDownloadHandler" :
178+ return ResultSetDownloadHandlerExtractor (obj )
142179 else :
143180 logger .debug ("No extractor found for %s" , obj .__class__ .__name__ )
144181 return None
@@ -196,6 +233,7 @@ def _safe_call(func_to_call):
196233 duration_ms = int ((end_time - start_time ) * 1000 )
197234
198235 extractor = get_extractor (self )
236+ print ("function name" , func .__name__ , "latency" , duration_ms , "session_id_hex" , extractor .get_session_id_hex (), "statement_id" , extractor .get_statement_id (), flush = True )
199237
200238 if extractor is not None :
201239 session_id_hex = _safe_call (extractor .get_session_id_hex )
@@ -205,7 +243,8 @@ def _safe_call(func_to_call):
205243 statement_type = statement_type ,
206244 is_compressed = _safe_call (extractor .get_is_compressed ),
207245 execution_result = _safe_call (extractor .get_execution_result ),
208- retry_count = _safe_call (extractor .get_retry_count ),
246+ retry_count = extractor .get_retry_count (),
247+ chunk_id = _safe_call (extractor .get_chunk_id ),
209248 )
210249
211250 telemetry_client = TelemetryClientFactory .get_telemetry_client (
0 commit comments