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(trace): UI lazy loading of spans #4014

Merged
merged 4 commits into from
Jul 26, 2024
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
1 change: 1 addition & 0 deletions app/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
prettierPath: null,
transform: {
"^.+\\.[jt]sx?$": ["esbuild-jest"],
},
Expand Down
22 changes: 11 additions & 11 deletions app/src/components/trace/TraceTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import { createSpanTree, SpanTreeNode } from "./utils";

type TraceTreeProps = {
spans: ISpanItem[];
onSpanClick?: (spanId: string) => void;
selectedSpanId: string;
onSpanClick?: (span: ISpanItem) => void;
selectedSpanNodeId: string;
};

export function TraceTree(props: TraceTreeProps) {
const { spans, onSpanClick, selectedSpanId } = props;
const { spans, onSpanClick, selectedSpanNodeId } = props;
const spanTree = createSpanTree(spans);
return (
<ul
Expand All @@ -31,10 +31,10 @@ export function TraceTree(props: TraceTreeProps) {
>
{spanTree.map((spanNode) => (
<SpanTreeItem
key={spanNode.span.context.spanId}
key={spanNode.span.id}
node={spanNode}
onSpanClick={onSpanClick}
selectedSpanId={selectedSpanId}
selectedSpanNodeId={selectedSpanNodeId}
/>
))}
</ul>
Expand All @@ -43,10 +43,10 @@ export function TraceTree(props: TraceTreeProps) {

function SpanTreeItem<TSpan extends ISpanItem>(props: {
node: SpanTreeNode<TSpan>;
selectedSpanId: string;
onSpanClick?: (spanId: string) => void;
selectedSpanNodeId: string;
onSpanClick?: (span: ISpanItem) => void;
}) {
const { node, selectedSpanId, onSpanClick } = props;
const { node, selectedSpanNodeId, onSpanClick } = props;
const childNodes = node.children;
return (
<div>
Expand All @@ -58,11 +58,11 @@ function SpanTreeItem<TSpan extends ISpanItem>(props: {
`}
onClick={() => {
startTransition(() => {
onSpanClick && onSpanClick(node.span.context.spanId);
onSpanClick && onSpanClick(node.span);
});
}}
>
<SpanNodeWrap isSelected={selectedSpanId === node.span.context.spanId}>
<SpanNodeWrap isSelected={selectedSpanNodeId === node.span.id}>
<Flex
direction="row"
gap="size-100"
Expand Down Expand Up @@ -102,7 +102,7 @@ function SpanTreeItem<TSpan extends ISpanItem>(props: {
<SpanTreeItem
node={leafNode}
onSpanClick={onSpanClick}
selectedSpanId={selectedSpanId}
selectedSpanNodeId={selectedSpanNodeId}
/>
</div>
);
Expand Down
10 changes: 10 additions & 0 deletions app/src/components/trace/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createSpanTree } from "../utils";
describe("createSpanTree", () => {
const traceSpans: ISpanItem[] = [
{
id: "1",
spanKind: "chain",
name: "query",
statusCode: "OK",
Expand All @@ -16,6 +17,7 @@ describe("createSpanTree", () => {
},
},
{
id: "2",
spanKind: "chain",
name: "synthesize",
statusCode: "OK",
Expand All @@ -28,6 +30,7 @@ describe("createSpanTree", () => {
},
},
{
id: "3",
spanKind: "llm",
name: "llm",
statusCode: "OK",
Expand All @@ -41,6 +44,7 @@ describe("createSpanTree", () => {
},
},
{
id: "4",
spanKind: "retriever",
name: "retrieve",
statusCode: "OK",
Expand All @@ -54,6 +58,7 @@ describe("createSpanTree", () => {
},
},
{
id: "5",
spanKind: "embedding",
name: "embedding",
statusCode: "OK",
Expand All @@ -80,6 +85,7 @@ describe("createSpanTree", () => {
"spanId": "86433110-f83a-429e-b6e9-5f23131d14f7",
"traceId": "c399b6c1-2826-4e4c-90f4-068afccb81c2",
},
"id": "5",
"latencyMs": 118,
"name": "embedding",
"parentId": "de0d1e57-70d4-4b2b-a100-30b706902da3",
Expand All @@ -94,6 +100,7 @@ describe("createSpanTree", () => {
"spanId": "de0d1e57-70d4-4b2b-a100-30b706902da3",
"traceId": "c399b6c1-2826-4e4c-90f4-068afccb81c2",
},
"id": "4",
"latencyMs": 352,
"name": "retrieve",
"parentId": "86d5abea-ca78-4e59-a3f7-02548bb4e19a",
Expand All @@ -112,6 +119,7 @@ describe("createSpanTree", () => {
"spanId": "5530a9fc-43d7-4add-bff9-91449ec0b1c3",
"traceId": "c399b6c1-2826-4e4c-90f4-068afccb81c2",
},
"id": "3",
"latencyMs": 1921,
"name": "llm",
"parentId": "6cd91cc2-c29d-45c9-b98b-dd37cffa1d7a",
Expand All @@ -127,6 +135,7 @@ describe("createSpanTree", () => {
"spanId": "6cd91cc2-c29d-45c9-b98b-dd37cffa1d7a",
"traceId": "c399b6c1-2826-4e4c-90f4-068afccb81c2",
},
"id": "2",
"latencyMs": 1923,
"name": "synthesize",
"parentId": "86d5abea-ca78-4e59-a3f7-02548bb4e19a",
Expand All @@ -141,6 +150,7 @@ describe("createSpanTree", () => {
"spanId": "86d5abea-ca78-4e59-a3f7-02548bb4e19a",
"traceId": "c399b6c1-2826-4e4c-90f4-068afccb81c2",
},
"id": "1",
"latencyMs": 2275,
"name": "query",
"parentId": null,
Expand Down
1 change: 1 addition & 0 deletions app/src/components/trace/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./SpanKindIcon";
1 change: 1 addition & 0 deletions app/src/components/trace/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* A generic interface for a span to be re-used as a constraint
*/
export interface ISpanItem {
id: string;
name: string;
spanKind: string;
statusCode: SpanStatusCodeType;
Expand Down
1 change: 1 addition & 0 deletions app/src/openInference/tracing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type AttributeToolCall = {
export type AttributeMessages = {
[SemanticAttributePrefixes.message]?: AttributeMessage;
}[];

export type AttributeMessage = {
[MessageAttributePostfixes.role]?: string;
[MessageAttributePostfixes.content]?: string;
Expand Down
6 changes: 3 additions & 3 deletions app/src/pages/example/ExampleDetailsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export function ExampleDetailsDialog({
metadata
}
span {
id
context {
spanId
traceId
}
project {
Expand Down Expand Up @@ -77,7 +77,7 @@ export function ExampleDetailsDialog({
return null;
}
return {
spanId: sourceSpan.context.spanId,
id: sourceSpan.id,
traceId: sourceSpan.context.traceId,
projectId: sourceSpan.project.id,
};
Expand All @@ -98,7 +98,7 @@ export function ExampleDetailsDialog({
size="compact"
onClick={() => {
navigate(
`/projects/${sourceSpanInfo.projectId}/traces/${sourceSpanInfo.traceId}?selectedSpanId=${sourceSpanInfo.spanId}`
`/projects/${sourceSpanInfo.projectId}/traces/${sourceSpanInfo.traceId}?selectedSpanNodeId=${sourceSpanInfo.id}`
);
}}
>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions app/src/pages/project/SpansTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type SpansTableProps = {
project: SpansTable_spans$key;
};

const PAGE_SIZE = 100;
const PAGE_SIZE = 50;

export function SpansTable(props: SpansTableProps) {
const { fetchKey } = useStreamState();
Expand Down Expand Up @@ -264,9 +264,10 @@ export function SpansTable(props: SpansTableProps) {
accessorKey: "name",
enableSorting: false,
cell: ({ getValue, row }) => {
const { spanId, traceId } = row.original.context;
const span = row.original;
const { traceId } = span.context;
return (
<Link to={`traces/${traceId}?selectedSpanId=${spanId}`}>
<Link to={`traces/${traceId}?selectedSpanNodeId=${span.id}`}>
{getValue() as string}
</Link>
);
Expand Down Expand Up @@ -470,7 +471,7 @@ export function SpansTable(props: SpansTableProps) {
key={row.id}
onClick={() =>
navigate(
`traces/${row.original.context.traceId}?selectedSpanId=${row.original.context.spanId}`
`traces/${row.original.context.traceId}?selectedSpanNodeId=${row.original.id}`
)
}
>
Expand Down
6 changes: 3 additions & 3 deletions app/src/pages/project/TracesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type TracesTableProps = {
project: TracesTable_spans$key;
};

const PAGE_SIZE = 100;
const PAGE_SIZE = 50;

/**
* A nested table row is a span with a children that recursively
Expand Down Expand Up @@ -372,9 +372,9 @@ export function TracesTable(props: TracesTableProps) {
accessorKey: "name",
enableSorting: false,
cell: ({ getValue, row }) => {
const { spanId, traceId } = row.original.context;
const { traceId } = row.original.context;
return (
<Link to={`traces/${traceId}?selectedSpanId=${spanId}`}>
<Link to={`traces/${traceId}?selectedSpanNodeId=${row.original.id}`}>
{getValue() as string}
</Link>
);
Expand Down
Loading
Loading