@@ -205,26 +205,33 @@ def _setup_auto_collector(self, app_name: str, environment: str, instruments: Op
205205 # Fallback to no-op tracer
206206 self .tracer = None
207207
208- def trace (self ):
208+ def trace (self , name : Optional [ str ] = None ):
209209 """
210210 Decorator to trace function calls for Quotient.
211211
212212 The TracingResource must be pre-configured via the configure() method
213213 before using this decorator.
214214
215+ Args:
216+ name: Optional custom name for the span. If not provided, uses func.__qualname__
217+
215218 Example:
216219 quotient.tracer.init(app_name="my_app", environment="prod")
217220 @quotient.trace()
218221 def my_function():
219222 pass
223+
224+ @quotient.trace('myagent')
225+ def my_other_function():
226+ pass
220227 """
221228 # Use only configured values - no parameters accepted
222229 if not self ._app_name or not self ._environment :
223230 logger .error ("tracer must be initialized with valid inputs before using trace(). Double check your inputs and try again." )
224231 return lambda func : func
225232
226233 def decorator (func ):
227- name = func .__qualname__
234+ span_name = name if name is not None else func .__qualname__
228235
229236 @functools .wraps (func )
230237 def sync_func_wrapper (* args , ** kwargs ):
@@ -240,7 +247,7 @@ def sync_func_wrapper(*args, **kwargs):
240247 if self .tracer is None :
241248 return func (* args , ** kwargs )
242249
243- with self .tracer .start_as_current_span (name ) as root_span :
250+ with self .tracer .start_as_current_span (span_name ) as root_span :
244251 try :
245252 result = func (* args , ** kwargs )
246253 except Exception as e :
@@ -267,7 +274,7 @@ async def async_func_wrapper(*args, **kwargs):
267274 if self .tracer is None :
268275 return await func (* args , ** kwargs )
269276
270- with self .tracer .start_as_current_span (name ) as root_span :
277+ with self .tracer .start_as_current_span (span_name ) as root_span :
271278 try :
272279 result = await func (* args , ** kwargs )
273280 except Exception as e :
0 commit comments