fix(lint): remove duplicate test import, LIT002 dict literal, and mock-echo otel test

- drop redundant in-function import of callback_config_error (F811)
- avoid the `or {}` mutable literal in _set_langfuse_specific_attributes (LIT002)
- rewrite the dynamic-env otel test to observe span.set_attribute output
  instead of patching litellm internals (TQ002/TQ008)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Yucheng Zhu 2026-08-26 12:38:58 -07:00
parent 3ff87e8157
commit 6ce403ccbe
3 changed files with 17 additions and 18 deletions

View file

@ -226,10 +226,10 @@ class LangfuseOtelLogger(OpenTelemetry):
from litellm.integrations.arize._utils import safe_set_attribute
from litellm.litellm_core_utils.safe_json_dumps import safe_dumps
dynamic_params: Final = kwargs.get("standard_callback_dynamic_params") or {}
langfuse_environment: Final = dynamic_params.get("langfuse_environment") or os.environ.get(
"LANGFUSE_TRACING_ENVIRONMENT"
)
dynamic_params: Final = kwargs.get("standard_callback_dynamic_params")
langfuse_environment: Final = (
dynamic_params.get("langfuse_environment") if dynamic_params else None
) or os.environ.get("LANGFUSE_TRACING_ENVIRONMENT")
if langfuse_environment:
safe_set_attribute(
span,

View file

@ -139,7 +139,15 @@ class TestLangfuseOtelIntegration:
def test_set_langfuse_environment_attribute_prefers_dynamic_param(self):
"""Per-key/team langfuse_environment beats the deployment env var."""
mock_span = MagicMock()
class _RecordingSpan:
def __init__(self):
self.attributes = {}
def set_attribute(self, key, value):
self.attributes[key] = value
span = _RecordingSpan()
mock_kwargs = {
"standard_callback_dynamic_params": {
"langfuse_environment": "team-a-env"
@ -149,16 +157,11 @@ class TestLangfuseOtelIntegration:
with patch.dict(
os.environ, {"LANGFUSE_TRACING_ENVIRONMENT": "deployment-wide"}
):
with patch(
"litellm.integrations.arize._utils.safe_set_attribute"
) as mock_safe_set_attribute:
LangfuseOtelLogger._set_langfuse_specific_attributes(
mock_span, mock_kwargs, {}
)
LangfuseOtelLogger._set_langfuse_specific_attributes(
span, mock_kwargs, {}
)
mock_safe_set_attribute.assert_called_once_with(
mock_span, "langfuse.environment", "team-a-env"
)
assert span.attributes["langfuse.environment"] == "team-a-env"
def test_extract_langfuse_metadata_basic(self):
"""Ensure metadata is correctly pulled from litellm_params."""

View file

@ -4,10 +4,6 @@ from litellm.proxy.common_utils.callback_config_validation import (
def test_callback_config_error_rejects_invalid_langfuse_environment():
from litellm.proxy.common_utils.callback_config_validation import (
callback_config_error,
)
for callback in ["langfuse", "langfuse_otel"]:
error = callback_config_error(callback, {"langfuse_environment": "Production"})
assert error is not None and "langfuse_environment" in error