Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions litellm/integrations/langfuse/langfuse_otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ def _set_observation_output(span: Span, response_obj):
"type": "function_call",
"arguments": arguments_obj,
}
if (namespace := getattr(item, "namespace", None)) is not None:
langfuse_tool_call["namespace"] = namespace

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Dictionary update breaks coding rules

The new assignment mutates langfuse_tool_call, violating CLAUDE.md’s no-mutation directive for updated code. Build the optional field inside the dictionary expression before merging

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

output_items_data.append(langfuse_tool_call)
if output_items_data:
safe_set_attribute(
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/integrations/test_langfuse_otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,8 @@ def test_responses_api_with_output(self):
== "The weather in San Francisco is sunny, 20°C."
)

def test_responses_api_with_function_calls(self):
@pytest.mark.parametrize("namespace", (None, "weather", ""))
def test_responses_api_with_function_calls(self, namespace: str | None):
"""Test Langfuse OTEL logger with Responses API function_call output."""
from litellm.types.integrations.langfuse_otel import LangfuseSpanAttributes
from openai.types.responses import ResponseFunctionToolCall
Expand All @@ -911,6 +912,7 @@ def test_responses_api_with_function_calls(self):
id="fc-123",
type="function_call",
name="get_weather",
namespace=namespace,
call_id="call-abc",
arguments='{"location": "San Francisco", "unit": "celsius"}',
status="completed",
Expand Down Expand Up @@ -958,6 +960,10 @@ def test_responses_api_with_function_calls(self):
assert output_data[0]["call_id"] == "call-abc"
assert output_data[0]["arguments"]["location"] == "San Francisco"
assert output_data[0]["arguments"]["unit"] == "celsius"
if namespace is None:
assert "namespace" not in output_data[0]
else:
assert output_data[0]["namespace"] == namespace

def test_responses_api_function_call_with_redacted_arguments(self):
"""Sentinel arguments (invalid JSON) must not kill the whole observation output."""
Expand Down
Loading