🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore: migrate remaining trace reads to AMT (#8056)
Steffen Schmitz5cb52041815c
diff --git a/packages/shared/src/server/repositories/traces.ts b/packages/shared/src/server/repositories/traces.tsindex c37187cd6b..3eb45c3bc6 100644--- a/packages/shared/src/server/repositories/traces.ts+++ b/packages/shared/src/server/repositories/traces.ts@@ -464,33 +464,71 @@ export const getTraceCountsByProjectInCreationInterval = async ({start: Date;end: Date;}) => {- const query = `- SELECT- project_id,- count(*) as count- FROM traces- WHERE created_at >= {start: DateTime64(3)}- AND created_at < {end: DateTime64(3)}- GROUP BY project_id- `;+ return measureAndReturn({+ operationName: "getTraceCountsByProjectInCreationInterval",+ projectId: "__CROSS_PROJECT__",+ input: {+ params: {+ start: convertDateToClickhouseDateTime(start),+ end: convertDateToClickhouseDateTime(end),+ },+ tags: {+ feature: "tracing",+ type: "trace",+ kind: "analytic",+ },+ timestamp: start,+ },+ existingExecution: async (input) => {+ const query = `+ SELECT+ project_id,+ count(*) as count+ FROM traces+ WHERE created_at >= {start: DateTime64(3)}+ AND created_at < {end: DateTime64(3)}+ GROUP BY project_id+ `;- const rows = await queryClickhouse<{ project_id: string; count: string }>({- query,- params: {- start: convertDateToClickhouseDateTime(start),- end: convertDateToClickhouseDateTime(end),+ const rows = await queryClickhouse<{ project_id: string; count: string }>(+ {+ query,+ params: input.params,+ tags: input.tags,+ },+ );++ return rows.map((row) => ({+ projectId: row.project_id,+ count: Number(row.count),+ }));},- tags: {- feature: "tracing",- type: "trace",- kind: "analytic",+ newExecution: async (input) => {+ const traceAmt = getTimeframesTracesAMT(input.timestamp);+ const query = `+ SELECT+ project_id,+ count(*) as count+ FROM ${traceAmt}+ WHERE created_at >= {start: DateTime64(3)}+ AND created_at < {end: DateTime64(3)}+ GROUP BY project_id+ `;++ const rows = await queryClickhouse<{ project_id: string; count: string }>(+ {+ query,+ params: input.params,+ tags: input.tags,+ },+ );++ return rows.map((row) => ({+ projectId: row.project_id,+ count: Number(row.count),+ }));},});-- return rows.map((row) => ({- projectId: row.project_id,- count: Number(row.count),- }));};export const getTraceCountOfProjectsSinceCreationDate = async ({@@ -500,28 +538,57 @@ export const getTraceCountOfProjectsSinceCreationDate = async ({projectIds: string[];start: Date;}) => {- const query = `- SELECT- count(*) as count- FROM traces- WHERE project_id IN ({projectIds: Array(String)})- AND created_at >= {start: DateTime64(3)}- `;+ return measureAndReturn({+ operationName: "getTraceCountOfProjectsSinceCreationDate",+ projectId: "__CROSS_PROJECT__",+ input: {+ params: {+ projectIds,+ start: convertDateToClickhouseDateTime(start),+ },+ tags: {+ feature: "tracing",+ type: "trace",+ kind: "analytic",+ },+ timestamp: start,+ },+ existingExecution: async (input) => {+ const query = `+ SELECT+ count(*) as count+ FROM traces+ WHERE project_id IN ({projectIds: Array(String)})+ AND created_at >= {start: DateTime64(3)}+ `;- const rows = await queryClickhouse<{ count: string }>({- query,- params: {- projectIds,- start: convertDateToClickhouseDateTime(start),+ const rows = await queryClickhouse<{ count: string }>({+ query,+ params: input.params,+ tags: input.tags,+ });++ return Number(rows[0]?.count ?? 0);},- tags: {- feature: "tracing",- type: "trace",- kind: "analytic",+ newExecution: async (input) => {+ const traceAmt = getTimeframesTracesAMT(input.timestamp);+ const query = `+ SELECT+ count(*) as count+ FROM ${traceAmt}+ WHERE project_id IN ({projectIds: Array(String)})+ AND created_at >= {start: DateTime64(3)}+ `;++ const rows = await queryClickhouse<{ count: string }>({+ query,+ params: input.params,+ tags: input.tags,+ });++ return Number(rows[0]?.count ?? 0);},});-- return Number(rows[0]?.count ?? 0);};/**@@ -1232,10 +1299,8 @@ export const getUserMetrics = async (o.project_id = {projectId: String }${timestampFilter ? `AND o.start_time >= {traceTimestamp: DateTime64(3)} - ${OBSERVATIONS_TO_TRACE_INTERVAL}` : ""}AND o.trace_id in (- SELECT- distinct id- from- traces+ SELECT distinct id+ from __TRACE_TABLE__whereuser_id IN ({userIds: Array(String) })AND project_id = {projectId: String }@@ -1249,25 +1314,17 @@ export const getUserMetrics = async (t.user_id,t.project_id,t.timestamp,- t.environment,- ROW_NUMBER() OVER (- PARTITION BY id- ORDER BY- event_ts DESC- ) AS rn+ t.environmentFROM- traces t+ __TRACE_TABLE__ t FINALWHEREt.user_id IN ({userIds: Array(String) })AND t.project_id = {projectId: String }${filter.length > 0 ? `AND ${chFilterRes.query}` : ""}) as t on t.id = o.trace_idand t.project_id = o.project_id- WHERE- o.rn = 1- and t.rn = 1- group by- t.user_id+ WHERE o.rn = 1+ group by t.user_id)SELECTarraySum(mapValues(mapFilter(x -> positionCaseInsensitive(x.1, 'input') > 0, sum_usage_details))) as input_usage,@@ -1280,56 +1337,101 @@ export const getUserMetrics = async (sum_total_cost,max_timestamp,min_timestamp- FROM- stats+ FROM stats`;- `;+ return measureAndReturn({+ operationName: "getUserMetrics",+ projectId,+ input: {+ params: {+ projectId,+ userIds,+ ...chFilterRes.params,+ ...(timestampFilter+ ? {+ traceTimestamp: convertDateToClickhouseDateTime(+ (timestampFilter as DateTimeFilter).value,+ ),+ }+ : {}),+ },+ tags: {+ feature: "tracing",+ type: "trace",+ kind: "analytic",+ projectId,+ },+ },+ existingExecution: async (input) => {+ const rows = await queryClickhouse<{+ user_id: string;+ environment: string;+ max_timestamp: string;+ min_timestamp: string;+ input_usage: string;+ output_usage: string;+ total_usage: string;+ obs_count: string;+ trace_count: string;+ sum_total_cost: string;+ }>({+ query: query.replaceAll("__TRACE_TABLE__", "traces"),+ params: input.params,+ tags: input.tags,+ });- const rows = await queryClickhouse<{- user_id: string;- environment: string;- max_timestamp: string;- min_timestamp: string;- input_usage: string;- output_usage: string;- total_usage: string;- obs_count: string;- trace_count: string;- sum_total_cost: string;- }>({- query,- params: {- projectId,- userIds,- ...chFilterRes.params,- ...(timestampFilter- ? {- traceTimestamp: convertDateToClickhouseDateTime(- (timestampFilter as DateTimeFilter).value,- ),- }- : {}),+ return rows.map((row) => ({+ userId: row.user_id,+ environment: row.environment,+ maxTimestamp: parseClickhouseUTCDateTimeFormat(row.max_timestamp),+ minTimestamp: parseClickhouseUTCDateTimeFormat(row.min_timestamp),+ inputUsage: Number(row.input_usage),+ outputUsage: Number(row.output_usage),+ totalUsage: Number(row.total_usage),+ observationCount: Number(row.obs_count),+ traceCount: Number(row.trace_count),+ totalCost: Number(row.sum_total_cost),+ }));},- tags: {- feature: "tracing",- type: "trace",- kind: "analytic",- projectId,+ newExecution: async (input) => {+ // Extract the timestamp from filter for AMT table selection+ const fromTimestamp = filter?.find(+ (f) =>+ f.column === "timestamp" &&+ (f.operator === ">=" || f.operator === ">"),+ )?.value as Date | undefined;+ const traceAmt = getTimeframesTracesAMT(fromTimestamp);+ const rows = await queryClickhouse<{+ user_id: string;+ environment: string;+ max_timestamp: string;+ min_timestamp: string;+ input_usage: string;+ output_usage: string;+ total_usage: string;+ obs_count: string;+ trace_count: string;+ sum_total_cost: string;+ }>({+ query: query.replaceAll("__TRACE_TABLE__", traceAmt),+ params: input.params,+ tags: input.tags,+ });++ return rows.map((row) => ({+ userId: row.user_id,+ environment: row.environment,+ maxTimestamp: parseClickhouseUTCDateTimeFormat(row.max_timestamp),+ minTimestamp: parseClickhouseUTCDateTimeFormat(row.min_timestamp),+ inputUsage: Number(row.input_usage),+ outputUsage: Number(row.output_usage),+ totalUsage: Number(row.total_usage),+ observationCount: Number(row.obs_count),+ traceCount: Number(row.trace_count),+ totalCost: Number(row.sum_total_cost),+ }));},});-- return rows.map((row) => ({- userId: row.user_id,- environment: row.environment,- maxTimestamp: parseClickhouseUTCDateTimeFormat(row.max_timestamp),- minTimestamp: parseClickhouseUTCDateTimeFormat(row.min_timestamp),- inputUsage: Number(row.input_usage),- outputUsage: Number(row.output_usage),- totalUsage: Number(row.total_usage),- observationCount: Number(row.obs_count),- traceCount: Number(row.trace_count),- totalCost: Number(row.sum_total_cost),- }));};export const getTracesForBlobStorageExport = function (@@ -1360,7 +1462,7 @@ export const getTracesForBlobStorageExport = function (AND timestamp <= {maxTimestamp: DateTime64(3)}`;- const records = queryClickhouseStream<Record<string, unknown>>({+ return queryClickhouseStream<Record<string, unknown>>({query,params: {projectId,@@ -1374,8 +1476,6 @@ export const getTracesForBlobStorageExport = function (projectId,},});-- return records;};export const getTracesForPostHog = async function* (@@ -1440,6 +1540,7 @@ export const getTracesForPostHog = async function* (});const baseUrl = env.NEXTAUTH_URL?.replace("/api/auth", "");+for await (const record of records) {yield {timestamp: record.timestamp,@@ -1467,32 +1568,68 @@ export const getTracesForPostHog = async function* (}};+/**+ * This query is used only for legacy support of redirects without a projectId.+ * We don't have an index on the traceId so it will be a full table scan.+ * We expect at most 10s of calls per day, so this is acceptable.+ */export const getTracesByIdsForAnyProject = async (traceIds: string[]) => {- const query = `- SELECT id, project_id- FROM traces- WHERE id IN ({traceIds: Array(String)})- ORDER BY event_ts DESC- LIMIT 1 by id, project_id;`;- const records = await queryClickhouse<{- id: string;- project_id: string;- }>({- query,- params: {- traceIds,+ return measureAndReturn({+ operationName: "getTracesByIdsForAnyProject",+ projectId: "__CROSS_PROJECT__",+ input: {+ params: {+ traceIds,+ },+ tags: {+ feature: "tracing",+ type: "trace",+ kind: "list",+ },},- tags: {- feature: "tracing",- type: "trace",- kind: "list",+ existingExecution: async (input) => {+ const query = `+ SELECT id, project_id+ FROM traces+ WHERE id IN ({traceIds: Array(String)})+ ORDER BY event_ts DESC+ LIMIT 1 by id, project_id;`;+ const records = await queryClickhouse<{+ id: string;+ project_id: string;+ }>({+ query,+ params: input.params,+ tags: input.tags,+ });++ return records.map((record) => ({+ id: record.id,+ projectId: record.project_id,+ }));},- });+ newExecution: async (input) => {+ // For this query, we need to query all AMT tables as we don't have a specific timestamp+ // We'll use the all AMT table as it contains all data+ const query = `+ SELECT DISTINCT id, project_id+ FROM traces_all_amt+ WHERE id IN ({traceIds: Array(String)})`;+ const records = await queryClickhouse<{+ id: string;+ project_id: string;+ }>({+ query,+ params: input.params,+ tags: input.tags,+ });- return records.map((record) => ({- id: record.id,- projectId: record.project_id,- }));+ return records.map((record) => ({+ id: record.id,+ projectId: record.project_id,+ }));+ },+ });};export async function getAgentGraphData(params: {diff --git a/packages/shared/src/server/services/sessions-ui-table-service.ts b/packages/shared/src/server/services/sessions-ui-table-service.tsindex cdc0cdde8b..abdbe9813e 100644--- a/packages/shared/src/server/services/sessions-ui-table-service.ts+++ b/packages/shared/src/server/services/sessions-ui-table-service.ts@@ -3,6 +3,7 @@ import { OrderByState } from "../../interfaces/orderBy";import { sessionCols } from "../../tableDefinitions/mapSessionTable";import { FilterState } from "../../types";import { convertDateToClickhouseDateTime } from "../clickhouse/client";+import { measureAndReturn } from "../clickhouse/measureAndReturn";import { DateTimeFilter, FilterList, orderByToClickhouseSql } from "../queries";import {getProjectIdDefaultFilter,@@ -11,6 +12,7 @@ import {import {TRACE_TO_OBSERVATIONS_INTERVAL,queryClickhouse,+ getTimeframesTracesAMT,} from "../repositories";export type SessionDataReturnType = {@@ -235,113 +237,135 @@ const getSessionsTableGeneric = async <T>(props: FetchSessionsTableProps) => {// We use deduplicated traces and observations CTEs instead of final to be able to use Skip indices in Clickhouse.const query = `- WITH deduplicated_traces AS (- SELECT * EXCEPT input, output, metadata- FROM traces t- WHERE t.session_id IS NOT NULL- AND t.project_id = {projectId: String}- ${singleTraceFilter?.query ? ` AND ${singleTraceFilter.query}` : ""}- ORDER BY event_ts DESC- LIMIT 1 BY id, project_id- ),- deduplicated_observations AS (- SELECT *- FROM observations o- WHERE o.project_id = {projectId: String}- ${traceTimestampFilter ? `AND o.start_time >= {observationsStartTime: DateTime64(3)} - ${TRACE_TO_OBSERVATIONS_INTERVAL}` : ""}- AND o.trace_id IN (- SELECT id- FROM deduplicated_traces- )- ORDER BY event_ts DESC- LIMIT 1 BY id, project_id- ),- observations_agg AS (- SELECT o.trace_id,- count(*) as obs_count,- min(o.start_time) as min_start_time,- max(o.end_time) as max_end_time,- sumMap(usage_details) as sum_usage_details,- sumMap(cost_details) as sum_cost_details,- anyLast(project_id) as project_id- FROM deduplicated_observations o- WHERE o.project_id = {projectId: String}- ${traceTimestampFilter ? `AND o.start_time >= {observationsStartTime: DateTime64(3)} - ${TRACE_TO_OBSERVATIONS_INTERVAL}` : ""}- GROUP BY o.trace_id- ),- session_data AS (- SELECT- t.session_id,- anyLast(t.project_id) as project_id,- max(t.timestamp) as max_timestamp,- min(t.timestamp) as min_timestamp,- groupArray(t.id) AS trace_ids,- groupUniqArray(t.user_id) AS user_ids,- count(*) as trace_count,- groupUniqArrayArray(t.tags) as trace_tags,- anyLast(t.environment) as trace_environment- -- Aggregate observations data at session level+ WITH deduplicated_traces AS (+ SELECT * EXCEPT input, output, metadata+ FROM __TRACE_TABLE__ t+ WHERE t.session_id IS NOT NULL+ AND t.project_id = {projectId: String}+ ${singleTraceFilter?.query ? ` AND ${singleTraceFilter.query}` : ""}+ ORDER BY event_ts DESC+ LIMIT 1 BY id, project_id+ ),+ deduplicated_observations AS (+ SELECT *+ FROM observations o+ WHERE o.project_id = {projectId: String}+ ${traceTimestampFilter ? `AND o.start_time >= {observationsStartTime: DateTime64(3)} - ${TRACE_TO_OBSERVATIONS_INTERVAL}` : ""}+ AND o.trace_id IN (+ SELECT id+ FROM deduplicated_traces+ )+ ORDER BY event_ts DESC+ LIMIT 1 BY id, project_id+ ),+ observations_agg AS (+ SELECT o.trace_id,+ count(*) as obs_count,+ min(o.start_time) as min_start_time,+ max(o.end_time) as max_end_time,+ sumMap(usage_details) as sum_usage_details,+ sumMap(cost_details) as sum_cost_details,+ anyLast(project_id) as project_id+ FROM deduplicated_observations o+ WHERE o.project_id = {projectId: String}+ ${traceTimestampFilter ? `AND o.start_time >= {observationsStartTime: DateTime64(3)} - ${TRACE_TO_OBSERVATIONS_INTERVAL}` : ""}+ GROUP BY o.trace_id+ ),+ session_data AS (+ SELECT+ t.session_id,+ anyLast(t.project_id) as project_id,+ max(t.timestamp) as max_timestamp,+ min(t.timestamp) as min_timestamp,+ groupArray(t.id) AS trace_ids,+ groupUniqArray(t.user_id) AS user_ids,+ count(*) as trace_count,+ groupUniqArrayArray(t.tags) as trace_tags,+ anyLast(t.environment) as trace_environment+ -- Aggregate observations data at session level+ ${+ selectMetrics+ ? `,+ sum(o.obs_count) as total_observations,+ -- Use minIf, because ClickHouse fills 1970-01-01 on left joins. We assume that no+ -- LLM session started on that date so this behaviour should yield better results.+ date_diff('second', minIf(min_start_time, min_start_time > '1970-01-01'), max(max_end_time)) as duration,+ sumMap(o.sum_usage_details) as session_usage_details,+ sumMap(o.sum_cost_details) as session_cost_details,+ arraySum(mapValues(mapFilter(x -> positionCaseInsensitive(x.1, 'input') > 0, sumMap(o.sum_cost_details)))) as session_input_cost,+ arraySum(mapValues(mapFilter(x -> positionCaseInsensitive(x.1, 'output') > 0, sumMap(o.sum_cost_details)))) as session_output_cost,+ sumMap(o.sum_cost_details)['total'] as session_total_cost,+ arraySum(mapValues(mapFilter(x -> positionCaseInsensitive(x.1, 'input') > 0, sumMap(o.sum_usage_details)))) as session_input_usage,+ arraySum(mapValues(mapFilter(x -> positionCaseInsensitive(x.1, 'output') > 0, sumMap(o.sum_usage_details)))) as session_output_usage,+ sumMap(o.sum_usage_details)['total'] as session_total_usage`+ : ""+ }+ FROM deduplicated_traces t${selectMetrics- ? `- ,- sum(o.obs_count) as total_observations,- -- Use minIf, because ClickHouse fills 1970-01-01 on left joins. We assume that no- -- LLM session started on that date so this behaviour should yield better results.- date_diff('second', minIf(min_start_time, min_start_time > '1970-01-01'), max(max_end_time)) as duration,- sumMap(o.sum_usage_details) as session_usage_details,- sumMap(o.sum_cost_details) as session_cost_details,- arraySum(mapValues(mapFilter(x -> positionCaseInsensitive(x.1, 'input') > 0, sumMap(o.sum_cost_details)))) as session_input_cost,- arraySum(mapValues(mapFilter(x -> positionCaseInsensitive(x.1, 'output') > 0, sumMap(o.sum_cost_details)))) as session_output_cost,- sumMap(o.sum_cost_details)['total'] as session_total_cost,- arraySum(mapValues(mapFilter(x -> positionCaseInsensitive(x.1, 'input') > 0, sumMap(o.sum_usage_details)))) as session_input_usage,- arraySum(mapValues(mapFilter(x -> positionCaseInsensitive(x.1, 'output') > 0, sumMap(o.sum_usage_details)))) as session_output_usage,- sumMap(o.sum_usage_details)['total'] as session_total_usage`+ ? `LEFT JOIN observations_agg o+ ON t.id = o.trace_id AND t.project_id = o.project_id`: ""}- FROM deduplicated_traces t- ${- selectMetrics- ? `LEFT JOIN observations_agg o- ON t.id = o.trace_id AND t.project_id = o.project_id`- : ""- }- WHERE t.session_id IS NOT NULL- AND t.project_id = {projectId: String}- ${singleTraceFilter?.query ? ` AND ${singleTraceFilter.query}` : ""}- GROUP BY t.session_id- )- SELECT ${sqlSelect}- FROM session_data s- WHERE ${tracesFilterRes.query ? tracesFilterRes.query : ""}- ${orderByToClickhouseSql(orderBy ?? null, sessionCols)}- ${limit !== undefined && page !== undefined ? `LIMIT {limit: Int32} OFFSET {offset: Int32}` : ""}- `;-- const obsStartTimeValue = traceTimestampFilter- ? convertDateToClickhouseDateTime(traceTimestampFilter.value)- : null;+ WHERE t.session_id IS NOT NULL+ AND t.project_id = {projectId: String}+ ${singleTraceFilter?.query ? ` AND ${singleTraceFilter.query}` : ""}+ GROUP BY t.session_id+ )+ SELECT ${sqlSelect}+ FROM session_data s+ WHERE ${tracesFilterRes.query ? tracesFilterRes.query : ""}+ ${orderByToClickhouseSql(orderBy ?? null, sessionCols)}+ ${limit !== undefined && page !== undefined ? `LIMIT {limit: Int32} OFFSET {offset: Int32}` : ""}+ `;- const res = await queryClickhouse<T>({- query: query,- params: {- projectId,- limit: limit,- offset: limit && page ? limit * page : 0,- ...tracesFilterRes.params,- ...singleTraceFilter?.params,- ...(obsStartTimeValue- ? { observationsStartTime: obsStartTimeValue }- : {}),+ return measureAndReturn({+ operationName: "getSessionsTableGeneric",+ projectId,+ input: {+ params: {+ projectId,+ limit: limit,+ offset: limit && page ? limit * page : 0,+ ...tracesFilterRes.params,+ ...singleTraceFilter?.params,+ ...(traceTimestampFilter+ ? {+ observationsStartTime: convertDateToClickhouseDateTime(+ traceTimestampFilter.value,+ ),+ }+ : {}),+ },+ tags: {+ ...(props.tags ?? {}),+ feature: "tracing",+ type: "sessions-table",+ projectId,+ },},- tags: {- ...(props.tags ?? {}),- feature: "tracing",- type: "sessions-table",- projectId,+ existingExecution: async (input) => {+ return queryClickhouse<T>({+ query: query.replace("__TRACE_TABLE__", "traces"),+ params: input.params,+ tags: input.tags,+ clickhouseConfigs,+ });+ },+ newExecution: async (input) => {+ // Extract the timestamp from filter for AMT table selection+ const fromTimestamp = filter?.find(+ (f) =>+ f.column === "min_timestamp" &&+ (f.operator === ">=" || f.operator === ">"),+ )?.value as Date | undefined;+ const traceAmt = getTimeframesTracesAMT(fromTimestamp);+ return queryClickhouse<T>({+ query: query.replace("__TRACE_TABLE__", traceAmt),+ params: input.params,+ tags: input.tags,+ clickhouseConfigs,+ });},- clickhouseConfigs,});-- return res;};diff --git a/worker/src/services/IngestionService/README.md b/worker/src/services/IngestionService/README.mdindex b9fc74937a..6e58a5f6ea 100644--- a/worker/src/services/IngestionService/README.md+++ b/worker/src/services/IngestionService/README.md@@ -547,21 +547,25 @@ This checklist documents all references and invocations to the `traces` table gr- [x] **getTracesGroupedByUsers()** - `packages/shared/src/server/repositories/traces.ts:537-597`- [x] **getTracesGroupedByTags()** - `packages/shared/src/server/repositories/traces.ts:605-640`- [x] **getTotalUserCount()** - `packages/shared/src/server/repositories/traces.ts:789-827`-- [ ] **getUserMetrics()** - `packages/shared/src/server/repositories/traces.ts:829-978`+- [x] **getUserMetrics()** - `packages/shared/src/server/repositories/traces.ts:829-978`- [x] **getTracesTableGeneric()** - `packages/shared/src/server/services/traces-ui-table-service.ts:207++`-- [ ] **getSessionsTableGeneric()** - `packages/shared/src/server/services/sessions-ui-table-service.ts:121++`)+- [x] **getSessionsTableGeneric()** - `packages/shared/src/server/services/sessions-ui-table-service.ts:121++`)- [x] **generateTracesForPublicApi()** - `web/src/features/public-api/server/traces.ts:36++`### 5. Data Export and Migration+Note: The measureAndReturn utility does not handle query streams well as it promisifies everything.+We need to cover these queries manually and cannot run a comparison.+We could use an opt-in on a projectId basis.+- [ ] **getTracesForPostHog()** - `packages/shared/src/server/repositories/traces.ts:1026-1113`- [ ] **getTracesForBlobStorageExport()** - `packages/shared/src/server/repositories/traces.ts:980-1024`### 6. Count and Statistics Queries-- [ ] **getTraceCountsByProjectInCreationInterval()** - `packages/shared/src/server/repositories/traces.ts:358-392`-- [ ] **getTraceCountOfProjectsSinceCreationDate()** - `packages/shared/src/server/repositories/traces.ts:394-423`+- [x] **getTraceCountsByProjectInCreationInterval()** - `packages/shared/src/server/repositories/traces.ts:358-392`+- [x] **getTraceCountOfProjectsSinceCreationDate()** - `packages/shared/src/server/repositories/traces.ts:394-423`### 7. Cross-Project Queries-- [ ] **getTracesByIdsForAnyProject()** - `packages/shared/src/server/repositories/traces.ts:1115-1141`+- [x] **getTracesByIdsForAnyProject()** - `packages/shared/src/server/repositories/traces.ts:1115-1141`