feat(langchain): add update_trace argument #1302
Merged
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.
Important
Adds
update_traceparameter toLangchainCallbackHandlerfor optional trace-level data updates on root-level chains.update_traceparameter toLangchainCallbackHandlerconstructor, defaulting toFalse.on_chain_start).on_chain_end).span.update_trace()method for trace updates.update_traceisFalse, maintaining existing behavior unless explicitly enabled.This description was created by
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_traceparameter to theLangchainCallbackHandlerclass, 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:on_chain_startwithparent_run_idofNone), the trace is updated with the chain's input, name, and metadataon_chain_end), the trace is updated with both the final output and the original inputThe feature is controlled by a boolean flag passed to the constructor (
update_trace=Falseby 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