Skip to content

Commit 5fb8765

Browse files
gustavocidornelaswhoseoyster
authored andcommitted
feat: allow inference_pipeline_id to be specified as a kwarg for tracing
1 parent 7f827a5 commit 5fb8765

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/openlayer/lib/tracing/tracer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def create_step(
4242
inputs: Optional[Any] = None,
4343
output: Optional[Any] = None,
4444
metadata: Optional[Dict[str, Any]] = None,
45+
inference_pipeline_id: Optional[str] = None,
4546
) -> Generator[steps.Step, None, None]:
4647
"""Starts a trace and yields a Step object."""
4748
new_step: steps.Step = steps.step_factory(
@@ -99,7 +100,8 @@ def create_step(
99100
if _publish:
100101
try:
101102
_client.inference_pipelines.data.stream(
102-
id=utils.get_env_variable("OPENLAYER_INFERENCE_PIPELINE_ID"),
103+
inference_pipeline_id=inference_pipeline_id
104+
or utils.get_env_variable("OPENLAYER_INFERENCE_PIPELINE_ID"),
103105
rows=[trace_data],
104106
config=config,
105107
)
@@ -119,7 +121,7 @@ def add_chat_completion_step_to_trace(**kwargs) -> None:
119121

120122

121123
# ----------------------------- Tracing decorator ---------------------------- #
122-
def trace(*step_args, **step_kwargs):
124+
def trace(*step_args, inference_pipeline_id: Optional[str] = None, **step_kwargs):
123125
"""Decorator to trace a function.
124126
125127
Examples
@@ -163,7 +165,7 @@ def decorator(func):
163165
def wrapper(*func_args, **func_kwargs):
164166
if step_kwargs.get("name") is None:
165167
step_kwargs["name"] = func.__name__
166-
with create_step(*step_args, **step_kwargs) as step:
168+
with create_step(*step_args, inference_pipeline_id=inference_pipeline_id, **step_kwargs) as step:
167169
output = exception = None
168170
try:
169171
output = func(*func_args, **func_kwargs)
@@ -196,7 +198,7 @@ def wrapper(*func_args, **func_kwargs):
196198
return decorator
197199

198200

199-
def trace_async(*step_args, **step_kwargs):
201+
def trace_async(*step_args, inference_pipeline_id: Optional[str] = None, **step_kwargs):
200202
"""Decorator to trace a function.
201203
202204
Examples
@@ -240,7 +242,7 @@ def decorator(func):
240242
async def wrapper(*func_args, **func_kwargs):
241243
if step_kwargs.get("name") is None:
242244
step_kwargs["name"] = func.__name__
243-
with create_step(*step_args, **step_kwargs) as step:
245+
with create_step(*step_args, inference_pipeline_id=inference_pipeline_id, **step_kwargs) as step:
244246
output = exception = None
245247
try:
246248
output = await func(*func_args, **func_kwargs)

0 commit comments

Comments
 (0)