@@ -21,36 +21,24 @@ def get_ai_pipeline_name():
2121 return _ai_pipeline_name .get ()
2222
2323
24- def ai_pipeline (description , op = "ai.pipeline" , ** span_kwargs ):
25- # type: (str, str, Any) -> Callable[..., Any]
26- def decorator (f ):
27- # type: (Callable[..., Any]) -> Callable[..., Any]
28- @wraps (f )
29- def wrapped (* args , ** kwargs ):
30- # type: (Any, Any) -> Any
31- with start_span (description = description , op = op , ** span_kwargs ):
32- _ai_pipeline_name .set (description )
33- res = f (* args , ** kwargs )
34- _ai_pipeline_name .set (None )
35- return res
36-
37- return wrapped
38-
39- return decorator
40-
41-
42- def ai_run (description , op = "ai.run" , ** span_kwargs ):
43- # type: (str, str, Any) -> Callable[..., Any]
24+ def ai_track (description , ** span_kwargs ):
25+ # type: (str, Any) -> Callable[..., Any]
4426 def decorator (f ):
4527 # type: (Callable[..., Any]) -> Callable[..., Any]
4628 @wraps (f )
4729 def wrapped (* args , ** kwargs ):
4830 # type: (Any, Any) -> Any
31+ curr_pipeline = _ai_pipeline_name .get ()
32+ op = span_kwargs .get ("op" , "ai.run" if curr_pipeline else "ai.pipeline" )
4933 with start_span (description = description , op = op , ** span_kwargs ) as span :
50- curr_pipeline = _ai_pipeline_name .get ()
5134 if curr_pipeline :
5235 span .set_data ("ai.pipeline.name" , curr_pipeline )
53- return f (* args , ** kwargs )
36+ return f (* args , ** kwargs )
37+ else :
38+ _ai_pipeline_name .set (description )
39+ res = f (* args , ** kwargs )
40+ _ai_pipeline_name .set (None )
41+ return res
5442
5543 return wrapped
5644
0 commit comments