Skip to content

Commit 2d0c3c8

Browse files
feat(tracer): add detailed debug logging for step creation and trace completion
1 parent 6611c05 commit 2d0c3c8

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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,21 @@ def stream_chunks(
156156
provider = "unknown"
157157
latest_chunk_metadata = {}
158158

159+
# #region agent log - Debug: Check parent step before creating LiteLLM step
160+
_parent = tracer.get_current_step()
161+
_trace = tracer.get_current_trace()
162+
print(f"[OPENLAYER_DEBUG] litellm_tracer:stream_chunks | BEFORE create_step | parent_step={_parent.name if _parent else None} | has_trace={_trace is not None}", flush=True)
163+
# #endregion
164+
159165
# Create step immediately so it's added to parent trace before parent publishes
160166
with tracer.create_step(
161167
name="LiteLLM Chat Completion",
162168
step_type=tracer_enums.StepType.CHAT_COMPLETION,
163169
inputs={"prompt": kwargs.get("messages", [])},
164170
) as step:
171+
# #region agent log - Debug: Check if step is root after creation
172+
print(f"[OPENLAYER_DEBUG] litellm_tracer:stream_chunks | AFTER create_step | step_id={step.id[:8] if step.id else None} | is_root={_parent is None}", flush=True)
173+
# #endregion
165174
try:
166175
i = 0
167176
for i, chunk in enumerate(chunks):

src/openlayer/lib/tracing/tracer.py

Lines changed: 10 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:_create_and_initialize_step | step_name={step_name} | is_root_step={is_root_step} | parent={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,9 @@ 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 entry
1353+
print(f"[OPENLAYER_DEBUG] tracer:_handle_trace_completion | step_name={step_name} | is_root_step={is_root_step}", flush=True)
1354+
# #endregion
13481355
if is_root_step:
13491356
logger.debug("Ending the trace...")
13501357
current_trace = get_current_trace()
@@ -1398,6 +1405,9 @@ def _handle_trace_completion(
13981405
client = _get_client()
13991406

14001407
if client:
1408+
# #region agent log - Debug: About to publish trace
1409+
print(f"[OPENLAYER_DEBUG] tracer:_handle_trace_completion | PUBLISHING | inferenceId={trace_data.get('inferenceId', 'unknown')[:8]} | step_name={step_name}", flush=True)
1410+
# #endregion
14011411
try:
14021412
response = client.inference_pipelines.data.stream(
14031413
inference_pipeline_id=inference_pipeline_id,

0 commit comments

Comments
 (0)