Skip to content
Merged
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
12 changes: 11 additions & 1 deletion tests/models/test_fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
from collections.abc import AsyncIterator
from datetime import timezone
from typing import Any

import pytest
from inline_snapshot import snapshot
Expand Down Expand Up @@ -247,6 +248,14 @@ def test_all_failed() -> None:
assert exceptions[0].body == {'error': 'test error'}


def add_missing_response_model(spans: list[dict[str, Any]]) -> list[dict[str, Any]]:
for span in spans:
attrs = span.setdefault('attributes', {})
if 'gen_ai.request.model' in attrs:
attrs.setdefault('gen_ai.response.model', attrs['gen_ai.request.model'])
return spans


@pytest.mark.skipif(not logfire_imports_successful(), reason='logfire not installed')
def test_all_failed_instrumented(capfire: CaptureLogfire) -> None:
fallback_model = FallbackModel(failure_model, failure_model)
Expand All @@ -260,7 +269,7 @@ def test_all_failed_instrumented(capfire: CaptureLogfire) -> None:
assert exceptions[0].status_code == 500
assert exceptions[0].model_name == 'test-function-model'
assert exceptions[0].body == {'error': 'test error'}
assert capfire.exporter.exported_spans_as_dict() == snapshot(
assert add_missing_response_model(capfire.exporter.exported_spans_as_dict()) == snapshot(
[
{
'name': 'chat fallback:function:failure_response:,function:failure_response:',
Expand All @@ -277,6 +286,7 @@ def test_all_failed_instrumented(capfire: CaptureLogfire) -> None:
'logfire.span_type': 'span',
'logfire.msg': 'chat fallback:function:failure_response:,function:failure_response:',
'logfire.level_num': 17,
'gen_ai.response.model': 'fallback:function:failure_response:,function:failure_response:',
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is easy to account for in other ways, this is not enough reason to restrict the version of logfire.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexmojaki The tests won't succeed when using logfire<3.22. If you think that restricting Logfire version isn't good reason for this PR, I will close it.

Copy link
Contributor

Choose a reason for hiding this comment

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

These tests won't pass as they are. You can make them pass.

It's good to test the newest version of logfire, this PR is a good idea, but the minimum version doesn't need to be raised.

},
'events': [
{
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.