Skip to content

Commit d6f3859

Browse files
feat(tracer): add debug logging for step creation and trace completion
1 parent e08cf3f commit d6f3859

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/openlayer/lib/integrations/litellm_tracer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ def stream_chunks(
204204
except Exception as e:
205205
logger.error("Failed to yield chunk. %s", e)
206206
finally:
207+
# #region agent log - Debug: trace finally block execution
208+
_parent = tracer.get_current_step()
209+
_trace = tracer.get_current_trace()
210+
print(f"[OPENLAYER_DEBUG] litellm_tracer.py:finally | has_parent_step={_parent is not None} | parent_step_name={_parent.name if _parent else None} | has_trace={_trace is not None} | trace_steps_count={len(_trace.steps) if _trace else 0}", flush=True)
211+
# #endregion
207212
# Try to add step to the trace
208213
try:
209214
collected_output_data = [message for message in collected_output_data if message is not None]

src/openlayer/lib/tracing/tracer.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,10 @@ def _create_and_initialize_step(
13221322
parent_step = get_current_step()
13231323
is_root_step = parent_step is None
13241324

1325+
# #region agent log - Debug: step creation
1326+
print(f"[OPENLAYER_DEBUG] tracer.py:_create_and_initialize_step | step_name={step_name} | step_type={step_type} | is_root_step={is_root_step} | parent_step_name={parent_step.name if parent_step else None}", flush=True)
1327+
# #endregion
1328+
13251329
if parent_step is None:
13261330
logger.debug("Starting a new trace...")
13271331
current_trace = traces.Trace()
@@ -1345,6 +1349,16 @@ def _handle_trace_completion(
13451349
on_flush_failure: Optional[OnFlushFailureCallback] = None,
13461350
) -> None:
13471351
"""Handle trace completion and data streaming."""
1352+
# #region agent log - Debug: trace completion
1353+
_trace = get_current_trace()
1354+
_steps = [s.name for s in _trace.steps] if _trace and _trace.steps else []
1355+
_nested = []
1356+
if _trace and _trace.steps:
1357+
for s in _trace.steps:
1358+
if hasattr(s, 'steps') and s.steps:
1359+
_nested.extend([ns.name for ns in s.steps])
1360+
print(f"[OPENLAYER_DEBUG] tracer.py:_handle_trace_completion | step_name={step_name} | is_root_step={is_root_step} | has_trace={_trace is not None} | root_steps={_steps} | nested_steps={_nested}", flush=True)
1361+
# #endregion
13481362
if is_root_step:
13491363
logger.debug("Ending the trace...")
13501364
current_trace = get_current_trace()

0 commit comments

Comments
 (0)