Skip to content

Conversation

@hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Dec 11, 2024

Important

Add timeout to resolve_media_references() in media.py and improve error handling in fetch_media() in client.py.

  • Behavior:
    • Add content_fetch_timeout_seconds parameter to resolve_media_references() in media.py for media content fetching timeout.
    • Update fetch_media() in client.py to handle exceptions using handle_fern_exception().
  • Classes:
    • Add FetchMediaResponse dataclass in client.py for fetch_media() method response.
  • Logging:
    • Change logging from logging.warning to LangfuseMedia._log.warning in media.py for consistency.

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

@hassiebp hassiebp enabled auto-merge (squash) December 11, 2024 21:26
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.

Disclaimer: Experimental PR review

PR Summary

This PR adds timeout functionality and improves media handling in the Langfuse Python client, focusing on better error handling and type safety.

  • Added new FetchMediaResponse dataclass in /langfuse/client.py to properly type and structure media response data
  • Implemented timeout parameter content_fetch_timeout_seconds in /langfuse/media.py to prevent hanging on slow media fetches
  • Enhanced error handling in fetch_media method with proper try/catch blocks and logging
  • Improved type hints and docstring documentation for media-related methods
  • Switched to using class logger instead of root logger for better logging organization

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

Comment on lines +280 to 282
media_content = requests.get(
media_data.url, timeout=content_fetch_timeout_seconds
)
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: timeout only applies to the GET request, but not to the fetch_media call which could also hang. Consider wrapping both operations in a timeout

@hassiebp hassiebp disabled auto-merge December 11, 2024 21:34
@hassiebp
Copy link
Contributor Author

todo: add link to main client

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.

Disclaimer: Experimental PR review

PR Summary

(updates since last review)

This PR continues to enhance the media handling functionality in the Langfuse Python client. Here's a concise summary of the latest changes:

  • Added content_fetch_timeout_seconds parameter (default 10s) to resolve_media_references() in client.py to prevent indefinite hangs
  • Moved media resolution functionality from LangfuseMedia class to Langfuse client for better organization
  • Improved error handling in fetch_media() using handle_fern_exception() for consistent error management
  • Updated test file to reflect the architectural changes in media resolution

The changes appear focused on improving reliability and maintainability of the media handling components.

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

@hassiebp hassiebp merged commit e7189a0 into main Dec 11, 2024
9 of 10 checks passed
@hassiebp hassiebp deleted the add-timeout-media-resolution branch December 11, 2024 22:55
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.

2 participants