Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Aug 19, 2025

Important

Adds update_trace parameter to LangchainCallbackHandler for optional trace-level data updates on root-level chains.

  • Behavior:
    • Adds update_trace parameter to LangchainCallbackHandler constructor, defaulting to False.
    • Updates trace with input, name, and metadata on root-level chain start (on_chain_start).
    • Updates trace with output and input on root-level chain end (on_chain_end).
  • Conditional Logic:
    • Trace updates only occur for root-level chains to prevent duplicate data in nested chains.
    • Uses span.update_trace() method for trace updates.
  • Backward Compatibility:
    • Default update_trace is False, maintaining existing behavior unless explicitly enabled.

This description was created by Ellipsis for e96f13b. You can customize this summary. It will automatically update as commits are pushed.


Disclaimer: Experimental PR review

Greptile Summary

This PR introduces a new optional update_trace parameter to the LangchainCallbackHandler class, allowing users to automatically populate trace-level input and output data when using Langchain with Langfuse. The implementation adds trace updates at two key points in the chain execution lifecycle:

  1. Chain Start: When a root-level chain begins (on_chain_start with parent_run_id of None), the trace is updated with the chain's input, name, and metadata
  2. Chain End: When a root-level chain completes (on_chain_end), the trace is updated with both the final output and the original input

The feature is controlled by a boolean flag passed to the constructor (update_trace=False by default) and only activates for root-level chains to avoid duplicate data in nested chain scenarios. This enhancement bridges a gap between span-level observation data (which was already captured) and trace-level data, providing users with a complete picture of what went into and came out of their entire chain workflow.

The change integrates seamlessly with the existing callback handler architecture, using the same span.update_trace() method that's available elsewhere in the codebase. The conditional logic ensures backward compatibility while offering opt-in functionality for users who need trace-level input/output visibility.

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it adds optional functionality without breaking existing behavior
  • Score reflects well-structured conditional logic and proper integration with existing patterns, though testing coverage for the new feature isn't visible in the diff
  • Pay close attention to the callback handler file to ensure the conditional logic works correctly in all chain execution scenarios

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

hassiebp and others added 2 commits August 19, 2025 14:52
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
@hassiebp hassiebp merged commit da1eb86 into main Aug 19, 2025
10 checks passed
@hassiebp hassiebp deleted the langchain-update-trace branch August 19, 2025 13:01
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