@@ -100,7 +100,12 @@ def init(
100100 """
101101 self .configure (app_name , environment , instruments , detections )
102102 detections_str = "," .join (detections ) if detections else None
103- self ._setup_auto_collector (app_name , environment , instruments , detections_str )
103+ self ._setup_auto_collector (
104+ app_name = app_name ,
105+ environment = environment ,
106+ instruments = tuple (instruments ),
107+ detections = detections_str ,
108+ )
104109
105110 def get_vector_db_instrumentors (self ):
106111 """
@@ -228,6 +233,7 @@ def _setup_auto_collector(
228233 if instruments :
229234 for instrument in instruments :
230235 instrument .instrument ()
236+
231237
232238 # Initialize tracer if not already done
233239 if self .tracer is None :
@@ -272,20 +278,19 @@ def my_other_function():
272278 def decorator (func ):
273279 span_name = name if name is not None else func .__qualname__
274280
281+ self ._setup_auto_collector (
282+ app_name = self ._app_name ,
283+ environment = self ._environment ,
284+ instruments = (
285+ tuple (self ._instruments )
286+ if self ._instruments is not None
287+ else None
288+ ),
289+ detections = self ._detections ,
290+ )
291+
275292 @functools .wraps (func )
276293 def sync_func_wrapper (* args , ** kwargs ):
277-
278- self ._setup_auto_collector (
279- app_name = self ._app_name ,
280- environment = self ._environment ,
281- instruments = (
282- tuple (self ._instruments )
283- if self ._instruments is not None
284- else None
285- ),
286- detections = self ._detections ,
287- )
288-
289294 # if there is no tracer, just run the function normally
290295 if self .tracer is None :
291296 return func (* args , ** kwargs )
@@ -307,17 +312,6 @@ def sync_func_wrapper(*args, **kwargs):
307312
308313 @functools .wraps (func )
309314 async def async_func_wrapper (* args , ** kwargs ):
310- self ._setup_auto_collector (
311- app_name = self ._app_name ,
312- environment = self ._environment ,
313- instruments = (
314- tuple (self ._instruments )
315- if self ._instruments is not None
316- else None
317- ),
318- detections = self ._detections ,
319- )
320-
321315 if self .tracer is None :
322316 return await func (* args , ** kwargs )
323317
@@ -343,6 +337,25 @@ async def async_func_wrapper(*args, **kwargs):
343337
344338 return decorator
345339
340+ def start_span (self , name : str ):
341+ """
342+ Start a span.
343+ """
344+ # Initialize tracer if not already done
345+ if self .tracer is None :
346+ self .tracer = get_tracer (
347+ TRACER_NAME , tracer_provider = get_tracer_provider ()
348+ )
349+
350+ # Use only configured values - no parameters accepted
351+ if not self ._app_name or not self ._environment :
352+ logger .error (
353+ "tracer must be initialized with valid inputs before using trace(). Double check your inputs and try again."
354+ )
355+ return lambda func : func
356+
357+ return self .tracer .start_span (name )
358+
346359 def _cleanup (self ):
347360 """
348361 Internal cleanup method registered with atexit.
0 commit comments