Fix: include traces generated from @traceable decorator#32
Open
Seán (seanderoiste) wants to merge 2 commits into
Open
Fix: include traces generated from @traceable decorator#32Seán (seanderoiste) wants to merge 2 commits into
Seán (seanderoiste) wants to merge 2 commits into
Conversation
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>
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
messagesfield at the root level.Updated
_extract_messages_from_child_runs()to:Why
Traces created with the
@traceabledecorator don't populate amessagesfield 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" } ]