Skip to content

Fix: include traces generated from @traceable decorator#32

Open
Seán (seanderoiste) wants to merge 2 commits into
mainfrom
sean/wrap-openai-support
Open

Fix: include traces generated from @traceable decorator#32
Seán (seanderoiste) wants to merge 2 commits into
mainfrom
sean/wrap-openai-support

Conversation

@seanderoiste
Copy link
Copy Markdown

@seanderoiste Seán (seanderoiste) commented Jan 9, 2026

Include all child runs in trace output

What Changed

Added functionality to extract and display all child runs for traces that don't have a messages field at the root level.

Updated _extract_messages_from_child_runs() to:

  • Fetch all direct child runs (previously only fetched LLM runs)
  • Extract key fields from each child run: name, run_type, inputs, outputs, error, status, start_time
  • Return child runs in chronological order
  • Include parent-level errors at the end

Why

Traces created with the @traceable decorator don't populate a messages field at the root level. Instead, all information is stored in child runs. This change makes that information accessible.

Example Output

[
  {
    "name": "ChatOpenAI",
    "run_type": "llm",
    "inputs": {...},
    "outputs": {...},
    "error": null,
    "status": "success",
    "start_time": "2026-01-09T18:47:01.675132"
  },
  {
    "name": "broken_tool",
    "run_type": "chain",
    "inputs": {"query": "Help user with something"},
    "outputs": {"output": null},
    "error": "RuntimeError('This tool is intentionally broken!')\n\nTraceback...",
    "status": "error",
    "start_time": "2026-01-09T18:47:03.688096"
  }
]

Problem: fetch_trace() returned [] for traces created with
wrap_openai(), even though messages were visible in LangSmith UI.

Root cause: wrap_openai stores messages in child LLM runs, not at
the root level like LangChain/LangGraph traces.

Solution: Added fallback to extract messages from child runs when
root-level messages are not found. Finds the last LLM child run
and combines inputs.messages with outputs.choices[0].message.

Maintains backward compatibility with existing LangChain traces.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@seanderoiste Seán (seanderoiste) changed the title Fix wrap_openai traces returning empty arrays Fix: include traces generated from @traceable decorator Jan 9, 2026
- Updated _extract_messages_from_child_runs() to fetch all child runs (not just LLM runs)
- Extract key fields: name, run_type, inputs, outputs, error, status, start_time
- Return child runs in chronological order
- Include parent-level errors at the end

This makes traces created with @Traceable decorator fully visible by extracting data from child runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant