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

feat: Add functionality to pass custom serializer

Open davidberenstein1957 opened this issue 9 months ago • 1 comments

Introduce BaseEventSerializer as an abstract base class

This refactoring introduces a new BaseEventSerializer abstract base class that provides a common interface and shared functionality for JSON serialization. Key changes include:

  • Creating an abstract base class with common serialization methods

  • Moving shared serialization logic to the base class

  • Adding an abstract default method for object serialization

  • Implementing safe integer range checking

  • Updating references in other files to use the new base class

  • [ ] documentation with explanation

  • [ ] JS SDK

Greptile Summary

Disclaimer: Experimental PR review

Introduces a new BaseEventSerializer abstract base class to standardize JSON serialization across the codebase, enabling custom serializer implementations while maintaining existing functionality.

  • Missing initialization of _serializer field in LangfuseClient.__init__ in langfuse/request.py needs to be added to prevent runtime errors
  • IngestionConsumer._serializer defined as class variable could cause shared state issues with multiple instances
  • No constructor parameter in IngestionConsumer to configure custom serializers without subclassing
  • Added abstract BaseEventSerializer with required default() method in langfuse/serializer.py
  • Test case for custom serializer extension needs pandas dependency added to test requirements

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

davidberenstein1957 avatar Feb 17 '25 14:02 davidberenstein1957

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Feb 17 '25 14:02 CLAassistant

Thanks again for your contribution! Closing this PR as stale / no longer mergeable in Python SDK v3. If you have specific requirements for a separate serializer, please open a Github issue for us to conduct the discussion there

hassiebp avatar Jul 15 '25 08:07 hassiebp