@@ -599,9 +599,24 @@ def set_tag(self, key, value):
599599 # type: (str, Any) -> None
600600 self ._tags [key ] = value
601601
602- def set_data (self , key , value ):
603- # type: (str, Any) -> None
604- self ._data [key ] = value
602+ def set_data (self , key , value = None ):
603+ # type: (Union[str, Dict[str, Any]], Any) -> None
604+ """Set data on the span.
605+
606+ Can be called in two ways:
607+ - set_data(key, value) - sets a single key-value pair
608+ - set_data({"key": "value"}) - sets multiple key-value pairs from a dict
609+ """
610+ if isinstance (key , dict ):
611+ # Dictionary calling pattern: set_data({"key": "value"})
612+ for k , v in key .items ():
613+ self ._data [k ] = v
614+ else :
615+ # Traditional calling pattern: set_data(key, value)
616+ if value is None :
617+ raise ValueError ("Value must be provided when key is a string" )
618+
619+ self ._data [key ] = value
605620
606621 def set_flag (self , flag , result ):
607622 # type: (str, bool) -> None
@@ -1272,8 +1287,8 @@ def set_tag(self, key, value):
12721287 # type: (str, Any) -> None
12731288 pass
12741289
1275- def set_data (self , key , value ):
1276- # type: (str, Any) -> None
1290+ def set_data (self , key , value = None ):
1291+ # type: (Union[ str, Dict[str, Any]] , Any) -> None
12771292 pass
12781293
12791294 def set_status (self , value ):
@@ -1343,18 +1358,20 @@ def trace(func):
13431358 pass
13441359
13451360
1346- def trace (func = None , * , as_type = "span" , name = None , attributes = None ):
1347- # type: (Optional[Callable[P, R]], str, Optional[str], Optional[dict[str, Any]]) -> Union[Callable[P, R], Callable[[Callable[P, R]], Callable[P, R]]]
1361+ def trace (func = None , * , template = "span" , op = None , name = None , attributes = None ):
1362+ # type: (Optional[Callable[P, R]], str, Optional[str], Optional[str], Optional[ dict[str, Any]]) -> Union[Callable[P, R], Callable[[Callable[P, R]], Callable[P, R]]]
13481363 """
13491364 Decorator to start a child span.
13501365
13511366 :param func: The function to trace.
1352- :param as_type: The type of span to create.
1367+ :param template: The type of span to create.
1368+ :param op: The operation of the span.
13531369 :param name: The name of the span. (defaults to the function name)
13541370 :param attributes: Additional attributes to set on the span.
13551371 """
13561372 decorator = create_span_decorator (
1357- template = as_type ,
1373+ template = template ,
1374+ op = op ,
13581375 name = name ,
13591376 attributes = attributes ,
13601377 )
0 commit comments