forked from phoenix/litellm-mirror
(fix) Langfuse key based logging (#6372)
* langfuse use helper for get_langfuse_logging_config * fix get_langfuse_logger_for_request * fix import * fix get_langfuse_logger_for_request * test_get_langfuse_logger_for_request_with_dynamic_params * unit testing for test_get_langfuse_logger_for_request_with_no_dynamic_params * parameterized langfuse testing * fix langfuse test * fix langfuse logging * fix test_aaalangfuse_logging_metadata * fix langfuse log metadata test * fix langfuse logger * use create_langfuse_logger_from_credentials * fix test_get_langfuse_logger_for_request_with_no_dynamic_params * fix correct langfuse/ folder structure * use static methods for langfuse logger * add commment on langfuse handler * fix linting error * add unit testing for langfuse logging * fix linting * fix failure handler langfuse
This commit is contained in:
parent
b70147f63b
commit
72a91ea9dd
7 changed files with 426 additions and 210 deletions
|
@ -70,7 +70,8 @@ from ..integrations.gcs_bucket.gcs_bucket import GCSBucketLogger
|
|||
from ..integrations.greenscale import GreenscaleLogger
|
||||
from ..integrations.helicone import HeliconeLogger
|
||||
from ..integrations.lago import LagoLogger
|
||||
from ..integrations.langfuse import LangFuseLogger
|
||||
from ..integrations.langfuse.langfuse import LangFuseLogger
|
||||
from ..integrations.langfuse.langfuse_handler import LangFuseHandler
|
||||
from ..integrations.langsmith import LangsmithLogger
|
||||
from ..integrations.litedebugger import LiteDebugger
|
||||
from ..integrations.literal_ai import LiteralAILogger
|
||||
|
@ -1116,74 +1117,13 @@ class Logging:
|
|||
print_verbose("reaches langfuse for streaming logging!")
|
||||
result = kwargs["complete_streaming_response"]
|
||||
|
||||
temp_langfuse_logger = langFuseLogger
|
||||
if langFuseLogger is None or (
|
||||
(
|
||||
self.standard_callback_dynamic_params.get(
|
||||
"langfuse_public_key"
|
||||
)
|
||||
is not None
|
||||
and self.standard_callback_dynamic_params.get(
|
||||
"langfuse_public_key"
|
||||
)
|
||||
!= langFuseLogger.public_key
|
||||
)
|
||||
or (
|
||||
self.standard_callback_dynamic_params.get(
|
||||
"langfuse_secret"
|
||||
)
|
||||
is not None
|
||||
and self.standard_callback_dynamic_params.get(
|
||||
"langfuse_secret"
|
||||
)
|
||||
!= langFuseLogger.secret_key
|
||||
)
|
||||
or (
|
||||
self.standard_callback_dynamic_params.get(
|
||||
"langfuse_host"
|
||||
)
|
||||
is not None
|
||||
and self.standard_callback_dynamic_params.get(
|
||||
"langfuse_host"
|
||||
)
|
||||
!= langFuseLogger.langfuse_host
|
||||
)
|
||||
):
|
||||
credentials = {
|
||||
"langfuse_public_key": self.standard_callback_dynamic_params.get(
|
||||
"langfuse_public_key"
|
||||
),
|
||||
"langfuse_secret": self.standard_callback_dynamic_params.get(
|
||||
"langfuse_secret"
|
||||
),
|
||||
"langfuse_host": self.standard_callback_dynamic_params.get(
|
||||
"langfuse_host"
|
||||
),
|
||||
}
|
||||
temp_langfuse_logger = (
|
||||
in_memory_dynamic_logger_cache.get_cache(
|
||||
credentials=credentials, service_name="langfuse"
|
||||
)
|
||||
)
|
||||
if temp_langfuse_logger is None:
|
||||
temp_langfuse_logger = LangFuseLogger(
|
||||
langfuse_public_key=self.standard_callback_dynamic_params.get(
|
||||
"langfuse_public_key"
|
||||
),
|
||||
langfuse_secret=self.standard_callback_dynamic_params.get(
|
||||
"langfuse_secret"
|
||||
),
|
||||
langfuse_host=self.standard_callback_dynamic_params.get(
|
||||
"langfuse_host"
|
||||
),
|
||||
)
|
||||
in_memory_dynamic_logger_cache.set_cache(
|
||||
credentials=credentials,
|
||||
service_name="langfuse",
|
||||
logging_obj=temp_langfuse_logger,
|
||||
)
|
||||
if temp_langfuse_logger is not None:
|
||||
_response = temp_langfuse_logger.log_event(
|
||||
langfuse_logger_to_use = LangFuseHandler.get_langfuse_logger_for_request(
|
||||
globalLangfuseLogger=langFuseLogger,
|
||||
standard_callback_dynamic_params=self.standard_callback_dynamic_params,
|
||||
in_memory_dynamic_logger_cache=in_memory_dynamic_logger_cache,
|
||||
)
|
||||
if langfuse_logger_to_use is not None:
|
||||
_response = langfuse_logger_to_use.log_event(
|
||||
kwargs=kwargs,
|
||||
response_obj=result,
|
||||
start_time=start_time,
|
||||
|
@ -1909,50 +1849,12 @@ class Logging:
|
|||
): # copy.deepcopy raises errors as this could be a coroutine
|
||||
kwargs[k] = v
|
||||
# this only logs streaming once, complete_streaming_response exists i.e when stream ends
|
||||
if langFuseLogger is None or (
|
||||
(
|
||||
self.standard_callback_dynamic_params.get(
|
||||
"langfuse_public_key"
|
||||
)
|
||||
is not None
|
||||
and self.standard_callback_dynamic_params.get(
|
||||
"langfuse_public_key"
|
||||
)
|
||||
!= langFuseLogger.public_key
|
||||
)
|
||||
or (
|
||||
self.standard_callback_dynamic_params.get(
|
||||
"langfuse_public_key"
|
||||
)
|
||||
is not None
|
||||
and self.standard_callback_dynamic_params.get(
|
||||
"langfuse_public_key"
|
||||
)
|
||||
!= langFuseLogger.public_key
|
||||
)
|
||||
or (
|
||||
self.standard_callback_dynamic_params.get(
|
||||
"langfuse_host"
|
||||
)
|
||||
is not None
|
||||
and self.standard_callback_dynamic_params.get(
|
||||
"langfuse_host"
|
||||
)
|
||||
!= langFuseLogger.langfuse_host
|
||||
)
|
||||
):
|
||||
langFuseLogger = LangFuseLogger(
|
||||
langfuse_public_key=self.standard_callback_dynamic_params.get(
|
||||
"langfuse_public_key"
|
||||
),
|
||||
langfuse_secret=self.standard_callback_dynamic_params.get(
|
||||
"langfuse_secret"
|
||||
),
|
||||
langfuse_host=self.standard_callback_dynamic_params.get(
|
||||
"langfuse_host"
|
||||
),
|
||||
)
|
||||
_response = langFuseLogger.log_event(
|
||||
langfuse_logger_to_use = LangFuseHandler.get_langfuse_logger_for_request(
|
||||
globalLangfuseLogger=langFuseLogger,
|
||||
standard_callback_dynamic_params=self.standard_callback_dynamic_params,
|
||||
in_memory_dynamic_logger_cache=in_memory_dynamic_logger_cache,
|
||||
)
|
||||
_response = langfuse_logger_to_use.log_event(
|
||||
start_time=start_time,
|
||||
end_time=end_time,
|
||||
response_obj=None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue