diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py index 59ea1d02d..eae8b8e22 100644 --- a/litellm/integrations/langfuse.py +++ b/litellm/integrations/langfuse.py @@ -13,7 +13,11 @@ from litellm._logging import verbose_logger class LangFuseLogger: # Class variables or attributes def __init__( - self, langfuse_public_key=None, langfuse_secret=None, flush_interval=1 + self, + langfuse_public_key=None, + langfuse_secret=None, + langfuse_host=None, + flush_interval=1, ): try: import langfuse @@ -25,7 +29,9 @@ class LangFuseLogger: # Instance variables self.secret_key = langfuse_secret or os.getenv("LANGFUSE_SECRET_KEY") self.public_key = langfuse_public_key or os.getenv("LANGFUSE_PUBLIC_KEY") - self.langfuse_host = os.getenv("LANGFUSE_HOST", "https://cloud.langfuse.com") + self.langfuse_host = langfuse_host or os.getenv( + "LANGFUSE_HOST", "https://cloud.langfuse.com" + ) self.langfuse_release = os.getenv("LANGFUSE_RELEASE") self.langfuse_debug = os.getenv("LANGFUSE_DEBUG") diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index 97994ad28..b7381b286 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -75,6 +75,44 @@ from ..integrations.weights_biases import WeightsBiasesLogger _in_memory_loggers: List[Any] = [] +### GLOBAL VARIABLES ### + +sentry_sdk_instance = None +capture_exception = None +add_breadcrumb = None +posthog = None +slack_app = None +alerts_channel = None +heliconeLogger = None +athinaLogger = None +promptLayerLogger = None +langsmithLogger = None +logfireLogger = None +weightsBiasesLogger = None +customLogger = None +langFuseLogger = None +openMeterLogger = None +lagoLogger = None +dataDogLogger = None +prometheusLogger = None +dynamoLogger = None +s3Logger = None +genericAPILogger = None +clickHouseLogger = None +greenscaleLogger = None +lunaryLogger = None +aispendLogger = None +berrispendLogger = None +supabaseClient = None +liteDebuggerClient = None +callback_list: Optional[List[str]] = [] +user_logger_fn = None +additional_details: Optional[Dict[str, str]] = {} +local_cache: Optional[Dict[str, str]] = {} +last_fetched_at = None +last_fetched_at_keys = None +#### + class Logging: global supabaseClient, liteDebuggerClient, promptLayerLogger, weightsBiasesLogger, langsmithLogger, logfireLogger, capture_exception, add_breadcrumb, lunaryLogger, logfireLogger, prometheusLogger, slack_app @@ -95,6 +133,7 @@ class Logging: dynamic_async_success_callbacks=None, langfuse_public_key=None, langfuse_secret=None, + langfuse_host=None, ): if call_type not in [item.value for item in CallTypes]: allowed_values = ", ".join([item.value for item in CallTypes]) @@ -136,6 +175,7 @@ class Logging: ## DYNAMIC LANGFUSE KEYS ## self.langfuse_public_key = langfuse_public_key self.langfuse_secret = langfuse_secret + self.langfuse_host = langfuse_host ## TIME TO FIRST TOKEN LOGGING ## self.completion_start_time: Optional[datetime.datetime] = None @@ -743,7 +783,7 @@ class Logging: ) if callback == "langfuse": global langFuseLogger - verbose_logger.debug("reaches langfuse for success logging!") + print_verbose("reaches langfuse for success logging!") kwargs = {} for k, v in self.model_call_details.items(): if ( @@ -775,6 +815,7 @@ class Logging: langFuseLogger = LangFuseLogger( langfuse_public_key=self.langfuse_public_key, langfuse_secret=self.langfuse_secret, + langfuse_host=self.langfuse_host, ) langFuseLogger.log_event( kwargs=kwargs, @@ -1556,6 +1597,7 @@ class Logging: langFuseLogger = LangFuseLogger( langfuse_public_key=self.langfuse_public_key, langfuse_secret=self.langfuse_secret, + langfuse_host=self.langfuse_host, ) langFuseLogger.log_event( start_time=start_time, diff --git a/litellm/proxy/_super_secret_config.yaml b/litellm/proxy/_super_secret_config.yaml index 77bd6ee96..d85cc771e 100644 --- a/litellm/proxy/_super_secret_config.yaml +++ b/litellm/proxy/_super_secret_config.yaml @@ -66,6 +66,18 @@ model_list: model_info: max_input_tokens: 80920 +litellm_settings: + default_team_settings: + - team_id: proj1 + success_callback: ["langfuse"] + langfuse_public_key: pk-lf-a65841e9-5192-4397-a679-cfff029fd5b0 + langfuse_secret: sk-lf-d58c2891-3717-4f98-89dd-df44826215fd + langfuse_host: https://us.cloud.langfuse.com + - team_id: proj2 + success_callback: ["langfuse"] + langfuse_public_key: pk-lf-3d789fd1-f49f-4e73-a7d9-1b4e11acbf9a + langfuse_secret: sk-lf-11b13aca-b0d4-4cde-9d54-721479dace6d + langfuse_host: https://us.cloud.langfuse.com assistant_settings: custom_llm_provider: openai diff --git a/litellm/tests/test_alangfuse.py b/litellm/tests/test_alangfuse.py index 449699335..705addf7f 100644 --- a/litellm/tests/test_alangfuse.py +++ b/litellm/tests/test_alangfuse.py @@ -866,3 +866,38 @@ async def test_make_request(): } }, ) + + +def test_langfuse_dynamic_logging(): + """ + pass in langfuse credentials via completion call + + assert call is logged. + + Covers the team-logging scenario. + """ + import uuid + + import langfuse + + trace_id = str(uuid.uuid4()) + _ = litellm.completion( + model="gpt-3.5-turbo", + messages=[{"role": "user", "content": "Hey"}], + mock_response="Hey! how's it going?", + langfuse_public_key=os.getenv("LANGFUSE_PROJECT2_PUBLIC"), + langfuse_secret_key=os.getenv("LANGFUSE_PROJECT2_SECRET"), + langfuse_host="https://us.cloud.langfuse.com", + metadata={"trace_id": trace_id}, + success_callback=["langfuse"], + ) + + time.sleep(1) + + langfuse_client = langfuse.Langfuse( + public_key=os.getenv("LANGFUSE_PROJECT2_PUBLIC"), + secret_key=os.getenv("LANGFUSE_PROJECT2_SECRET"), + host="https://us.cloud.langfuse.com", + ) + + langfuse_client.get_trace(id=trace_id) diff --git a/litellm/utils.py b/litellm/utils.py index 65896f0cd..2c63c2092 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -542,6 +542,7 @@ def function_setup( langfuse_public_key=kwargs.pop("langfuse_public_key", None), langfuse_secret=kwargs.pop("langfuse_secret", None) or kwargs.pop("langfuse_secret_key", None), + langfuse_host=kwargs.pop("langfuse_host", None), ) ## check if metadata is passed in litellm_params = {"api_base": ""}