1717import asyncio
1818import inspect
1919import logging
20+ import time
2021from typing import Optional
2122
2223from garf .core import query_editor , report , report_fetcher
23- from garf .executors import execution_context , query_processor
24+ from garf .executors import execution_context , query_processor , telemetry
2425from garf .executors .telemetry import tracer
2526from garf .io .writers import abs_writer
2627from opentelemetry import trace
@@ -58,7 +59,9 @@ def execute(
5859 Returns:
5960 Report with data if query returns some data otherwise empty Report.
6061 """
62+ start_time = time .perf_counter ()
6163 span = trace .get_current_span ()
64+ executor_attributes = {'executor.class' : self .__class__ .__name__ }
6265 query_spec = (
6366 query_editor .QuerySpecification (
6467 text = query , title = title , args = context .query_parameters
@@ -76,14 +79,25 @@ def execute(
7679 if self .preprocessors :
7780 _handle_processors (processors = self .preprocessors , context = context )
7881 results = self ._execute (query = query_text , title = title , context = context )
82+ if hasattr (self , 'fetcher' ):
83+ fetcher_attributes = {
84+ 'api.client.class' : self .fetcher .api_client .__class__ .__name__
85+ }
86+ executor_attributes .update (fetcher_attributes )
87+ telemetry .executor_counter .add (1 , executor_attributes )
7988 if (results or results .results_placeholder ) and (
8089 self .writers or context .writer
8190 ):
8291 writer_clients = self .writers or context .writer_clients
83- return write_many (writer_clients , results , title )
92+ write_outputs = write_many (writer_clients , results , title )
93+ duration = time .perf_counter () - start_time
94+ telemetry .executor_histogram .record (duration , executor_attributes )
95+ return write_outputs
8496 span .set_attribute ('execute.num_results' , len (results ))
8597 if self .postprocessors :
8698 _handle_processors (processors = self .postprocessors , context = context )
99+ duration = time .perf_counter () - start_time
100+ telemetry .executor_histogram .record (duration , executor_attributes )
87101 return results
88102
89103 def _execute (
@@ -207,12 +221,17 @@ def write_many(
207221) -> Optional [str ]:
208222 writing_results = []
209223 for writer_client in writer_clients :
224+ start_time = time .perf_counter ()
210225 logger .debug (
211226 'Start writing data for query %s via %s writer' ,
212227 title ,
213228 type (writer_client ),
214229 )
215230 writing_result = writer_client .write (results , title )
231+ duration = time .perf_counter () - start_time
232+ telemetry .write_histogram .record (
233+ duration , {'writer_class' : writer_client .__class__ .__name__ }
234+ )
216235 logger .debug (
217236 'Finish writing data for query %s via %s writer' ,
218237 title ,
0 commit comments