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
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ class AIConversationModelUsage(TypedDict):


class AIConversationStats(AIConversationAggregates):
cacheReadTokens: int
cacheWriteTokens: int
errorToolNames: list[str]
reasoningTokens: int
usageByModel: list[AIConversationModelUsage]


Expand Down Expand Up @@ -259,7 +262,10 @@ def _parse_grouped_stats(rows: Sequence[Mapping[str, Any]]) -> AIConversationSta
)
return {
**conversation_stats,
"cacheReadTokens": sum(usage["cacheReadTokens"] for usage in sorted_usage),
"cacheWriteTokens": sum(usage["cacheWriteTokens"] for usage in sorted_usage),
"errorToolNames": sorted(error_tool_names),
"reasoningTokens": sum(usage["reasoningTokens"] for usage in sorted_usage),
"usageByModel": sorted_usage,
}

Expand Down Expand Up @@ -303,6 +309,7 @@ def get(
Message, tool, and response attributes contain their recorded string values.
`stats.errors` counts spans whose status is not `ok`, `cancelled`, or `unknown`.
`stats.errorToolNames` lists tools used by those spans.
`stats.inputTokens` includes cache-read and cache-write tokens.
Without an explicit range, Sentry widens the search across available retention.
A missing conversation returns an empty `spans` list.
"""
Expand Down
3 changes: 3 additions & 0 deletions src/sentry/apidocs/examples/ai_conversation_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ class AIConversationExamples:
"projects": [{"id": 1, "name": "Weather Assistant", "slug": "weather-assistant"}],
"webUrl": "https://sentry.io/organizations/org-slug/explore/agents/conversations/01JQZ4W8X7J2Q9B4R5M6N7P8T9/?project=1",
"stats": {
"cacheReadTokens": 0,
"cacheWriteTokens": 0,
"endTimestamp": 1743465601250,
"errors": 0,
"errorToolNames": [],
"generationDuration": 1250.0,
"inputTokens": 0,
"llmCalls": 1,
"outputTokens": 0,
"reasoningTokens": 0,
"startTimestamp": 1743465600000,
"toolCalls": 0,
"toolErrors": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,12 +1078,15 @@ def test_returns_full_conversation_stats_on_each_page(self) -> None:
assert response.status_code == 200
assert len(response.data["spans"]) == 1
expected_stats = {
"cacheReadTokens": 30,
"cacheWriteTokens": 15,
"endTimestamp": int(now.timestamp() * 1000),
"errors": 1,
"errorToolNames": ["database"],
"inputTokens": 190,
"llmCalls": 2,
"outputTokens": 110,
"reasoningTokens": 12,
"startTimestamp": int((now - timedelta(seconds=2)).timestamp() * 1000),
"toolCalls": 1,
"toolErrors": 1,
Expand Down
Loading