diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py index 38ab9c994b2..dcce6ff77a6 100644 --- a/litellm/integrations/langfuse.py +++ b/litellm/integrations/langfuse.py @@ -34,6 +34,14 @@ class LangFuseLogger: flush_interval=1, # flush interval in seconds ) + # set the current langfuse project id in the environ + # this is used by Alerting to link to the correct project + try: + project_id = self.Langfuse.client.projects.get().data[0].id + except: + project_id = None + os.environ["LANGFUSE_PROJECT_ID"] = project_id + if os.getenv("UPSTREAM_LANGFUSE_SECRET_KEY") is not None: self.upstream_langfuse_secret_key = os.getenv( "UPSTREAM_LANGFUSE_SECRET_KEY" diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index 4fc252c3316..c2bd0a4f00a 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -305,7 +305,14 @@ class ProxyLogging: _litellm_params["metadata"]["trace_id"] = trace_id _langfuse_host = os.environ.get("LANGFUSE_HOST", "https://cloud.langfuse.com") - request_info += f"\n🪢 Langfuse Trace: {_langfuse_host}/trace/{trace_id}" + _langfuse_project_id = os.environ.get("LANGFUSE_PROJECT_ID") + + # langfuse urls look like: https://us.cloud.langfuse.com/project/************/traces/litellm-alert-trace-ididi9dk-09292-************ + + _langfuse_url = ( + f"{_langfuse_host}/project/{_langfuse_project_id}/traces/{trace_id}" + ) + request_info += f"\n🪢 Langfuse Trace: {_langfuse_url}" return request_info async def response_taking_too_long(