mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-23 10:26:09 +00:00
Revert "Fix: Langfuse reporting "client closed" error due to httpx client TTL…" (#13291)
This reverts commit 1c6be9bdad.
This commit is contained in:
@@ -12,10 +12,6 @@ from litellm.litellm_core_utils.litellm_logging import StandardCallbackDynamicPa
|
||||
|
||||
from .langfuse import LangFuseLogger, LangfuseLoggingConfig
|
||||
|
||||
from httpx._client import ClientState
|
||||
|
||||
from litellm._logging import verbose_logger
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from litellm.litellm_core_utils.litellm_logging import DynamicLoggingCache
|
||||
else:
|
||||
@@ -64,17 +60,7 @@ class LangFuseHandler:
|
||||
)
|
||||
|
||||
# if not cached, create a new langfuse logger and cache it
|
||||
if temp_langfuse_logger is None or not LangFuseHandler._logger_httpx_client_is_unclosed(temp_langfuse_logger):
|
||||
# if the cached logger is closed, remove it from cache
|
||||
if temp_langfuse_logger is not None:
|
||||
key = in_memory_dynamic_logger_cache.get_cache_key(
|
||||
args={**credentials_dict, "service_name": "langfuse"}
|
||||
)
|
||||
in_memory_dynamic_logger_cache.cache._remove_key(key)
|
||||
verbose_logger.warning(
|
||||
"LangFuseLogger was found in cache but it was closed. Removing it from cache and creating a new one."
|
||||
)
|
||||
|
||||
if temp_langfuse_logger is None:
|
||||
temp_langfuse_logger = (
|
||||
LangFuseHandler._create_langfuse_logger_from_credentials(
|
||||
credentials=credentials_dict,
|
||||
@@ -97,7 +83,7 @@ class LangFuseHandler:
|
||||
If no Global LangfuseLogger is set, it will check in_memory_dynamic_logger_cache for a cached LangFuseLogger
|
||||
This function is used to return the globalLangfuseLogger if it exists, otherwise it will check in_memory_dynamic_logger_cache for a cached LangFuseLogger
|
||||
"""
|
||||
if globalLangfuseLogger is not None and LangFuseHandler._logger_httpx_client_is_unclosed(globalLangfuseLogger):
|
||||
if globalLangfuseLogger is not None:
|
||||
return globalLangfuseLogger
|
||||
|
||||
credentials_dict: Dict[
|
||||
@@ -109,17 +95,7 @@ class LangFuseHandler:
|
||||
credentials=credentials_dict,
|
||||
service_name="langfuse",
|
||||
)
|
||||
if globalLangfuseLogger is None or not LangFuseHandler._logger_httpx_client_is_unclosed(globalLangfuseLogger):
|
||||
# if the cached logger is closed, remove it from cache
|
||||
if globalLangfuseLogger is not None:
|
||||
key = in_memory_dynamic_logger_cache.get_cache_key(
|
||||
args={**credentials_dict, "service_name": "langfuse"}
|
||||
)
|
||||
in_memory_dynamic_logger_cache.cache._remove_key(key)
|
||||
verbose_logger.warning(
|
||||
"LangFuseLogger was found in cache but it was closed. Removing it from cache and creating a new one."
|
||||
)
|
||||
|
||||
if globalLangfuseLogger is None:
|
||||
globalLangfuseLogger = (
|
||||
LangFuseHandler._create_langfuse_logger_from_credentials(
|
||||
credentials=credentials_dict,
|
||||
@@ -192,21 +168,3 @@ class LangFuseHandler:
|
||||
):
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _logger_httpx_client_is_unclosed(
|
||||
logger: LangFuseLogger,
|
||||
) -> bool:
|
||||
"""
|
||||
This function checks if the httpx client used by the logger is not closed.
|
||||
|
||||
Args:
|
||||
logger (LangFuseLogger): The LangFuseLogger instance to check.
|
||||
|
||||
Returns:
|
||||
bool: True if the httpx client is not closed, False otherwise.
|
||||
"""
|
||||
verbose_logger.debug(f"LangFuseLogger's httpx client state: {logger.Langfuse.httpx_client._state}")
|
||||
if logger is not None and logger.Langfuse.httpx_client._state != ClientState.CLOSED:
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user