Skip to content

feat: allow output overwrite #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/openlayer/lib/tracing/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,23 @@ def sync_wrapper(*func_args, **func_kwargs):
return decorator


def log_output(output: Any) -> None:
"""Logs output information to the current step of the trace.

This will overwrite the output of the currently active step instead of
relying on the returned object from the traced function.

Args:
output: The output value to log to the current step.
"""
current_step = get_current_step()
if current_step:
logger.debug("Logging output to current step: %s", output)
current_step.log(output=output, metadata={"manual_output_logged": True})
else:
logger.warning("No current step found to log output.")


def log_context(context: List[str]) -> None:
"""Logs context information to the current step of the trace.

Expand Down Expand Up @@ -562,9 +579,14 @@ def _finalize_step_logging(
if step.latency is None:
step.latency = (step.end_time - start_time) * 1000 # in ms

# Check if manual output was logged
if step.metadata.get("manual_output_logged"):
logger.debug("Using manually logged output for step: %s", step.name)
else:
step.log(output=output)

step.log(
inputs=inputs,
output=output,
end_time=step.end_time,
latency=step.latency,
)
Expand Down