2020import sys
2121from importlib .metadata import entry_points
2222
23+ from opentelemetry import trace
24+
2325from garf_io import exceptions
26+ from garf_io .telemetry import tracer
2427from garf_io .writers import abs_writer
2528
2629
30+ @tracer .start_as_current_span ('get_writers' )
2731def _get_writers ():
2832 if sys .version_info .major == 3 and sys .version_info .minor == 9 :
2933 try :
@@ -52,6 +56,7 @@ class GarfIoWriterError(exceptions.GarfIoError):
5256 """Writer specific exception."""
5357
5458
59+ @tracer .start_as_current_span ('create_writer' )
5560def create_writer (
5661 writer_option : str | WriterOption , ** kwargs : str
5762) -> type [abs_writer .AbsWriter ]:
@@ -71,13 +76,16 @@ def create_writer(
7176 ImportError: When writer specific library is not installed.
7277 GarfIoError: When incorrect writer option is specified.
7378 """
79+ span = trace .get_current_span ()
7480 try :
7581 WriterOption [writer_option ]
7682 except KeyError as e :
7783 raise GarfIoWriterError (f'{ writer_option } is unknown writer type!' ) from e
7884 found_writers = {}
7985 for writer in _get_writers ():
8086 try :
87+ if writer .name != writer_option :
88+ continue
8189 writer_module = writer .load ()
8290 for name , obj in inspect .getmembers (writer_module ):
8391 if inspect .isclass (obj ) and issubclass (obj , abs_writer .AbsWriter ):
@@ -89,5 +97,8 @@ def create_writer(
8997 raise e
9098 continue
9199 if concrete_writer := found_writers .get (writer_option ):
100+ span .set_attribute ('writer.alias' , writer_option )
101+ for k , v in kwargs .items ():
102+ span .set_attribute (f'{ writer_option } .{ k } ' , v )
92103 return concrete_writer (** kwargs )
93104 raise GarfIoWriterError (f'Failed to load { writer_option } !' )
0 commit comments