langfuse-python icon indicating copy to clipboard operation
langfuse-python copied to clipboard

feat(client): allow more params.(like langfuse_version, etc)

Open XenoAmess opened this issue 11 months ago • 2 comments

[!IMPORTANT] Enhance on_chain_start in langchain.py to dynamically update trace-level parameters using metadata prefixed with langfuse_.

  • Behavior:
    • In on_chain_start in langchain.py, trace-level information is updated with metadata keys prefixed by langfuse_.
    • This allows dynamic updates to parameters like session_id and user_id based on metadata.
  • Misc:
    • Refactored code to use a dictionary update_dict for updating trace information.

This description was created by Ellipsis for 0b4f495ae1c9144f0d249718c819b146c08cb5a2. It will automatically update as commits are pushed.

Greptile Summary

Disclaimer: Experimental PR review

Added support for dynamic trace parameter updates through metadata prefixing in the langchain callback handler, but introduced a bug that breaks existing functionality.

  • Fixed bug in on_chain_start where session_id and user_id are incorrectly set to None instead of using metadata values
  • Added support for dynamic parameter updates via langfuse_ prefixed metadata keys
  • Improved code organization by collecting updates in a dictionary before applying to trace
  • Maintained backward compatibility for existing metadata parameter handling

The main issue is that the current implementation always sets session_id and user_id to None in the update_dict, overriding any values that may have been set in metadata. This needs to be fixed to preserve the existing functionality while adding support for the new dynamic parameters.

💡 (2/5) Greptile learns from your feedback when you react with 👍/👎!

XenoAmess avatar Apr 16 '25 10:04 XenoAmess

@XenoAmess Thanks for raising this! As per our contributing guide, could you please open a Github issue / discussion first to lay out your line of thinking for this change to continue the discussion there on why this should be merged / this feature is necessary?

hassiebp avatar May 05 '25 10:05 hassiebp

@XenoAmess Thanks for raising this! As per our contributing guide, could you please open a Github issue / discussion first to lay out your line of thinking for this change to continue the discussion there on why this should be merged / this feature is necessary?

sure, at https://github.com/orgs/langfuse/discussions/6697

XenoAmess avatar May 06 '25 02:05 XenoAmess

Thanks for raising this @XenoAmess - please upgrade to the Langfuse SDK v3 as the v2 will only get critical bug fixes and security patches

hassiebp avatar Aug 27 '25 15:08 hassiebp