From 5b2ba06b6da50ca80026ef9efac72d0ff9482cc9 Mon Sep 17 00:00:00 2001 From: Alexsander Hamir Date: Fri, 23 Jan 2026 14:57:43 -0800 Subject: [PATCH] Reduce excessive comments in Langfuse mock client --- litellm/integrations/langfuse/langfuse.py | 4 ---- .../integrations/langfuse/langfuse_mock_client.py | 12 ------------ 2 files changed, 16 deletions(-) diff --git a/litellm/integrations/langfuse/langfuse.py b/litellm/integrations/langfuse/langfuse.py index 532993655ae..46ada3c3930 100644 --- a/litellm/integrations/langfuse/langfuse.py +++ b/litellm/integrations/langfuse/langfuse.py @@ -124,13 +124,10 @@ class LangFuseLogger: flush_interval ) - # Check if we should use mock mode if should_use_langfuse_mock(): - # Use mock client - exercises all code without network calls self.langfuse_client = create_mock_langfuse_client() self.is_mock_mode = True else: - # Use real httpx client http_client = _get_httpx_client() self.langfuse_client = http_client.client self.is_mock_mode = False @@ -153,7 +150,6 @@ class LangFuseLogger: # set the current langfuse project id in the environ # this is used by Alerting to link to the correct project if self.is_mock_mode: - # In mock mode, use a fake project ID os.environ["LANGFUSE_PROJECT_ID"] = "mock-project-id" verbose_logger.debug("Langfuse Mock: Using mock project ID") else: diff --git a/litellm/integrations/langfuse/langfuse_mock_client.py b/litellm/integrations/langfuse/langfuse_mock_client.py index 4281c0cb3cf..3633dee55a4 100644 --- a/litellm/integrations/langfuse/langfuse_mock_client.py +++ b/litellm/integrations/langfuse/langfuse_mock_client.py @@ -14,7 +14,6 @@ from typing import Dict, Optional from litellm._logging import verbose_logger -# Store original post method for restoration _original_httpx_post = None @@ -35,38 +34,30 @@ class MockLangfuseResponse: @property def text(self) -> str: - """Return response text.""" return self._text @property def content(self) -> bytes: - """Return response content.""" return self._content def json(self) -> Dict: - """Return JSON response data.""" return self._json_data def read(self) -> bytes: - """Read response content.""" return self._content def raise_for_status(self): - """Raise exception for error status codes.""" if self.status_code >= 400: raise Exception(f"HTTP {self.status_code}") def _mock_httpx_post(self, url, **kwargs): """Monkey-patched httpx.Client.post that intercepts Langfuse calls.""" - # Only mock Langfuse API calls if isinstance(url, str) and ("langfuse.com" in url or "langfuse" in url.lower()): print(f"[LANGFUSE MOCK] POST to {url}") return MockLangfuseResponse(status_code=200, json_data={"status": "success"}, url=url) - # For non-Langfuse calls, use original method if _original_httpx_post is not None: return _original_httpx_post(self, url, **kwargs) - # Fallback: if original not set, create a temporary client for this call import httpx with httpx.Client() as client: return client.post(url, **kwargs) @@ -85,7 +76,6 @@ def create_mock_langfuse_client(): httpx.Client.post = _mock_httpx_post # type: ignore print("[LANGFUSE MOCK] Patched httpx.Client.post") - # Return real client - monkey-patch handles interception return httpx.Client() @@ -103,8 +93,6 @@ def should_use_langfuse_mock() -> bool: mock_mode = os.getenv("LANGFUSE_MOCK", "false") result = str_to_bool(mock_mode) - - # Ensure we return a bool, not None result = bool(result) if result is not None else False if result: