Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sessions): sessions table on project page #5204

Merged
merged 27 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
21 changes: 21 additions & 0 deletions app/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,16 @@ type ProjectSession implements Node {
"""The Globally Unique ID of this object"""
id: GlobalID!
sessionId: String!
sessionUser: String
startTime: DateTime!
endTime: DateTime!

"""Duration of the session in seconds"""
duration: Int!
numTraces: Int!
firstInput: SpanIOValue
lastOutput: SpanIOValue
tokenUsage: TokenUsage!
traces(first: Int = 50, last: Int, after: String, before: String): TraceConnection!
}

Expand Down Expand Up @@ -1535,6 +1545,12 @@ type TimeSeriesDataPoint {
value: Float
}

type TokenUsage {
prompt: Int!
completion: Int!
total: Int!
}

type ToolCallChunk {
id: String!
function: FunctionCallChunk!
Expand All @@ -1544,7 +1560,12 @@ type Trace implements Node {
"""The Globally Unique ID of this object"""
id: GlobalID!
traceId: String!
startTime: DateTime!
endTime: DateTime!
projectId: GlobalID!
projectSessionId: GlobalID!
projectSession: ProjectSession
rootSpan: Span
spans(first: Int = 50, last: Int, after: String, before: String): SpanConnection!

"""Annotations associated with the trace."""
Expand Down
2 changes: 2 additions & 0 deletions app/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { embeddingLoaderQuery$data } from "./pages/embedding/__generated__/embed
import { Layout } from "./pages/Layout";
import { spanPlaygroundPageLoaderQuery$data } from "./pages/playground/__generated__/spanPlaygroundPageLoaderQuery.graphql";
import { projectLoaderQuery$data } from "./pages/project/__generated__/projectLoaderQuery.graphql";
import { SessionPage } from "./pages/trace/SessionPage";
import {
APIsPage,
AuthenticatedRoot,
Expand Down Expand Up @@ -117,6 +118,7 @@ const router = createBrowserRouter(
<Route index element={<ProjectPage />} />
<Route element={<ProjectPage />}>
<Route path="traces/:traceId" element={<TracePage />} />
<Route path="sessions/:sessionId" element={<SessionPage />} />
</Route>
</Route>
</Route>
Expand Down
54 changes: 53 additions & 1 deletion app/src/pages/project/ProjectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import {
} from "@phoenix/components/datetime";

import { ProjectPageQuery } from "./__generated__/ProjectPageQuery.graphql";
import { ProjectPageSessionsQuery as ProjectPageSessionsQueryType } from "./__generated__/ProjectPageSessionsQuery.graphql";
import { ProjectPageSpansQuery as ProjectPageSpansQueryType } from "./__generated__/ProjectPageSpansQuery.graphql";
import { ProjectPageHeader } from "./ProjectPageHeader";
import { SessionsTable } from "./SessionsTable";
import { SpanFilterConditionProvider } from "./SpanFilterConditionContext";
import { SpansTable } from "./SpansTable";
import { StreamToggle } from "./StreamToggle";
Expand Down Expand Up @@ -75,6 +77,14 @@ const ProjectPageSpansQuery = graphql`
}
`;

const ProjectPageSessionsQuery = graphql`
query ProjectPageSessionsQuery($id: GlobalID!, $timeRange: TimeRange!) {
project: node(id: $id) {
...SessionsTable_sessions
}
}
`;
RogerHYang marked this conversation as resolved.
Show resolved Hide resolved

export function ProjectPageContent({
projectId,
timeRange,
Expand Down Expand Up @@ -109,18 +119,35 @@ export function ProjectPageContent({
);
const [spansQueryReference, loadSpansQuery, disposeSpansQuery] =
useQueryLoader<ProjectPageSpansQueryType>(ProjectPageSpansQuery);
const [sessionsQueryReference, loadSessionsQuery, disposeSessionsQuery] =
useQueryLoader<ProjectPageSessionsQueryType>(ProjectPageSessionsQuery);
const onTabChange = useCallback(
(index: number) => {
if (index === 1) {
disposeSessionsQuery();
RogerHYang marked this conversation as resolved.
Show resolved Hide resolved
loadSpansQuery({
id: projectId as string,
timeRange: timeRangeVariable,
});
} else if (index === 2) {
disposeSpansQuery();
loadSessionsQuery({
id: projectId as string,
timeRange: timeRangeVariable,
});
RogerHYang marked this conversation as resolved.
Show resolved Hide resolved
} else {
disposeSpansQuery();
disposeSessionsQuery();
}
},
[disposeSpansQuery, loadSpansQuery, projectId, timeRangeVariable]
[
disposeSpansQuery,
loadSpansQuery,
disposeSessionsQuery,
loadSessionsQuery,
projectId,
timeRangeVariable,
]
);
return (
<main css={mainCSS}>
Expand Down Expand Up @@ -161,6 +188,22 @@ export function ProjectPageContent({
);
}}
</TabPane>
<TabPane name="Sessions" title="Sessions">
{({ isSelected }) => {
return (
isSelected &&
sessionsQueryReference && (
<SpanFilterConditionProvider>
<Suspense>
<SessionsTabContent
queryReference={sessionsQueryReference}
/>
</Suspense>
</SpanFilterConditionProvider>
)
);
}}
</TabPane>
</Tabs>
<Suspense>
<Outlet />
Expand All @@ -177,3 +220,12 @@ function SpansTabContent({
const data = usePreloadedQuery(ProjectPageSpansQuery, queryReference);
return <SpansTable project={data.project} />;
}

function SessionsTabContent({
queryReference,
}: {
queryReference: PreloadedQuery<ProjectPageSessionsQueryType>;
}) {
const data = usePreloadedQuery(ProjectPageSessionsQuery, queryReference);
return <SessionsTable project={data.project} />;
}
Loading
Loading