@@ -21,36 +21,24 @@ def get_ai_pipeline_name():
21
21
return _ai_pipeline_name .get ()
22
22
23
23
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]
44
26
def decorator (f ):
45
27
# type: (Callable[..., Any]) -> Callable[..., Any]
46
28
@wraps (f )
47
29
def wrapped (* args , ** kwargs ):
48
30
# 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" )
49
33
with start_span (description = description , op = op , ** span_kwargs ) as span :
50
- curr_pipeline = _ai_pipeline_name .get ()
51
34
if curr_pipeline :
52
35
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
54
42
55
43
return wrapped
56
44
0 commit comments