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: 1 addition & 1 deletion langfuse/_client/span_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def is_genai_span(span: ReadableSpan) -> bool:
return False

return any(
isinstance(key, str) and key.startswith("gen_ai")
isinstance(key, str) and key.startswith("gen_ai.")
for key in span.attributes.keys()
)

Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_span_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ def test_is_genai_span_with_genai_attributes():
)


@pytest.mark.parametrize("predicate", [is_genai_span, is_default_export_span])
@pytest.mark.parametrize(
("attributes", "expected"),
[
({"gen_ai": "value"}, False),
({"gen_ai_custom": "value"}, False),
({"gen_ai-request.model": "value"}, False),
({"gen_airflow.model": "value"}, False),
({"custom.gen_ai.request.model": "value"}, False),
({b"gen_ai.request.model": "value"}, False),
({}, False),
({"gen_ai.request.model": "model"}, True),
({"gen_ai.usage.input_tokens": 0}, True),
({"gen_ai.custom": False}, True),
({"gen_ai_custom": "value", "gen_ai.request.model": "model"}, True),
],
)
def test_genai_filters_match_attribute_namespace(predicate, attributes, expected):
"""Match gen_ai.* attributes without accepting lookalike namespaces."""
span = _make_span(scope_name="unknown.scope", attributes=attributes)

assert predicate(span) is expected


def test_is_genai_span_ignores_non_string_keys():
"""Ignore non-string keys when checking gen_ai.* attributes."""
assert (
Expand Down