@mastra/clickhouse 1.7.1 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3685,6 +3685,26 @@ function rowToSpanRecord(row) {
3685
3685
  updatedAt: null
3686
3686
  };
3687
3687
  }
3688
+ function rowToLightSpanRecord(row) {
3689
+ const startedAt = toDate(row.startedAt);
3690
+ const endedAt = row.isEvent ? startedAt : toDateOrNull(row.endedAt);
3691
+ return {
3692
+ traceId: row.traceId,
3693
+ spanId: row.spanId,
3694
+ parentSpanId: nullableString(row.parentSpanId),
3695
+ name: row.name,
3696
+ spanType: row.spanType,
3697
+ isEvent: Boolean(row.isEvent),
3698
+ startedAt,
3699
+ endedAt,
3700
+ entityType: nullableEntityType(row.entityType),
3701
+ entityId: nullableString(row.entityId),
3702
+ entityName: nullableString(row.entityName),
3703
+ error: parseJson(row.error) ?? void 0,
3704
+ createdAt: startedAt,
3705
+ updatedAt: null
3706
+ };
3707
+ }
3688
3708
  function spanRecordToRow(span) {
3689
3709
  const endedAt = span.isEvent ? span.startedAt : span.endedAt ?? span.startedAt;
3690
3710
  const metadata = span.metadata ?? null;
@@ -5587,7 +5607,7 @@ async function getRootSpan(client, args) {
5587
5607
  if (!rows || rows.length === 0) return null;
5588
5608
  return { span: rowToSpanRecord(rows[0]) };
5589
5609
  }
5590
- async function listTraces(client, args) {
5610
+ async function listTraceRows(client, args, selectClause, mapRows) {
5591
5611
  const { filters, pagination, orderBy } = listTracesArgsSchema.parse(args);
5592
5612
  const page = pagination?.page ?? 0;
5593
5613
  const perPage = pagination?.perPage ?? 10;
@@ -5635,8 +5655,8 @@ async function listTraces(client, args) {
5635
5655
  }
5636
5656
  const dataResult = await client.query({
5637
5657
  query: `
5638
- SELECT * FROM (
5639
- SELECT *
5658
+ SELECT ${selectClause} FROM (
5659
+ SELECT ${selectClause}
5640
5660
  FROM ${TABLE_TRACE_ROOTS} r
5641
5661
  ${whereClause}
5642
5662
  ORDER BY dedupeKey
@@ -5655,7 +5675,6 @@ async function listTraces(client, args) {
5655
5675
  clickhouse_settings: CH_SETTINGS
5656
5676
  });
5657
5677
  const rows = await dataResult.json();
5658
- const spans = rows.map(rowToSpanRecord);
5659
5678
  return {
5660
5679
  pagination: {
5661
5680
  total,
@@ -5663,9 +5682,29 @@ async function listTraces(client, args) {
5663
5682
  perPage,
5664
5683
  hasMore: (page + 1) * perPage < total
5665
5684
  },
5666
- spans: toTraceSpans(spans)
5685
+ spans: mapRows(rows)
5667
5686
  };
5668
5687
  }
5688
+ async function listTraces(client, args) {
5689
+ return listTraceRows(client, args, "*", (rows) => toTraceSpans(rows.map(rowToSpanRecord)));
5690
+ }
5691
+ var LIGHT_TRACE_ROOT_COLUMNS = [
5692
+ "traceId",
5693
+ "spanId",
5694
+ "parentSpanId",
5695
+ "name",
5696
+ "spanType",
5697
+ "isEvent",
5698
+ "startedAt",
5699
+ "endedAt",
5700
+ "entityType",
5701
+ "entityId",
5702
+ "entityName",
5703
+ "error"
5704
+ ].join(", ");
5705
+ async function listTracesLight(client, args) {
5706
+ return listTraceRows(client, args, LIGHT_TRACE_ROOT_COLUMNS, (rows) => rows.map(rowToLightSpanRecord));
5707
+ }
5669
5708
  var BRANCH_SPAN_TYPE_SQL_LIST = BRANCH_SPAN_TYPES.map((t) => `'${t}'`).join(", ");
5670
5709
  async function createSpan(client, args) {
5671
5710
  const row = spanRecordToRow(args.span);
@@ -6286,6 +6325,21 @@ var ObservabilityStorageClickhouseVNext = class extends ObservabilityStorage {
6286
6325
  );
6287
6326
  }
6288
6327
  }
6328
+ async listTracesLight(args) {
6329
+ try {
6330
+ return await listTracesLight(this.#client, args);
6331
+ } catch (error) {
6332
+ if (error instanceof MastraError) throw error;
6333
+ throw new MastraError(
6334
+ {
6335
+ id: createStorageErrorId("CLICKHOUSE", "LIST_TRACES_LIGHT", "FAILED"),
6336
+ domain: ErrorDomain.STORAGE,
6337
+ category: ErrorCategory.THIRD_PARTY
6338
+ },
6339
+ error
6340
+ );
6341
+ }
6342
+ }
6289
6343
  async listBranches(args) {
6290
6344
  try {
6291
6345
  return await listBranches(this.#client, args);