This commit is contained in:
Devaanga Prakash 2026-08-26 00:35:06 -06:00 committed by GitHub
commit 48df116a10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 0 deletions

View file

@ -174,6 +174,13 @@ class LangfuseOtelLogger(OpenTelemetry):
safe_dumps(output_data),
)
results: Final = response_obj.get("results", [])
if results:
safe_set_attribute(
span,
LangfuseSpanAttributes.OBSERVATION_OUTPUT.value,
safe_dumps(results),
)
output: Final = response_obj.get("output", [])
if output:
output_items_data: Final[list[dict]] = []

View file

@ -336,6 +336,33 @@ class TestLangfuseOtelIntegration:
actual == expect_output
), "Mismatch in observation input/output OTEL attributes."
def test_set_langfuse_specific_attributes_with_rerank_results(self):
from litellm.types.integrations.langfuse_otel import LangfuseSpanAttributes
from litellm.types.rerank import RerankResponse
response_obj = RerankResponse(
id="rerank-test",
results=[
{"index": 2, "relevance_score": 0.98},
{"index": 0, "relevance_score": 0.41},
],
)
with patch(
"litellm.integrations.arize._utils.safe_set_attribute"
) as mock_safe_set_attribute:
LangfuseOtelLogger._set_langfuse_specific_attributes(
MagicMock(), {}, response_obj
)
output_calls = [
call
for call in mock_safe_set_attribute.call_args_list
if call.args[1] == LangfuseSpanAttributes.OBSERVATION_OUTPUT.value
]
assert len(output_calls) == 1
assert json.loads(output_calls[0].args[2]) == response_obj.results
def test_set_langfuse_specific_attributes_with_tool_calls(self):
"""Test that _set_langfuse_specific_attributes correctly sets observation.output with tool calls in Langfuse format."""
from litellm.types.integrations.langfuse_otel import LangfuseSpanAttributes