The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
[Feat] Bump langfuse python SDK version and `LANGFUSE_TRACING_ENVIRONMENT` (#12376)
Ishaan Jaff08f3b06d82d2
diff --git a/.circleci/config.yml b/.circleci/config.ymlindex 92a26af32fc..413415ae8a5 100644--- a/.circleci/config.yml+++ b/.circleci/config.yml@@ -88,7 +88,7 @@ jobs:pip install langchainpip install lunary==0.2.5pip install "azure-identity==1.16.1"- pip install "langfuse==2.45.0"+ pip install "langfuse==2.59.7"pip install "logfire==0.29.0"pip install numpydocpip install traceloop-sdk==0.21.1@@ -211,7 +211,7 @@ jobs:pip install langchainpip install lunary==0.2.5pip install "azure-identity==1.16.1"- pip install "langfuse==2.45.0"+ pip install "langfuse==2.59.7"pip install "logfire==0.29.0"pip install numpydocpip install traceloop-sdk==0.21.1@@ -318,7 +318,7 @@ jobs:pip install langchainpip install lunary==0.2.5pip install "azure-identity==1.16.1"- pip install "langfuse==2.45.0"+ pip install "langfuse==2.59.7"pip install "logfire==0.29.0"pip install numpydocpip install traceloop-sdk==0.21.1@@ -591,7 +591,7 @@ jobs:pip install langchainpip install lunary==0.2.5pip install "azure-identity==1.16.1"- pip install "langfuse==2.45.0"+ pip install "langfuse==2.59.7"pip install "logfire==0.29.0"pip install numpydocpip install traceloop-sdk==0.21.1diff --git a/docs/my-website/docs/observability/langfuse_integration.md b/docs/my-website/docs/observability/langfuse_integration.mdindex b6d8c836520..c1cf6165b34 100644--- a/docs/my-website/docs/observability/langfuse_integration.md+++ b/docs/my-website/docs/observability/langfuse_integration.md@@ -28,7 +28,7 @@ For Langfuse v3, we recommend using the [Langfuse OTEL](./langfuse_otel_integrat### Pre-RequisitesEnsure you have run `pip install langfuse` for this integration```shell-pip install langfuse==2.45.0 litellm+pip install langfuse==2.59.7 litellm```### Quick Startdiff --git a/litellm/integrations/langfuse/langfuse_otel.py b/litellm/integrations/langfuse/langfuse_otel.pyindex 7fc222ff6c6..f257da6d95e 100644--- a/litellm/integrations/langfuse/langfuse_otel.py+++ b/litellm/integrations/langfuse/langfuse_otel.py@@ -5,7 +5,10 @@ from urllib.parse import quotefrom litellm._logging import verbose_loggerfrom litellm.integrations.arize import _utils-from litellm.types.integrations.langfuse_otel import LangfuseOtelConfig+from litellm.types.integrations.langfuse_otel import (+ LangfuseOtelConfig,+ LangfuseSpanAttributes,+)if TYPE_CHECKING:from opentelemetry.trace import Span as _Span@@ -28,6 +31,7 @@ LANGFUSE_CLOUD_EU_ENDPOINT = "https://cloud.langfuse.com/api/public/otel"LANGFUSE_CLOUD_US_ENDPOINT = "https://us.cloud.langfuse.com/api/public/otel"+class LangfuseOtelLogger:@staticmethoddef set_langfuse_otel_attributes(span: Span, kwargs, response_obj):@@ -36,7 +40,29 @@ class LangfuseOtelLogger:Uses the same attribute setting logic as Arize Phoenix for consistency."""_utils.set_attributes(span, kwargs, response_obj)++ #########################################################+ # Set Langfuse specific attributes eg Langfuse Environment+ #########################################################+ LangfuseOtelLogger._set_langfuse_specific_attributes(+ span=span,+ kwargs=kwargs+ )return++ @staticmethod+ def _set_langfuse_specific_attributes(span: Span, kwargs):+ """+ Sets Langfuse specific attributes to the span.+ """+ from litellm.integrations.arize._utils import safe_set_attribute+ langfuse_environment = os.environ.get("LANGFUSE_TRACING_ENVIRONMENT", None)+ if langfuse_environment:+ safe_set_attribute(+ span=span,+ key=LangfuseSpanAttributes.LANGFUSE_ENVIRONMENT.value,+ value=langfuse_environment+ )@staticmethoddef get_langfuse_otel_config() -> LangfuseOtelConfig:diff --git a/litellm/types/integrations/langfuse_otel.py b/litellm/types/integrations/langfuse_otel.pyindex 389b0135017..d4b61304546 100644--- a/litellm/types/integrations/langfuse_otel.py+++ b/litellm/types/integrations/langfuse_otel.py@@ -1,4 +1,5 @@-from typing import TYPE_CHECKING, Literal, Optional, Any+from enum import Enum+from typing import TYPE_CHECKING, Any, Literal, Optionalfrom pydantic import BaseModel@@ -10,4 +11,7 @@ else:class LangfuseOtelConfig(BaseModel):otlp_auth_headers: Optional[str] = None- protocol: Protocol = "otlp_http"\ No newline at end of file+ protocol: Protocol = "otlp_http"++class LangfuseSpanAttributes(Enum):+ LANGFUSE_ENVIRONMENT = "langfuse.environment"\ No newline at end of filediff --git a/requirements.txt b/requirements.txtindex 391c627a95c..df8d9c4242d 100644--- a/requirements.txt+++ b/requirements.txt@@ -19,7 +19,7 @@ anthropic[vertex]==0.54.0mcp==1.9.3 # for MCP servergoogle-generativeai==0.5.0 # for vertex ai callsasync_generator==1.10.0 # for async ollama calls-langfuse==2.45.0 # for langfuse self-hosted logging+langfuse==2.59.7 # for langfuse self-hosted loggingprometheus_client==0.20.0 # for /metrics endpoint on proxyddtrace==2.19.0 # for advanced DD tracing / profilingorjson==3.10.12 # fast /embedding responsesdiff --git a/tests/test_litellm/integrations/test_langfuse_otel.py b/tests/test_litellm/integrations/test_langfuse_otel.pyindex 97125529169..cf33299f62e 100644--- a/tests/test_litellm/integrations/test_langfuse_otel.py+++ b/tests/test_litellm/integrations/test_langfuse_otel.py@@ -81,6 +81,22 @@ class TestLangfuseOtelIntegration:mock_set_attributes.assert_called_once_with(mock_span, mock_kwargs, mock_response)+ def test_set_langfuse_environment_attribute(self):+ """Test that Langfuse environment is set correctly when environment variable is present."""+ mock_span = MagicMock()+ mock_kwargs = {"test": "kwargs"}+ test_env = "staging"++ with patch.dict(os.environ, {'LANGFUSE_TRACING_ENVIRONMENT': test_env}):+ with patch('litellm.integrations.arize._utils.safe_set_attribute') as mock_safe_set_attribute:+ LangfuseOtelLogger._set_langfuse_specific_attributes(mock_span, mock_kwargs)++ mock_safe_set_attribute.assert_called_once_with(+ span=mock_span,+ key="langfuse.environment",+ value=test_env+ )+if __name__ == "__main__":pytest.main([__file__])\ No newline at end of file