Skip to content

Commit

Permalink
feat(sessions): sessions table on project page (#5204)
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerHYang committed Dec 9, 2024
1 parent 518e29f commit 021cee9
Show file tree
Hide file tree
Showing 37 changed files with 2,492 additions and 442 deletions.
21 changes: 21 additions & 0 deletions app/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,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"""
durationS: Float!
numTraces: Int!
firstInput: SpanIOValue
lastOutput: SpanIOValue
tokenUsage: TokenUsage!
traces(first: Int = 50, last: Int, after: String, before: String): TraceConnection!
}

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

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

type ToolCallChunk implements ChatCompletionSubscriptionPayload {
datasetExampleId: GlobalID
id: String!
Expand All @@ -1716,7 +1732,12 @@ type Trace implements Node {
"""The Globally Unique ID of this object"""
id: GlobalID!
traceId: String!
startTime: DateTime!
endTime: DateTime!
projectId: GlobalID!
projectSessionId: GlobalID
session: 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 @@ -8,6 +8,7 @@ import { Layout } from "./pages/Layout";
import { spanPlaygroundPageLoaderQuery$data } from "./pages/playground/__generated__/spanPlaygroundPageLoaderQuery.graphql";
import { PlaygroundExamplePage } from "./pages/playground/PlaygroundExamplePage";
import { projectLoaderQuery$data } from "./pages/project/__generated__/projectLoaderQuery.graphql";
import { SessionPage } from "./pages/trace/SessionPage";
import {
APIsPage,
AuthenticatedRoot,
Expand Down Expand Up @@ -118,6 +119,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
}
}
`;

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();
loadSpansQuery({
id: projectId as string,
timeRange: timeRangeVariable,
});
} else if (index === 2) {
disposeSpansQuery();
loadSessionsQuery({
id: projectId as string,
timeRange: timeRangeVariable,
});
} 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

0 comments on commit 021cee9

Please sign in to comment.