Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add functionality to pass custom serializer #1116

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

davidberenstein1957
Copy link

@davidberenstein1957 davidberenstein1957 commented Feb 17, 2025

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!

…se 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
@CLAassistant
Copy link

CLAassistant commented Feb 17, 2025

CLA assistant check
All committers have signed the CLA.

@davidberenstein1957 davidberenstein1957 changed the title refactor(serializer): Introduce BaseEventSerializer as an abstract ba… feat: Add functionality to pass custom serializer Feb 17, 2025
Copy link

@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.

5 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Copy link

@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.

5 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -60,7 +61,7 @@ def post(self, **kwargs) -> httpx.Response:
"""Post the `kwargs` to the API"""
log = logging.getLogger("langfuse")
url = self._remove_trailing_slash(self._base_url) + "/api/public/ingestion"
data = json.dumps(kwargs, cls=EventSerializer)
data = json.dumps(kwargs, cls=self._serializer)
Copy link

Choose a reason for hiding this comment

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

Ensure _serializer is initialized (e.g. self._serializer = EventSerializer) in init as it's used in json.dumps but not set.

Copy link

@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.

LGTM

5 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

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.

3 participants