@mastra/duckdb 1.14.2-alpha.0 → 1.15.0-alpha.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/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/{features-BzhPmFg2.cjs → features-BAGbFa2n.cjs} +2 -2
- package/dist/{features-BzhPmFg2.cjs.map → features-BAGbFa2n.cjs.map} +1 -1
- package/dist/{features-D3sUOsCL.js → features-vjVgmb36.js} +2 -2
- package/dist/{features-D3sUOsCL.js.map → features-vjVgmb36.js.map} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/dist/{observability-G5gsNol7.cjs → observability-DJs6G-BH.cjs} +153 -33
- package/dist/observability-DJs6G-BH.cjs.map +1 -0
- package/dist/{observability-CXUQZgpz.js → observability-HUYFWVy-.js} +153 -33
- package/dist/observability-HUYFWVy-.js.map +1 -0
- package/dist/storage/domains/observability/ddl.d.ts +1 -1
- package/dist/storage/domains/observability/ddl.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +1 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/preview-compat.d.ts +18 -12
- package/dist/storage/domains/observability/preview-compat.d.ts.map +1 -1
- package/dist/storage/domains/observability/span-query.d.ts +18 -12
- package/dist/storage/domains/observability/span-query.d.ts.map +1 -1
- package/dist/storage/domains/observability/trace-query.d.ts +1 -1
- package/dist/storage/domains/observability/trace-query.d.ts.map +1 -1
- package/dist/storage/domains/observability/tracing.d.ts.map +1 -1
- package/dist/storage/features.d.ts +1 -1
- package/dist/storage/features.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/observability-CXUQZgpz.js.map +0 -1
- package/dist/observability-G5gsNol7.cjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as DuckDBConnection, r as DuckDBQueryTimeoutError, t as spanQueryFeatures } from "./features-
|
|
1
|
+
import { n as DuckDBConnection, r as DuckDBQueryTimeoutError, t as spanQueryFeatures } from "./features-vjVgmb36.js";
|
|
2
2
|
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
3
3
|
import * as coreStorage from "@mastra/core/storage";
|
|
4
4
|
import { BRANCH_SPAN_TYPES, METRIC_DISTINCT_COLUMNS, ObservabilityStorage, computeTraceStatus, createStorageErrorId, executeRetentionPrune, feedbackRecordSchema, listBranchesArgsSchema, listFeedbackArgsSchema, listLogsArgsSchema, listMetricsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, resolveRetentionTargets, retentionCutoffMs, toTraceSpans } from "@mastra/core/storage";
|
|
@@ -99,6 +99,7 @@ CREATE TABLE IF NOT EXISTS span_events (
|
|
|
99
99
|
spanType VARCHAR,
|
|
100
100
|
isEvent BOOLEAN,
|
|
101
101
|
endedAt TIMESTAMP,
|
|
102
|
+
timeToFirstChunkMs DOUBLE,
|
|
102
103
|
|
|
103
104
|
-- JSON fields
|
|
104
105
|
attributes JSON,
|
|
@@ -370,6 +371,7 @@ const ALL_MIGRATIONS = [
|
|
|
370
371
|
`ALTER TABLE span_events ADD COLUMN IF NOT EXISTS hasInputPayload BOOLEAN`,
|
|
371
372
|
`ALTER TABLE span_events ADD COLUMN IF NOT EXISTS hasOutputPayload BOOLEAN`,
|
|
372
373
|
`ALTER TABLE span_events ADD COLUMN IF NOT EXISTS hasErrorPayload BOOLEAN`,
|
|
374
|
+
`ALTER TABLE span_events ADD COLUMN IF NOT EXISTS timeToFirstChunkMs DOUBLE`,
|
|
373
375
|
`ALTER TABLE metric_events ADD COLUMN IF NOT EXISTS cursorId BIGINT`,
|
|
374
376
|
`ALTER TABLE metric_events ADD COLUMN IF NOT EXISTS entityVersionId VARCHAR`,
|
|
375
377
|
`ALTER TABLE metric_events ADD COLUMN IF NOT EXISTS parentEntityVersionId VARCHAR`,
|
|
@@ -727,9 +729,27 @@ function readPreview(preview, payload, jsonEncoded = false) {
|
|
|
727
729
|
}
|
|
728
730
|
/** Older response builders may shorten previews or turn empty strings into null. */
|
|
729
731
|
function buildSpanQueryResponse(...args) {
|
|
730
|
-
|
|
731
|
-
const
|
|
732
|
-
|
|
732
|
+
const [plan, selected, payloads, metrics = []] = args;
|
|
733
|
+
const compatibleSelected = coreStorage.SPAN_QUERY_FIELD_REGISTRY ? selected : selected.map((row) => ({
|
|
734
|
+
organizationId: row.organizationId,
|
|
735
|
+
resourceId: row.resourceId,
|
|
736
|
+
traceId: row.traceId,
|
|
737
|
+
spanId: row.spanId,
|
|
738
|
+
parentSpanId: row.parentSpanId,
|
|
739
|
+
name: row.name,
|
|
740
|
+
spanType: row.spanType,
|
|
741
|
+
status: row.status,
|
|
742
|
+
startedAt: row.startedAt,
|
|
743
|
+
endedAt: row.endedAt,
|
|
744
|
+
durationMs: row.durationMs,
|
|
745
|
+
entityType: row.entityType,
|
|
746
|
+
entityId: row.entityId,
|
|
747
|
+
entityName: row.entityName,
|
|
748
|
+
model: row.model,
|
|
749
|
+
provider: row.provider
|
|
750
|
+
}));
|
|
751
|
+
if (canGeneratePreviews) return coreStorage.buildSpanQueryResponse(plan, compatibleSelected, payloads, metrics);
|
|
752
|
+
const response = coreStorage.buildSpanQueryResponse(plan, compatibleSelected, [], metrics);
|
|
733
753
|
const byIdentity = new Map(payloads.map((payload) => [coreStorage.spanQueryIdentityKey(payload), payload]));
|
|
734
754
|
for (const span of response.spans) {
|
|
735
755
|
const payload = byIdentity.get(coreStorage.spanQueryIdentityKey(span));
|
|
@@ -1606,7 +1626,10 @@ async function getStreamHeadCursor$2(db) {
|
|
|
1606
1626
|
}
|
|
1607
1627
|
//#endregion
|
|
1608
1628
|
//#region src/storage/domains/observability/metrics.ts
|
|
1609
|
-
const METRIC_FILTER_FIELD_MAPPINGS = {
|
|
1629
|
+
const METRIC_FILTER_FIELD_MAPPINGS = {
|
|
1630
|
+
traceIds: "traceId",
|
|
1631
|
+
experimentIds: "experimentId"
|
|
1632
|
+
};
|
|
1610
1633
|
function resolveDistinctColumnSql(distinctColumn) {
|
|
1611
1634
|
if (!distinctColumn) throw new Error(`count_distinct aggregation requires a 'distinctColumn' argument`);
|
|
1612
1635
|
if (!METRIC_DISTINCT_COLUMNS.includes(distinctColumn)) throw new Error(`Invalid distinctColumn: ${distinctColumn}`);
|
|
@@ -2952,6 +2975,73 @@ const SPAN_FIELDS = {
|
|
|
2952
2975
|
parameterType: "scalar"
|
|
2953
2976
|
}
|
|
2954
2977
|
};
|
|
2978
|
+
const SPAN_QUERY_FIELDS = {
|
|
2979
|
+
...SPAN_FIELDS,
|
|
2980
|
+
traceId: {
|
|
2981
|
+
sql: "s.traceId",
|
|
2982
|
+
parameterType: "scalar"
|
|
2983
|
+
},
|
|
2984
|
+
spanId: {
|
|
2985
|
+
sql: "s.spanId",
|
|
2986
|
+
parameterType: "scalar"
|
|
2987
|
+
},
|
|
2988
|
+
parentSpanId: {
|
|
2989
|
+
sql: "s.parentSpanId",
|
|
2990
|
+
parameterType: "scalar"
|
|
2991
|
+
},
|
|
2992
|
+
threadId: {
|
|
2993
|
+
sql: "s.threadId",
|
|
2994
|
+
parameterType: "scalar"
|
|
2995
|
+
},
|
|
2996
|
+
resourceId: {
|
|
2997
|
+
sql: "s.resourceId",
|
|
2998
|
+
parameterType: "scalar"
|
|
2999
|
+
},
|
|
3000
|
+
requestId: {
|
|
3001
|
+
sql: "s.requestId",
|
|
3002
|
+
parameterType: "scalar"
|
|
3003
|
+
},
|
|
3004
|
+
serviceName: {
|
|
3005
|
+
sql: "s.serviceName",
|
|
3006
|
+
parameterType: "scalar"
|
|
3007
|
+
},
|
|
3008
|
+
experimentId: {
|
|
3009
|
+
sql: "s.experimentId",
|
|
3010
|
+
parameterType: "scalar"
|
|
3011
|
+
},
|
|
3012
|
+
environment: {
|
|
3013
|
+
sql: "s.environment",
|
|
3014
|
+
parameterType: "scalar"
|
|
3015
|
+
},
|
|
3016
|
+
executionSource: {
|
|
3017
|
+
sql: "s.executionSource",
|
|
3018
|
+
parameterType: "scalar"
|
|
3019
|
+
},
|
|
3020
|
+
parentEntityType: {
|
|
3021
|
+
sql: "s.parentEntityType",
|
|
3022
|
+
parameterType: "scalar"
|
|
3023
|
+
},
|
|
3024
|
+
parentEntityId: {
|
|
3025
|
+
sql: "s.parentEntityId",
|
|
3026
|
+
parameterType: "scalar"
|
|
3027
|
+
},
|
|
3028
|
+
parentEntityName: {
|
|
3029
|
+
sql: "s.parentEntityName",
|
|
3030
|
+
parameterType: "scalar"
|
|
3031
|
+
},
|
|
3032
|
+
rootEntityType: {
|
|
3033
|
+
sql: "s.rootEntityType",
|
|
3034
|
+
parameterType: "scalar"
|
|
3035
|
+
},
|
|
3036
|
+
rootEntityId: {
|
|
3037
|
+
sql: "s.rootEntityId",
|
|
3038
|
+
parameterType: "scalar"
|
|
3039
|
+
},
|
|
3040
|
+
rootEntityName: {
|
|
3041
|
+
sql: "s.rootEntityName",
|
|
3042
|
+
parameterType: "scalar"
|
|
3043
|
+
}
|
|
3044
|
+
};
|
|
2955
3045
|
const SCORE_FIELDS = {
|
|
2956
3046
|
scorerId: {
|
|
2957
3047
|
sql: "s.scorerId",
|
|
@@ -3832,9 +3922,9 @@ async function queryThreads(db, plan) {
|
|
|
3832
3922
|
}) : null }
|
|
3833
3923
|
});
|
|
3834
3924
|
}
|
|
3835
|
-
/** Compile a span-
|
|
3925
|
+
/** Compile a direct span-query filter using its dedicated field mapping. */
|
|
3836
3926
|
function compileSpanQueryPredicate(predicate) {
|
|
3837
|
-
return compileScalarPredicate(predicate,
|
|
3927
|
+
return compileScalarPredicate(predicate, SPAN_QUERY_FIELDS);
|
|
3838
3928
|
}
|
|
3839
3929
|
//#endregion
|
|
3840
3930
|
//#region src/storage/domains/observability/span-query.ts
|
|
@@ -3844,6 +3934,15 @@ const identityFields = [
|
|
|
3844
3934
|
"traceId",
|
|
3845
3935
|
"spanId"
|
|
3846
3936
|
];
|
|
3937
|
+
const missingFields = /* @__PURE__ */ new Set([
|
|
3938
|
+
"parentEntityType",
|
|
3939
|
+
"parentEntityId",
|
|
3940
|
+
"parentEntityName",
|
|
3941
|
+
"rootEntityType",
|
|
3942
|
+
"rootEntityId",
|
|
3943
|
+
"rootEntityName",
|
|
3944
|
+
"executionSource"
|
|
3945
|
+
]);
|
|
3847
3946
|
const identities = identityFields.join(", ");
|
|
3848
3947
|
const fields = [
|
|
3849
3948
|
...identityFields,
|
|
@@ -3854,11 +3953,23 @@ const fields = [
|
|
|
3854
3953
|
"entityId",
|
|
3855
3954
|
"entityName",
|
|
3856
3955
|
"entityVersionId",
|
|
3956
|
+
"parentEntityType",
|
|
3957
|
+
"parentEntityId",
|
|
3958
|
+
"parentEntityName",
|
|
3857
3959
|
"parentEntityVersionId",
|
|
3960
|
+
"rootEntityType",
|
|
3961
|
+
"rootEntityId",
|
|
3962
|
+
"rootEntityName",
|
|
3858
3963
|
"rootEntityVersionId",
|
|
3964
|
+
"threadId",
|
|
3859
3965
|
"runId",
|
|
3860
3966
|
"sessionId",
|
|
3861
|
-
"userId"
|
|
3967
|
+
"userId",
|
|
3968
|
+
"requestId",
|
|
3969
|
+
"serviceName",
|
|
3970
|
+
"experimentId",
|
|
3971
|
+
"environment",
|
|
3972
|
+
"executionSource"
|
|
3862
3973
|
];
|
|
3863
3974
|
function keys(rows, values, alias = "") {
|
|
3864
3975
|
return rows.map((row) => `(${identityFields.map((field) => {
|
|
@@ -3909,6 +4020,8 @@ function compileDuckDBSpanQuery(plan) {
|
|
|
3909
4020
|
const after = afterCursor(plan);
|
|
3910
4021
|
values.push(plan.timeRange.from, plan.timeRange.to, ...predicate.values, ...after.values, plan.limit + 1);
|
|
3911
4022
|
const join = identityFields.map((field) => `e.${field} IS NOT DISTINCT FROM c.${field}`).join(" AND ");
|
|
4023
|
+
const legacyModelFields = coreStorage.SPAN_QUERY_FIELD_REGISTRY ? "" : `CASE WHEN json_type(e.attributes, '$.model') = 'VARCHAR' THEN json_extract_string(e.attributes, '$.model') END AS model,
|
|
4024
|
+
CASE WHEN json_type(e.attributes, '$.provider') = 'VARCHAR' THEN json_extract_string(e.attributes, '$.provider') END AS provider,`;
|
|
3912
4025
|
return {
|
|
3913
4026
|
sql: `WITH candidates AS MATERIALIZED (
|
|
3914
4027
|
SELECT ${identities} FROM span_events
|
|
@@ -3916,10 +4029,9 @@ function compileDuckDBSpanQuery(plan) {
|
|
|
3916
4029
|
${scope.length ? `AND ${scope.join(" AND ")}` : ""}
|
|
3917
4030
|
GROUP BY ${identities}
|
|
3918
4031
|
), ranked AS (
|
|
3919
|
-
SELECT ${fields.map((field) => `e.${field}`).join(", ")},
|
|
4032
|
+
SELECT ${fields.map((field) => missingFields.has(field) ? `CAST(NULL AS VARCHAR) AS ${field}` : `e.${field}`).join(", ")},
|
|
3920
4033
|
min(e.timestamp) FILTER (WHERE e.eventType = 'start') OVER (PARTITION BY ${identityFields.map((field) => `e.${field}`).join(", ")}) AS startedAt, e.endedAt, e.cursorId,
|
|
3921
|
-
|
|
3922
|
-
CASE WHEN json_type(e.attributes, '$.provider') = 'VARCHAR' THEN json_extract_string(e.attributes, '$.provider') END AS provider,
|
|
4034
|
+
${legacyModelFields}
|
|
3923
4035
|
date_diff('millisecond', min(e.timestamp) FILTER (WHERE e.eventType = 'start') OVER (PARTITION BY ${identityFields.map((field) => `e.${field}`).join(", ")}), e.endedAt) AS durationMs,
|
|
3924
4036
|
CASE WHEN e.error IS NULL THEN 'success' ELSE 'error' END AS status,
|
|
3925
4037
|
CASE WHEN e.error IS NULL THEN NULL ELSE 'error' END AS error,
|
|
@@ -3928,15 +4040,7 @@ function compileDuckDBSpanQuery(plan) {
|
|
|
3928
4040
|
FROM span_events e INNER JOIN candidates c ON ${join}
|
|
3929
4041
|
)
|
|
3930
4042
|
SELECT ${[
|
|
3931
|
-
...
|
|
3932
|
-
"parentSpanId",
|
|
3933
|
-
"name",
|
|
3934
|
-
"spanType",
|
|
3935
|
-
"entityType",
|
|
3936
|
-
"entityId",
|
|
3937
|
-
"entityName",
|
|
3938
|
-
"model",
|
|
3939
|
-
"provider",
|
|
4043
|
+
...fields,
|
|
3940
4044
|
"startedAt",
|
|
3941
4045
|
"endedAt",
|
|
3942
4046
|
"durationMs",
|
|
@@ -3975,16 +4079,19 @@ async function querySpans(db, plan) {
|
|
|
3975
4079
|
endedAt: endedAt.toISOString()
|
|
3976
4080
|
}));
|
|
3977
4081
|
const page = rows.slice(0, plan.limit);
|
|
3978
|
-
if (!page.length) return
|
|
4082
|
+
if (!page.length) return buildSpanQueryResponse(plan, [], []);
|
|
3979
4083
|
const payloadValues = [];
|
|
3980
4084
|
const payloadWhere = page.map((row) => {
|
|
3981
4085
|
const key = keys([row], payloadValues);
|
|
3982
4086
|
payloadValues.push(row.cursorId, row.endedAt);
|
|
3983
4087
|
return `(${key} AND cursorId IS NOT DISTINCT FROM ? AND endedAt = ?)`;
|
|
3984
4088
|
}).join(" OR ");
|
|
3985
|
-
const
|
|
4089
|
+
const previewRows = await query(`SELECT DISTINCT ${identities},
|
|
4090
|
+
CASE WHEN json_type(attributes, '$.model') = 'VARCHAR' THEN json_extract_string(attributes, '$.model') END AS model,
|
|
4091
|
+
CASE WHEN json_type(attributes, '$.provider') = 'VARCHAR' THEN json_extract_string(attributes, '$.provider') END AS provider,
|
|
3986
4092
|
${previewPayloads.map(([preview, payload]) => `${preview}, CASE WHEN ${missingPreviewSql(preview)} THEN CAST(${payload} AS VARCHAR) END AS ${preview}Payload`).join(",\n ")}
|
|
3987
|
-
FROM span_events WHERE ${payloadWhere}`, payloadValues)
|
|
4093
|
+
FROM span_events WHERE ${payloadWhere}`, payloadValues);
|
|
4094
|
+
const payloads = previewRows.map((row) => {
|
|
3988
4095
|
const payload = {
|
|
3989
4096
|
organizationId: row.organizationId,
|
|
3990
4097
|
resourceId: row.resourceId,
|
|
@@ -4000,15 +4107,24 @@ async function querySpans(db, plan) {
|
|
|
4000
4107
|
}
|
|
4001
4108
|
return payload;
|
|
4002
4109
|
});
|
|
4003
|
-
const
|
|
4004
|
-
const
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
if (
|
|
4011
|
-
|
|
4110
|
+
const metadata = new Map(previewRows.map((row) => [coreStorage.spanQueryIdentityKey(row), row]));
|
|
4111
|
+
const hydrated = selected.map((row) => ({
|
|
4112
|
+
...row,
|
|
4113
|
+
model: metadata.get(coreStorage.spanQueryIdentityKey(row))?.model ?? null,
|
|
4114
|
+
provider: metadata.get(coreStorage.spanQueryIdentityKey(row))?.provider ?? null
|
|
4115
|
+
}));
|
|
4116
|
+
let metrics = [];
|
|
4117
|
+
if (!coreStorage.SPAN_QUERY_FIELD_REGISTRY) {
|
|
4118
|
+
const metricValues = [];
|
|
4119
|
+
const metricWhere = keys(page, metricValues);
|
|
4120
|
+
metrics = await query(`SELECT ${identities}, name, estimatedCost, costUnit,
|
|
4121
|
+
json_extract_string(costMetadata, '$.allocation') AS allocation,
|
|
4122
|
+
COALESCE(json_exists(costMetadata, '$.error'), false) AS costError
|
|
4123
|
+
FROM metric_events WHERE (${metricWhere}) AND name LIKE 'mastra_model_%'
|
|
4124
|
+
LIMIT ${coreStorage.SPAN_QUERY_MAX_COST_METRICS + 1}`, metricValues);
|
|
4125
|
+
if (metrics.length > coreStorage.SPAN_QUERY_MAX_COST_METRICS) throw new coreStorage.TraceQueryResourceLimitError();
|
|
4126
|
+
}
|
|
4127
|
+
return buildSpanQueryResponse(plan, hydrated, payloads, metrics);
|
|
4012
4128
|
}
|
|
4013
4129
|
//#endregion
|
|
4014
4130
|
//#region src/storage/domains/observability/trace-aggregate.ts
|
|
@@ -4343,6 +4459,7 @@ const COLUMNS_SQL = [
|
|
|
4343
4459
|
"spanType",
|
|
4344
4460
|
"isEvent",
|
|
4345
4461
|
"endedAt",
|
|
4462
|
+
"timeToFirstChunkMs",
|
|
4346
4463
|
"experimentId",
|
|
4347
4464
|
"entityType",
|
|
4348
4465
|
"entityId",
|
|
@@ -4830,6 +4947,7 @@ function toValuesTuple(row) {
|
|
|
4830
4947
|
v(row.spanType),
|
|
4831
4948
|
v(row.isEvent),
|
|
4832
4949
|
v(row.endedAt),
|
|
4950
|
+
v(row.timeToFirstChunkMs),
|
|
4833
4951
|
v(row.experimentId),
|
|
4834
4952
|
v(row.entityType),
|
|
4835
4953
|
v(row.entityId),
|
|
@@ -4882,6 +5000,7 @@ function createStartSpanRow(s) {
|
|
|
4882
5000
|
spanType: s.spanType,
|
|
4883
5001
|
isEvent: s.isEvent,
|
|
4884
5002
|
endedAt: s.isEvent ? s.startedAt : null,
|
|
5003
|
+
timeToFirstChunkMs: s.timeToFirstChunkMs ?? null,
|
|
4885
5004
|
experimentId: s.experimentId ?? null,
|
|
4886
5005
|
entityType: s.entityType ?? null,
|
|
4887
5006
|
entityId: s.entityId ?? null,
|
|
@@ -4930,6 +5049,7 @@ function createEndSpanRow(s) {
|
|
|
4930
5049
|
spanType: s.spanType,
|
|
4931
5050
|
isEvent: s.isEvent,
|
|
4932
5051
|
endedAt: s.endedAt ?? null,
|
|
5052
|
+
timeToFirstChunkMs: s.timeToFirstChunkMs ?? null,
|
|
4933
5053
|
experimentId: s.experimentId ?? null,
|
|
4934
5054
|
entityType: s.entityType ?? null,
|
|
4935
5055
|
entityId: s.entityId ?? null,
|
|
@@ -5966,4 +6086,4 @@ var ObservabilityStorageDuckDB = class ObservabilityStorageDuckDB extends Observ
|
|
|
5966
6086
|
//#endregion
|
|
5967
6087
|
export { ObservabilityStorageDuckDB };
|
|
5968
6088
|
|
|
5969
|
-
//# sourceMappingURL=observability-
|
|
6089
|
+
//# sourceMappingURL=observability-HUYFWVy-.js.map
|