Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

perf(ui): increase speed of tables, no `nulls first/last` modifier when sorting by non-nullable attributes (#3068)

Marc Klingen7668995ec9c0
diff --git a/packages/shared/src/observationsTable.ts b/packages/shared/src/observationsTable.ts
index dfe1097e2e..524f0d9f29 100644
--- a/packages/shared/src/observationsTable.ts
+++ b/packages/shared/src/observationsTable.ts
@@ -18,6 +18,7 @@ export const observationsTableCols: ColumnDefinition[] = [
type: "stringOptions",
internal: 'o."name"',
options: [], // to be added at runtime
+ nullable: true,
},
{ name: "Trace ID", id: "traceId", type: "string", internal: 't."id"' },
{
@@ -26,8 +27,15 @@ export const observationsTableCols: ColumnDefinition[] = [
type: "stringOptions",
internal: 't."name"',
options: [], // to be added at runtime
+ nullable: true,
+ },
+ {
+ name: "User ID",
+ id: "userId",
+ type: "string",
+ internal: 't."user_id"',
+ nullable: true,
},
- { name: "User ID", id: "userId", type: "string", internal: 't."user_id"' },
{
name: "Start Time",
id: "startTime",
@@ -45,6 +53,7 @@ export const observationsTableCols: ColumnDefinition[] = [
id: "timeToFirstToken",
type: "number",
internal: 'o."completion_start_time" - o."start_time"',
+ nullable: true,
},
{
name: "Latency (s)",
@@ -57,24 +66,28 @@ export const observationsTableCols: ColumnDefinition[] = [
id: "timePerOutputToken",
type: "number",
internal: '"latency" / o."completion_tokens"',
+ nullable: true,
},
{
name: "Input Cost ($)",
id: "inputCost",
type: "number",
internal: 'o."calculated_input_cost"',
+ nullable: true,
},
{
name: "Output Cost ($)",
id: "outputCost",
type: "number",
internal: 'o."calculated_output_cost"',
+ nullable: true,
},
{
name: "Total Cost ($)",
id: "totalCost",
type: "number",
internal: 'o."calculated_total_cost"',
+ nullable: true,
},
{
name: "Level",
@@ -88,6 +101,7 @@ export const observationsTableCols: ColumnDefinition[] = [
id: "statusMessage",
type: "string",
internal: 'o."status_message"',
+ nullable: true,
},
{
name: "Model",
@@ -95,24 +109,28 @@ export const observationsTableCols: ColumnDefinition[] = [
type: "stringOptions",
internal: 'o."model"',
options: [], // to be added at runtime
+ nullable: true,
},
{
name: "Input Tokens",
id: "inputTokens",
type: "number",
internal: 'o."prompt_tokens"',
+ nullable: true,
},
{
name: "Output Tokens",
id: "outputTokens",
type: "number",
internal: 'o."completion_tokens"',
+ nullable: true,
},
{
name: "Total Tokens",
id: "totalTokens",
type: "number",
internal: 'o."total_tokens"',
+ nullable: true,
},
{
name: "Usage",
@@ -137,6 +155,7 @@ export const observationsTableCols: ColumnDefinition[] = [
id: "version",
type: "string",
internal: 'o."version"',
+ nullable: true,
},
{
name: "Prompt Name",
@@ -144,12 +163,14 @@ export const observationsTableCols: ColumnDefinition[] = [
type: "stringOptions",
internal: "p.name",
options: [], // to be added at runtime
+ nullable: true,
},
{
name: "Prompt Version",
id: "promptVersion",
type: "number",
internal: "p.version",
+ nullable: true,
},
];
diff --git a/packages/shared/src/orderByToPrisma.ts b/packages/shared/src/orderByToPrisma.ts
index 4c654f105d..bd5b49dfb1 100644
--- a/packages/shared/src/orderByToPrisma.ts
+++ b/packages/shared/src/orderByToPrisma.ts
@@ -16,7 +16,7 @@ export function orderByToPrismaSql(
tableColumns: ColumnDefinition[]
): Prisma.Sql {
if (!orderBy) {
- return Prisma.sql`ORDER BY t.timestamp DESC NULLS LAST`;
+ return Prisma.sql`ORDER BY t.timestamp DESC`;
}
// Get column definition to map column to internal name, e.g. "t.id"
const col = tableColumns.find(
@@ -40,6 +40,6 @@ export function orderByToPrismaSql(
// Both column and order are safe, can use raw SQL
return Prisma.raw(
- `ORDER BY ${col.internal} ${order.data} ${orderBy.order === "DESC" ? "NULLS LAST" : "NULLS FIRST"}`
+ `ORDER BY ${col.internal} ${order.data} ${col.nullable ? (orderBy.order === "DESC" ? "NULLS LAST" : "NULLS FIRST") : ""}`
);
}
diff --git a/packages/shared/src/tableDefinitions/sessionsView.ts b/packages/shared/src/tableDefinitions/sessionsView.ts
index c8335a61ac..61e46b88b8 100644
--- a/packages/shared/src/tableDefinitions/sessionsView.ts
+++ b/packages/shared/src/tableDefinitions/sessionsView.ts
@@ -17,6 +17,7 @@ export const sessionsViewCols: ColumnDefinition[] = [
type: "arrayOptions",
internal: 't."userIds"',
options: [], // to be filled in at runtime
+ nullable: true,
},
{
name: "Session Duration (s)",
diff --git a/packages/shared/src/tableDefinitions/types.ts b/packages/shared/src/tableDefinitions/types.ts
index c338da3ec7..e5bda80422 100644
--- a/packages/shared/src/tableDefinitions/types.ts
+++ b/packages/shared/src/tableDefinitions/types.ts
@@ -9,6 +9,7 @@ export type ColumnDefinition =
id: string;
type: "number" | "string" | "datetime" | "boolean";
internal: string;
+ nullable?: boolean;
}
| {
name: string;
@@ -16,6 +17,7 @@ export type ColumnDefinition =
type: "stringOptions";
options: Array<OptionsDefinition>;
internal: string;
+ nullable?: boolean;
}
| {
name: string;
@@ -23,6 +25,7 @@ export type ColumnDefinition =
type: "arrayOptions";
options: Array<OptionsDefinition>;
internal: string;
+ nullable?: boolean;
}
| {
name: string;
@@ -30,6 +33,7 @@ export type ColumnDefinition =
type: "stringObject" | "numberObject";
internal: string;
keyOptions?: Array<string>;
+ nullable?: boolean;
};
export const tableNames = [
diff --git a/packages/shared/src/tracesTable.ts b/packages/shared/src/tracesTable.ts
index a2af9edac1..c4c8c367b3 100644
--- a/packages/shared/src/tracesTable.ts
+++ b/packages/shared/src/tracesTable.ts
@@ -15,6 +15,7 @@ const tracesOnlyCols: ColumnDefinition[] = [
type: "stringOptions",
internal: 't."name"',
options: [], // to be filled in at runtime
+ nullable: true,
},
{
name: "Timestamp",
@@ -22,12 +23,19 @@ const tracesOnlyCols: ColumnDefinition[] = [
type: "datetime",
internal: 't."timestamp"',
},
- { name: "User ID", id: "userId", type: "string", internal: 't."user_id"' },
+ {
+ name: "User ID",
+ id: "userId",
+ type: "string",
+ internal: 't."user_id"',
+ nullable: true,
+ },
{
name: "Session ID",
id: "sessionId",
type: "string",
internal: 't."session_id"',
+ nullable: true,
},
{
name: "Metadata",
@@ -40,12 +48,14 @@ const tracesOnlyCols: ColumnDefinition[] = [
id: "version",
type: "string",
internal: 't."version"',
+ nullable: true,
},
{
name: "Release",
id: "release",
type: "string",
internal: 't."release"',
+ nullable: true,
},
{
name: "Level",
@@ -69,24 +79,28 @@ export const tracesTableCols: ColumnDefinition[] = [
id: "inputTokens",
type: "number",
internal: 'tm."promptTokens"',
+ nullable: true,
},
{
name: "Output Tokens",
id: "outputTokens",
type: "number",
internal: 'tm."completionTokens"',
+ nullable: true,
},
{
name: "Total Tokens",
id: "totalTokens",
type: "number",
internal: 'tm."totalTokens"',
+ nullable: true,
},
{
name: "Usage",
id: "usage",
type: "number",
internal: 'tm."totalTokens"',
+ nullable: true,
},
{
@@ -106,18 +120,21 @@ export const tracesTableCols: ColumnDefinition[] = [
id: "inputCost",
type: "number",
internal: '"calculatedInputCost"',
+ nullable: true,
},
{
name: "Output Cost ($)",
id: "outputCost",
type: "number",
internal: '"calculatedOutputCost"',
+ nullable: true,
},
{
name: "Total Cost ($)",
id: "totalCost",
type: "number",
internal: '"calculatedTotalCost"',
+ nullable: true,
},
];