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: 10 additions & 2 deletions tests/e2e/test_core_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1843,15 +1843,23 @@ def test_get_observations():


def test_get_observations_for_unknown_trace_is_empty():
response = get_api(retry=False).observations.get_many(trace_id=create_uuid())
# A lower bound within the server's first 7-day scan window makes one
# request cover the whole range, so the cursor is reliably absent.
response = get_api(retry=False).observations.get_many(
trace_id=create_uuid(),
from_start_time=datetime.now(timezone.utc) - timedelta(days=1),
)

assert response.data == []
assert response.meta.cursor is None


def test_get_observations_empty():
# Fetch observations with a filter that should return no results
response = get_api(retry=False).observations.get_many(name=create_uuid())
response = get_api(retry=False).observations.get_many(
name=create_uuid(),
from_start_time=datetime.now(timezone.utc) - timedelta(days=1),
)

assert response.data == []
assert response.meta.cursor is None
Expand Down
3 changes: 2 additions & 1 deletion tests/support/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ def get_observations(
)
observations.extend(response.data)
cursor = response.meta.cursor
if not cursor or not response.data:
# Pages can be short or empty before the end.
if not cursor:
break

# The events table can briefly return several rows for one span until
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/test_e2e_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ def test_user_metadata_drops_server_added_keys():
assert user_metadata(observation) == {"key": "value"}


def test_get_observations_follows_cursor_and_sorts_by_start_time(monkeypatch):
def test_get_observations_follows_cursor_past_empty_pages_and_sorts(monkeypatch):
calls = []
pages = {
None: _page([_observation(2), _observation(0)], cursor="next"),
"next": _page([_observation(1)]),
None: _page([_observation(2), _observation(0)], cursor="empty"),
"empty": _page([], cursor="last"),
"last": _page([_observation(1)]),
}

def get_many(**kwargs):
Expand All @@ -140,7 +141,7 @@ def get_many(**kwargs):
observations = get_observations(trace_id="trace-123")

assert [o.id for o in observations] == ["obs-0", "obs-1", "obs-2"]
assert [call["cursor"] for call in calls] == [None, "next"]
assert [call["cursor"] for call in calls] == [None, "empty", "last"]
assert all(call["trace_id"] == "trace-123" for call in calls)


Expand Down
Loading