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] `langfuse_otel` logger - allow using LANGFUSE_OTEL_HOST for configuring host (#14013)
Ishaan Jaff165242e31f32
diff --git a/docs/my-website/docs/observability/langfuse_otel_integration.md b/docs/my-website/docs/observability/langfuse_otel_integration.mdindex 4801fa8e1b0..b4c9a2bd1ad 100644--- a/docs/my-website/docs/observability/langfuse_otel_integration.md+++ b/docs/my-website/docs/observability/langfuse_otel_integration.md@@ -35,14 +35,14 @@ The Langfuse OpenTelemetry integration allows you to send LiteLLM traces and obs|----------|----------|-------------|---------|| `LANGFUSE_PUBLIC_KEY` | Yes | Your Langfuse public key | `pk-lf-...` || `LANGFUSE_SECRET_KEY` | Yes | Your Langfuse secret key | `sk-lf-...` |-| `LANGFUSE_HOST` | No | Langfuse host URL | `https://us.cloud.langfuse.com` (default) |+| `LANGFUSE_OTEL_HOST` | No | OTEL endpoint host | `https://otel.my-langfuse.com` |### Endpoint Resolution-The integration automatically constructs the OTEL endpoint from the `LANGFUSE_HOST`:+The integration automatically constructs the OTEL endpoint from `LANGFUSE_OTEL_HOST`- **Default (US)**: `https://us.cloud.langfuse.com/api/public/otel`- **EU Region**: `https://cloud.langfuse.com/api/public/otel`-- **Self-hosted**: `{LANGFUSE_HOST}/api/public/otel`+- **Self-hosted**: `{LANGFUSE_OTEL_HOST}/api/public/otel`## Usage@@ -77,11 +77,11 @@ os.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-..."os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-..."# Use EU region-os.environ["LANGFUSE_HOST"] = "https://cloud.langfuse.com" # EU region-# os.environ["LANGFUSE_HOST"] = "https://us.cloud.langfuse.com" # US region (default)+os.environ["LANGFUSE_OTEL_HOST"] = "https://cloud.langfuse.com" # EU region+# os.environ["LANGFUSE_OTEL_HOST"] = "https://otel.my-langfuse.company.com" # custom OTEL endpoint# Or use self-hosted instance-# os.environ["LANGFUSE_HOST"] = "https://my-langfuse.company.com"+# os.environ["LANGFUSE_OTEL_HOST"] = "https://my-langfuse.company.com"litellm.callbacks = ["langfuse_otel"]```@@ -98,14 +98,16 @@ import litellm# Get keys for your project from the project settings page: https://cloud.langfuse.comos.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-..."os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-..."-os.environ["LANGFUSE_HOST"] = "https://cloud.langfuse.com" # EU region-# os.environ["LANGFUSE_HOST"] = "https://us.cloud.langfuse.com" # US region+os.environ["LANGFUSE_OTEL_HOST"] = "https://cloud.langfuse.com" # EU region+# os.environ["LANGFUSE_OTEL_HOST"] = "https://us.cloud.langfuse.com" # US region+# os.environ["LANGFUSE_OTEL_HOST"] = "https://otel.my-langfuse.company.com" # custom OTEL endpointLANGFUSE_AUTH = base64.b64encode(f"{os.environ.get('LANGFUSE_PUBLIC_KEY')}:{os.environ.get('LANGFUSE_SECRET_KEY')}".encode()).decode()-os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = os.environ.get("LANGFUSE_HOST") + "/api/public/otel"+host = os.environ.get("LANGFUSE_OTEL_HOST")+os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = host + "/api/public/otel"os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"Authorization=Basic {LANGFUSE_AUTH}"litellm.callbacks = ["langfuse_otel"]@@ -120,7 +122,8 @@ Add the integration to your proxy configuration:```bashexport LANGFUSE_PUBLIC_KEY="pk-lf-..."export LANGFUSE_SECRET_KEY="sk-lf-..."-export LANGFUSE_HOST="https://us.cloud.langfuse.com" # Default US region+export LANGFUSE_OTEL_HOST="https://us.cloud.langfuse.com" # Default US region+# export LANGFUSE_OTEL_HOST="https://otel.my-langfuse.company.com" # custom OTEL endpoint```2. Setup config.yamldiff --git a/litellm/integrations/langfuse/langfuse_otel.py b/litellm/integrations/langfuse/langfuse_otel.pyindex 8b90e123371..fbe480be95f 100644--- a/litellm/integrations/langfuse/langfuse_otel.py+++ b/litellm/integrations/langfuse/langfuse_otel.py@@ -141,6 +141,17 @@ class LangfuseOtelLogger(OpenTelemetry):value = str(value)safe_set_attribute(span, enum_attr.value, value)+ @staticmethod+ def _get_langfuse_otel_host() -> Optional[str]:+ """+ Returns the Langfuse OTEL host based on environment variables.++ Returned in the following order of precedence:+ 1. LANGFUSE_OTEL_HOST+ 2. LANGFUSE_HOST+ """+ return os.environ.get("LANGFUSE_OTEL_HOST") or os.environ.get("LANGFUSE_HOST")+@staticmethoddef get_langfuse_otel_config() -> LangfuseOtelConfig:"""@@ -166,7 +177,7 @@ class LangfuseOtelLogger(OpenTelemetry):)# Determine endpoint - default to US cloud- langfuse_host = os.environ.get("LANGFUSE_HOST", None)+ langfuse_host = LangfuseOtelLogger._get_langfuse_otel_host()if langfuse_host:# If LANGFUSE_HOST is provided, construct OTEL endpoint from itdiff --git a/tests/test_litellm/integrations/test_langfuse_otel.py b/tests/test_litellm/integrations/test_langfuse_otel.pyindex 41b20c2a236..ceae019d344 100644--- a/tests/test_litellm/integrations/test_langfuse_otel.py+++ b/tests/test_litellm/integrations/test_langfuse_otel.py@@ -229,6 +229,19 @@ class TestLangfuseOtelIntegration:# Should return an empty dictassert result == {}++ def test_get_langfuse_otel_config_with_otel_host_priority(self):+ """LANGFUSE_OTEL_HOST should take priority over LANGFUSE_HOST."""+ with patch.dict(os.environ, {+ 'LANGFUSE_PUBLIC_KEY': 'test_public_key',+ 'LANGFUSE_SECRET_KEY': 'test_secret_key',+ 'LANGFUSE_HOST': 'https://should-not-be-used.com',+ 'LANGFUSE_OTEL_HOST': 'https://otel-host.com'+ }, clear=False):+ _ = LangfuseOtelLogger.get_langfuse_otel_config()++ assert os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT") == "https://otel-host.com/api/public/otel"+if __name__ == "__main__":