Skip to content

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

feat(dashboard): allow breakdown by month (#7725)

Steffen Schmitz35f6f5f0fc49
diff --git a/web/src/__tests__/queryBuilder.servertest.ts b/web/src/__tests__/queryBuilder.servertest.ts
index 79ff57e6ef..61d90a7c7e 100644
--- a/web/src/__tests__/queryBuilder.servertest.ts
+++ b/web/src/__tests__/queryBuilder.servertest.ts
@@ -3477,6 +3477,57 @@ describe("queryBuilder", () => {
);
expect(totalCount).toBe(30); // Should match our 30 observations
});
+
+ it("should format startTimeMonth dimension correctly", async () => {
+ // Setup
+ const projectId = randomUUID();
+ const trace = createTrace({
+ project_id: projectId,
+ name: "test-trace",
+ environment: "default",
+ timestamp: new Date().getTime(),
+ });
+
+ const observation = createObservation({
+ project_id: projectId,
+ trace_id: trace.id,
+ type: "generation",
+ name: "test-observation",
+ environment: "default",
+ start_time: new Date("2024-03-15T10:00:00Z").getTime(),
+ });
+
+ await createTracesCh([trace]);
+ await createObservationsCh([observation]);
+
+ // Query with startTimeMonth dimension
+ const query: QueryType = {
+ view: "observations",
+ dimensions: [{ field: "startTimeMonth" }],
+ metrics: [{ measure: "count", aggregation: "count" }],
+ filters: [],
+ timeDimension: null,
+ fromTimestamp: "2024-03-01T00:00:00.000Z",
+ toTimestamp: "2024-03-31T23:59:59.999Z",
+ orderBy: null,
+ };
+
+ const queryBuilder = new QueryBuilder();
+ const { query: compiledQuery, parameters } = queryBuilder.build(
+ query,
+ projectId,
+ );
+ const result = await (
+ await clickhouseClient().query({
+ query: compiledQuery,
+ query_params: parameters,
+ })
+ ).json();
+
+ // Verify the month is formatted as YYYY-MM
+ expect(result.data).toHaveLength(1);
+ expect(result.data[0].startTimeMonth).toBe("2024-03");
+ });
});
});
});
diff --git a/web/src/features/query/dataModel.ts b/web/src/features/query/dataModel.ts
index e69725191f..eb54a606d3 100644
--- a/web/src/features/query/dataModel.ts
+++ b/web/src/features/query/dataModel.ts
@@ -14,48 +14,60 @@ export const traceView: ViewDeclarationType = {
"Traces represent a group of observations and typically represent a single request or operation.",
dimensions: {
id: {
- sql: "id",
+ sql: "traces.id",
+ alias: "id",
type: "string",
description: "Unique identifier of the trace.",
},
name: {
- sql: "name",
+ sql: "traces.name",
+ alias: "name",
type: "string",
description:
"Name assigned to the trace (often the endpoint or operation).",
},
tags: {
- sql: "tags",
+ sql: "traces.tags",
+ alias: "tags",
type: "string[]",
description: "User-defined tags associated with the trace.",
},
userId: {
- sql: "user_id",
+ sql: "traces.user_id",
alias: "userId",
type: "string",
description: "Identifier of the user triggering the trace.",
},
sessionId: {
- sql: "session_id",
+ sql: "traces.session_id",
alias: "sessionId",
type: "string",
description: "Identifier of the session triggering the trace.",
},
release: {
- sql: "release",
+ sql: "traces.release",
+ alias: "release",
type: "string",
description: "Release version of the trace.",
},
version: {
- sql: "version",
+ sql: "traces.version",
+ alias: "version",
type: "string",
description: "Version of the trace.",
},
environment: {
- sql: "environment",
+ sql: "traces.environment",
+ alias: "environment",
type: "string",
description: "Deployment environment (e.g., production, staging).",
},
+ timestampMonth: {
+ sql: "formatDateTime(traces.timestamp, '%Y-%m')",
+ alias: "timestampMonth",
+ type: "string",
+ description: "Month of the trace timestamp in YYYY-MM format.",
+ },
},
measures: {
count: {
@@ -132,108 +144,121 @@ export const observationsView: ViewDeclarationType = {
"Observations represent individual requests or operations within a trace. They are grouped into Spans, Generations, and Events.",
dimensions: {
id: {
- sql: "id",
+ sql: "observations.id",
+ alias: "id",
type: "string",
description: "Unique identifier for the observation.",
},
traceId: {
- sql: "trace_id",
+ sql: "observations.trace_id",
alias: "traceId",
type: "string",
description: "Identifier linking the observation to its parent trace.",
},
traceName: {
- sql: "name",
+ sql: "traces.name",
alias: "traceName",
type: "string",
relationTable: "traces",
description: "Name of the parent trace.",
},
environment: {
- sql: "environment",
+ sql: "observations.environment",
+ alias: "environment",
type: "string",
description: "Deployment environment (e.g., production, staging).",
},
parentObservationId: {
- sql: "parent_observation_id",
+ sql: "observations.parent_observation_id",
alias: "parentObservationId",
type: "string",
description:
"Identifier of the parent observation. Empty for the root span.",
},
type: {
- sql: "type",
+ sql: "observations.type",
+ alias: "type",
type: "string",
description:
"Type of the observation. Can be a SPAN, GENERATION, or EVENT.",
},
name: {
- sql: "name",
+ sql: "observations.name",
+ alias: "name",
type: "string",
description: "Name of the observation.",
},
level: {
- sql: "level",
+ sql: "observations.level",
+ alias: "level",
type: "string",
description: "Logging level of the observation.",
},
version: {
- sql: "version",
+ sql: "observations.version",
+ alias: "version",
type: "string",
description: "Version of the observation.",
},
tags: {
- sql: "tags",
+ sql: "traces.tags",
+ alias: "tags",
type: "string[]",
relationTable: "traces",
description: "User-defined tags associated with the trace.",
},
providedModelName: {
- sql: "provided_model_name",
+ sql: "observations.provided_model_name",
alias: "providedModelName",
type: "string",
description: "Name of the model used for the observation.",
},
promptName: {
- sql: "prompt_name",
+ sql: "observations.prompt_name",
alias: "promptName",
type: "string",
description: "Name of the prompt used for the observation.",
},
promptVersion: {
- sql: "prompt_version",
+ sql: "observations.prompt_version",
alias: "promptVersion",
type: "string",
description: "Version of the prompt used for the observation.",
},
userId: {
- sql: "user_id",
+ sql: "traces.user_id",
alias: "userId",
type: "string",
relationTable: "traces",
description: "Identifier of the user triggering the observation.",
},
sessionId: {
- sql: "session_id",
+ sql: "traces.session_id",
alias: "sessionId",
type: "string",
relationTable: "traces",
description: "Identifier of the session triggering the observation.",
},
traceRelease: {
- sql: "release",
+ sql: "traces.release",
alias: "traceRelease",
type: "string",
relationTable: "traces",
description: "Release version of the parent trace.",
},
traceVersion: {
- sql: "version",
+ sql: "traces.version",
alias: "traceVersion",
type: "string",
relationTable: "traces",
description: "Version of the parent trace.",
},
+ startTimeMonth: {
+ sql: "formatDateTime(observations.start_time, '%Y-%m')",
+ alias: "startTimeMonth",
+ type: "string",
+ description: "Month of the observation start_time in YYYY-MM format.",
+ },
},
measures: {
count: {
@@ -358,120 +383,76 @@ export const observationsView: ViewDeclarationType = {
};
const scoreBaseDimensions: DimensionsDeclarationType = {
- id: {
- sql: "id",
- type: "string",
- description: "Unique identifier of the score entry.",
- },
- environment: {
- sql: "environment",
- type: "string",
- description: "Deployment environment (e.g., production, staging).",
- },
- name: {
- sql: "name",
- type: "string",
- description: "Name of the score (e.g., accuracy, toxicity).",
- },
- source: {
- sql: "source",
- type: "string",
- description: "Origin of the score. Can be API, ANNOTATION, or EVAL.",
- },
- dataType: {
- sql: "data_type",
- alias: "dataType",
- type: "string",
- description:
- "Internal data type of the score (NUMERIC, BOOLEAN, CATEGORICAL).",
- },
- traceId: {
- sql: "trace_id",
- alias: "traceId",
- type: "string",
- description: "Identifier of the parent trace.",
- },
traceName: {
- sql: "name",
+ sql: "traces.name",
alias: "traceName",
type: "string",
relationTable: "traces",
description: "Name of the parent trace.",
},
tags: {
- sql: "tags",
+ sql: "traces.tags",
+ alias: "tags",
type: "string[]",
relationTable: "traces",
description: "User-defined tags associated with the trace.",
},
userId: {
- sql: "user_id",
+ sql: "traces.user_id",
alias: "userId",
type: "string",
relationTable: "traces",
description: "Identifier of the user triggering the trace.",
},
sessionId: {
- sql: "session_id",
+ sql: "traces.session_id",
alias: "sessionId",
type: "string",
relationTable: "traces",
description: "Identifier of the session triggering the trace.",
},
traceRelease: {
- sql: "release",
+ sql: "traces.release",
alias: "traceRelease",
type: "string",
relationTable: "traces",
description: "Release version of the parent trace.",
},
traceVersion: {
- sql: "version",
+ sql: "traces.version",
alias: "traceVersion",
type: "string",
relationTable: "traces",
description: "Version of the parent trace.",
},
- observationId: {
- sql: "observation_id",
- alias: "observationId",
- type: "string",
- description: "Identifier of the observation associated with the score.",
- },
observationName: {
- sql: "name",
+ sql: "observations.name",
alias: "observationName",
type: "string",
relationTable: "observations",
description: "Name of the observation associated with the score.",
},
observationModelName: {
- sql: "provided_model_name",
+ sql: "observations.provided_model_name",
alias: "observationModelName",
type: "string",
relationTable: "observations",
description: "Name of the model used for the observation.",
},
observationPromptName: {
- sql: "prompt_name",
+ sql: "observations.prompt_name",
alias: "observationPromptName",
type: "string",
relationTable: "observations",
description: "Name of the prompt used for the observation.",
},
observationPromptVersion: {
- sql: "prompt_version",
+ sql: "observations.prompt_version",
alias: "observationPromptVersion",
type: "string",
relationTable: "observations",
description: "Version of the prompt used for the observation.",
},
- configId: {
- sql: "config_id",
- alias: "configId",
- type: "string",
- description: "Identifier of the config associated with the score.",
- },
};
export const scoresNumericView: ViewDeclarationType = {
@@ -480,8 +461,64 @@ export const scoresNumericView: ViewDeclarationType = {
"Scores are flexible objects that are used for evaluations. This view contains numeric scores.",
dimensions: {
...scoreBaseDimensions,
+ id: {
+ sql: "scores_numeric.id",
+ alias: "id",
+ type: "string",
+ description: "Unique identifier of the score entry.",
+ },
+ environment: {
+ sql: "scores_numeric.environment",
+ alias: "environment",
+ type: "string",
+ description: "Deployment environment (e.g., production, staging).",
+ },
+ name: {
+ sql: "scores_numeric.name",
+ alias: "name",
+ type: "string",
+ description: "Name of the score (e.g., accuracy, toxicity).",
+ },
+ source: {
+ sql: "scores_numeric.source",
+ alias: "source",
+ type: "string",
+ description: "Origin of the score. Can be API, ANNOTATION, or EVAL.",
+ },
+ dataType: {
+ sql: "scores_numeric.data_type",
+ alias: "dataType",
+ type: "string",
+ description:
+ "Internal data type of the score (NUMERIC, BOOLEAN, CATEGORICAL).",
+ },
+ traceId: {
+ sql: "scores_numeric.trace_id",
+ alias: "traceId",
+ type: "string",
+ description: "Identifier of the parent trace.",
+ },
+ configId: {
+ sql: "scores_numeric.config_id",
+ alias: "configId",
+ type: "string",
+ description: "Identifier of the config associated with the score.",
+ },
+ timestampMonth: {
+ sql: "formatDateTime(scores_numeric.timestamp, '%Y-%m')",
+ alias: "timestampMonth",
+ type: "string",
+ description: "Month of the score timestamp in YYYY-MM format.",
+ },
+ observationId: {
+ sql: "scores_numeric.observation_id",
+ alias: "observationId",
+ type: "string",
+ description: "Identifier of the observation associated with the score.",
+ },
value: {
sql: "value",
+ alias: "value",
type: "number",
description: "Value of the score.",
},
@@ -534,6 +571,61 @@ export const scoresCategoricalView: ViewDeclarationType = {
"Scores are flexible objects that are used for evaluations. This view contains categorical scores.",
dimensions: {
...scoreBaseDimensions,
+ id: {
+ sql: "scores_categorical.id",
+ alias: "id",
+ type: "string",
+ description: "Unique identifier of the score entry.",
+ },
+ environment: {
+ sql: "scores_categorical.environment",
+ alias: "environment",
+ type: "string",
+ description: "Deployment environment (e.g., production, staging).",
+ },
+ name: {
+ sql: "scores_categorical.name",
+ alias: "name",
+ type: "string",
+ description: "Name of the score (e.g., accuracy, toxicity).",
+ },
+ source: {
+ sql: "scores_categorical.source",
+ alias: "source",
+ type: "string",
+ description: "Origin of the score. Can be API, ANNOTATION, or EVAL.",
+ },
+ dataType: {
+ sql: "scores_categorical.data_type",
+ alias: "dataType",
+ type: "string",
+ description:
+ "Internal data type of the score (NUMERIC, BOOLEAN, CATEGORICAL).",
+ },
+ traceId: {
+ sql: "scores_categorical.trace_id",
+ alias: "traceId",
+ type: "string",
+ description: "Identifier of the parent trace.",
+ },
+ configId: {
+ sql: "scores_categorical.config_id",
+ alias: "configId",
+ type: "string",
+ description: "Identifier of the config associated with the score.",
+ },
+ timestampMonth: {
+ sql: "formatDateTime(scores_categorical.timestamp, '%Y-%m')",
+ alias: "timestampMonth",
+ type: "string",
+ description: "Month of the score timestamp in YYYY-MM format.",
+ },
+ observationId: {
+ sql: "scores_categorical.observation_id",
+ alias: "observationId",
+ type: "string",
+ description: "Identifier of the observation associated with the score.",
+ },
stringValue: {
sql: "string_value",
alias: "stringValue",
diff --git a/web/src/features/query/server/queryBuilder.ts b/web/src/features/query/server/queryBuilder.ts
index 5ec4041333..baccd2927b 100644
--- a/web/src/features/query/server/queryBuilder.ts
+++ b/web/src/features/query/server/queryBuilder.ts
@@ -124,6 +124,7 @@ export class QueryBuilder {
// Transform our filters to match the column mapping format expected by createFilterFromFilterState
const columnMappings = filters.map((filter) => {
let clickhouseSelect: string;
+ let queryPrefix: string = "";
let clickhouseTableName: string = view.name;
let type: string;
@@ -144,15 +145,18 @@ export class QueryBuilder {
// }
} else if (filter.column === view.timeDimension) {
clickhouseSelect = view.timeDimension;
+ queryPrefix = clickhouseTableName;
type = "datetime";
} else if (filter.column === "metadata") {
clickhouseSelect = "metadata";
+ queryPrefix = clickhouseTableName;
type = "stringObject";
} else if (filter.column.endsWith("Name")) {
// Sometimes, the filter does not update correctly and sends us scoreName instead of name for scores, etc.
// If this happens, none of the conditions above apply, and we use this fallback to avoid raising an error.
// As this is hard to catch, we include this workaround. (LFE-4838).
clickhouseSelect = "name";
+ queryPrefix = clickhouseTableName;
type = "string";
} else {
throw new InvalidRequestError(
@@ -165,7 +169,7 @@ export class QueryBuilder {
uiTableId: filter.column,
clickhouseTableName,
clickhouseSelect,
- queryPrefix: clickhouseTableName,
+ queryPrefix,
type,
};
});
@@ -428,7 +432,7 @@ export class QueryBuilder {
dimensions += `${appliedDimensions
.map(
(dimension) =>
- `any(${dimension.table}.${dimension.sql}) as ${dimension.alias ?? dimension.sql}`,
+ `any(${dimension.sql}) as ${dimension.alias ?? dimension.sql}`,
)
.join(",\n")},`;
}