-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sessions): add last trace start time column to UI table for sess…
…ions (#5481)
- Loading branch information
1 parent
3bf4b3a
commit 0b402db
Showing
10 changed files
with
94 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletions
13
app/src/pages/project/__generated__/ProjectPageSessionsQuery.graphql.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 11 additions & 4 deletions
15
app/src/pages/project/__generated__/SessionsTableQuery.graphql.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 10 additions & 2 deletions
12
app/src/pages/project/__generated__/SessionsTable_sessions.graphql.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/phoenix/server/api/dataloaders/session_last_start_times.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from datetime import datetime | ||
from typing import Optional | ||
|
||
from openinference.semconv.trace import SpanAttributes | ||
from sqlalchemy import func, select | ||
from strawberry.dataloader import DataLoader | ||
from typing_extensions import TypeAlias | ||
|
||
from phoenix.db import models | ||
from phoenix.server.types import DbSessionFactory | ||
|
||
Key: TypeAlias = int | ||
Result: TypeAlias = Optional[datetime] | ||
|
||
|
||
class SessionLastTraceStartTimeDataLoader(DataLoader[Key, Result]): | ||
def __init__(self, db: DbSessionFactory) -> None: | ||
super().__init__(load_fn=self._load_fn) | ||
self._db = db | ||
|
||
async def _load_fn(self, keys: list[Key]) -> list[Result]: | ||
stmt = ( | ||
select( | ||
models.Trace.project_session_rowid, | ||
func.max(models.Trace.start_time).label("last_start_time"), | ||
) | ||
.where(models.Trace.project_session_rowid.in_(set(keys))) | ||
.group_by(models.Trace.project_session_rowid) | ||
) | ||
async with self._db() as session: | ||
result: dict[Key, Result] = { | ||
id_: last_start_time | ||
async for id_, last_start_time in await session.stream(stmt) | ||
if id_ is not None | ||
} | ||
return [result.get(key) for key in keys] | ||
|
||
|
||
INPUT_VALUE = SpanAttributes.INPUT_VALUE.split(".") | ||
INPUT_MIME_TYPE = SpanAttributes.INPUT_MIME_TYPE.split(".") | ||
OUTPUT_VALUE = SpanAttributes.OUTPUT_VALUE.split(".") | ||
OUTPUT_MIME_TYPE = SpanAttributes.OUTPUT_MIME_TYPE.split(".") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters