Reduce excessive comments in Langfuse mock client

This commit is contained in:
Alexsander Hamir 2026-01-23 14:57:43 -08:00
parent 9e5e8a8b28
commit 5b2ba06b6d
2 changed files with 0 additions and 16 deletions

View file

@ -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:

View file

@ -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: