@mastra/duckdb 1.14.1 → 1.15.0-alpha.1
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-BluQ-Iys.cjs} +147 -33
- package/dist/observability-BluQ-Iys.cjs.map +1 -0
- package/dist/{observability-CXUQZgpz.js → observability-DTTykJwa.js} +147 -33
- package/dist/observability-DTTykJwa.js.map +1 -0
- 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/features.d.ts +1 -1
- package/dist/storage/features.d.ts.map +1 -1
- package/package.json +3 -3
- 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";
|
|
@@ -727,9 +727,27 @@ function readPreview(preview, payload, jsonEncoded = false) {
|
|
|
727
727
|
}
|
|
728
728
|
/** Older response builders may shorten previews or turn empty strings into null. */
|
|
729
729
|
function buildSpanQueryResponse(...args) {
|
|
730
|
-
|
|
731
|
-
const
|
|
732
|
-
|
|
730
|
+
const [plan, selected, payloads, metrics = []] = args;
|
|
731
|
+
const compatibleSelected = coreStorage.SPAN_QUERY_FIELD_REGISTRY ? selected : selected.map((row) => ({
|
|
732
|
+
organizationId: row.organizationId,
|
|
733
|
+
resourceId: row.resourceId,
|
|
734
|
+
traceId: row.traceId,
|
|
735
|
+
spanId: row.spanId,
|
|
736
|
+
parentSpanId: row.parentSpanId,
|
|
737
|
+
name: row.name,
|
|
738
|
+
spanType: row.spanType,
|
|
739
|
+
status: row.status,
|
|
740
|
+
startedAt: row.startedAt,
|
|
741
|
+
endedAt: row.endedAt,
|
|
742
|
+
durationMs: row.durationMs,
|
|
743
|
+
entityType: row.entityType,
|
|
744
|
+
entityId: row.entityId,
|
|
745
|
+
entityName: row.entityName,
|
|
746
|
+
model: row.model,
|
|
747
|
+
provider: row.provider
|
|
748
|
+
}));
|
|
749
|
+
if (canGeneratePreviews) return coreStorage.buildSpanQueryResponse(plan, compatibleSelected, payloads, metrics);
|
|
750
|
+
const response = coreStorage.buildSpanQueryResponse(plan, compatibleSelected, [], metrics);
|
|
733
751
|
const byIdentity = new Map(payloads.map((payload) => [coreStorage.spanQueryIdentityKey(payload), payload]));
|
|
734
752
|
for (const span of response.spans) {
|
|
735
753
|
const payload = byIdentity.get(coreStorage.spanQueryIdentityKey(span));
|
|
@@ -1606,7 +1624,10 @@ async function getStreamHeadCursor$2(db) {
|
|
|
1606
1624
|
}
|
|
1607
1625
|
//#endregion
|
|
1608
1626
|
//#region src/storage/domains/observability/metrics.ts
|
|
1609
|
-
const METRIC_FILTER_FIELD_MAPPINGS = {
|
|
1627
|
+
const METRIC_FILTER_FIELD_MAPPINGS = {
|
|
1628
|
+
traceIds: "traceId",
|
|
1629
|
+
experimentIds: "experimentId"
|
|
1630
|
+
};
|
|
1610
1631
|
function resolveDistinctColumnSql(distinctColumn) {
|
|
1611
1632
|
if (!distinctColumn) throw new Error(`count_distinct aggregation requires a 'distinctColumn' argument`);
|
|
1612
1633
|
if (!METRIC_DISTINCT_COLUMNS.includes(distinctColumn)) throw new Error(`Invalid distinctColumn: ${distinctColumn}`);
|
|
@@ -2952,6 +2973,73 @@ const SPAN_FIELDS = {
|
|
|
2952
2973
|
parameterType: "scalar"
|
|
2953
2974
|
}
|
|
2954
2975
|
};
|
|
2976
|
+
const SPAN_QUERY_FIELDS = {
|
|
2977
|
+
...SPAN_FIELDS,
|
|
2978
|
+
traceId: {
|
|
2979
|
+
sql: "s.traceId",
|
|
2980
|
+
parameterType: "scalar"
|
|
2981
|
+
},
|
|
2982
|
+
spanId: {
|
|
2983
|
+
sql: "s.spanId",
|
|
2984
|
+
parameterType: "scalar"
|
|
2985
|
+
},
|
|
2986
|
+
parentSpanId: {
|
|
2987
|
+
sql: "s.parentSpanId",
|
|
2988
|
+
parameterType: "scalar"
|
|
2989
|
+
},
|
|
2990
|
+
threadId: {
|
|
2991
|
+
sql: "s.threadId",
|
|
2992
|
+
parameterType: "scalar"
|
|
2993
|
+
},
|
|
2994
|
+
resourceId: {
|
|
2995
|
+
sql: "s.resourceId",
|
|
2996
|
+
parameterType: "scalar"
|
|
2997
|
+
},
|
|
2998
|
+
requestId: {
|
|
2999
|
+
sql: "s.requestId",
|
|
3000
|
+
parameterType: "scalar"
|
|
3001
|
+
},
|
|
3002
|
+
serviceName: {
|
|
3003
|
+
sql: "s.serviceName",
|
|
3004
|
+
parameterType: "scalar"
|
|
3005
|
+
},
|
|
3006
|
+
experimentId: {
|
|
3007
|
+
sql: "s.experimentId",
|
|
3008
|
+
parameterType: "scalar"
|
|
3009
|
+
},
|
|
3010
|
+
environment: {
|
|
3011
|
+
sql: "s.environment",
|
|
3012
|
+
parameterType: "scalar"
|
|
3013
|
+
},
|
|
3014
|
+
executionSource: {
|
|
3015
|
+
sql: "s.executionSource",
|
|
3016
|
+
parameterType: "scalar"
|
|
3017
|
+
},
|
|
3018
|
+
parentEntityType: {
|
|
3019
|
+
sql: "s.parentEntityType",
|
|
3020
|
+
parameterType: "scalar"
|
|
3021
|
+
},
|
|
3022
|
+
parentEntityId: {
|
|
3023
|
+
sql: "s.parentEntityId",
|
|
3024
|
+
parameterType: "scalar"
|
|
3025
|
+
},
|
|
3026
|
+
parentEntityName: {
|
|
3027
|
+
sql: "s.parentEntityName",
|
|
3028
|
+
parameterType: "scalar"
|
|
3029
|
+
},
|
|
3030
|
+
rootEntityType: {
|
|
3031
|
+
sql: "s.rootEntityType",
|
|
3032
|
+
parameterType: "scalar"
|
|
3033
|
+
},
|
|
3034
|
+
rootEntityId: {
|
|
3035
|
+
sql: "s.rootEntityId",
|
|
3036
|
+
parameterType: "scalar"
|
|
3037
|
+
},
|
|
3038
|
+
rootEntityName: {
|
|
3039
|
+
sql: "s.rootEntityName",
|
|
3040
|
+
parameterType: "scalar"
|
|
3041
|
+
}
|
|
3042
|
+
};
|
|
2955
3043
|
const SCORE_FIELDS = {
|
|
2956
3044
|
scorerId: {
|
|
2957
3045
|
sql: "s.scorerId",
|
|
@@ -3832,9 +3920,9 @@ async function queryThreads(db, plan) {
|
|
|
3832
3920
|
}) : null }
|
|
3833
3921
|
});
|
|
3834
3922
|
}
|
|
3835
|
-
/** Compile a span-
|
|
3923
|
+
/** Compile a direct span-query filter using its dedicated field mapping. */
|
|
3836
3924
|
function compileSpanQueryPredicate(predicate) {
|
|
3837
|
-
return compileScalarPredicate(predicate,
|
|
3925
|
+
return compileScalarPredicate(predicate, SPAN_QUERY_FIELDS);
|
|
3838
3926
|
}
|
|
3839
3927
|
//#endregion
|
|
3840
3928
|
//#region src/storage/domains/observability/span-query.ts
|
|
@@ -3844,6 +3932,15 @@ const identityFields = [
|
|
|
3844
3932
|
"traceId",
|
|
3845
3933
|
"spanId"
|
|
3846
3934
|
];
|
|
3935
|
+
const missingFields = /* @__PURE__ */ new Set([
|
|
3936
|
+
"parentEntityType",
|
|
3937
|
+
"parentEntityId",
|
|
3938
|
+
"parentEntityName",
|
|
3939
|
+
"rootEntityType",
|
|
3940
|
+
"rootEntityId",
|
|
3941
|
+
"rootEntityName",
|
|
3942
|
+
"executionSource"
|
|
3943
|
+
]);
|
|
3847
3944
|
const identities = identityFields.join(", ");
|
|
3848
3945
|
const fields = [
|
|
3849
3946
|
...identityFields,
|
|
@@ -3854,11 +3951,23 @@ const fields = [
|
|
|
3854
3951
|
"entityId",
|
|
3855
3952
|
"entityName",
|
|
3856
3953
|
"entityVersionId",
|
|
3954
|
+
"parentEntityType",
|
|
3955
|
+
"parentEntityId",
|
|
3956
|
+
"parentEntityName",
|
|
3857
3957
|
"parentEntityVersionId",
|
|
3958
|
+
"rootEntityType",
|
|
3959
|
+
"rootEntityId",
|
|
3960
|
+
"rootEntityName",
|
|
3858
3961
|
"rootEntityVersionId",
|
|
3962
|
+
"threadId",
|
|
3859
3963
|
"runId",
|
|
3860
3964
|
"sessionId",
|
|
3861
|
-
"userId"
|
|
3965
|
+
"userId",
|
|
3966
|
+
"requestId",
|
|
3967
|
+
"serviceName",
|
|
3968
|
+
"experimentId",
|
|
3969
|
+
"environment",
|
|
3970
|
+
"executionSource"
|
|
3862
3971
|
];
|
|
3863
3972
|
function keys(rows, values, alias = "") {
|
|
3864
3973
|
return rows.map((row) => `(${identityFields.map((field) => {
|
|
@@ -3909,6 +4018,8 @@ function compileDuckDBSpanQuery(plan) {
|
|
|
3909
4018
|
const after = afterCursor(plan);
|
|
3910
4019
|
values.push(plan.timeRange.from, plan.timeRange.to, ...predicate.values, ...after.values, plan.limit + 1);
|
|
3911
4020
|
const join = identityFields.map((field) => `e.${field} IS NOT DISTINCT FROM c.${field}`).join(" AND ");
|
|
4021
|
+
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,
|
|
4022
|
+
CASE WHEN json_type(e.attributes, '$.provider') = 'VARCHAR' THEN json_extract_string(e.attributes, '$.provider') END AS provider,`;
|
|
3912
4023
|
return {
|
|
3913
4024
|
sql: `WITH candidates AS MATERIALIZED (
|
|
3914
4025
|
SELECT ${identities} FROM span_events
|
|
@@ -3916,10 +4027,9 @@ function compileDuckDBSpanQuery(plan) {
|
|
|
3916
4027
|
${scope.length ? `AND ${scope.join(" AND ")}` : ""}
|
|
3917
4028
|
GROUP BY ${identities}
|
|
3918
4029
|
), ranked AS (
|
|
3919
|
-
SELECT ${fields.map((field) => `e.${field}`).join(", ")},
|
|
4030
|
+
SELECT ${fields.map((field) => missingFields.has(field) ? `CAST(NULL AS VARCHAR) AS ${field}` : `e.${field}`).join(", ")},
|
|
3920
4031
|
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,
|
|
4032
|
+
${legacyModelFields}
|
|
3923
4033
|
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
4034
|
CASE WHEN e.error IS NULL THEN 'success' ELSE 'error' END AS status,
|
|
3925
4035
|
CASE WHEN e.error IS NULL THEN NULL ELSE 'error' END AS error,
|
|
@@ -3928,15 +4038,7 @@ function compileDuckDBSpanQuery(plan) {
|
|
|
3928
4038
|
FROM span_events e INNER JOIN candidates c ON ${join}
|
|
3929
4039
|
)
|
|
3930
4040
|
SELECT ${[
|
|
3931
|
-
...
|
|
3932
|
-
"parentSpanId",
|
|
3933
|
-
"name",
|
|
3934
|
-
"spanType",
|
|
3935
|
-
"entityType",
|
|
3936
|
-
"entityId",
|
|
3937
|
-
"entityName",
|
|
3938
|
-
"model",
|
|
3939
|
-
"provider",
|
|
4041
|
+
...fields,
|
|
3940
4042
|
"startedAt",
|
|
3941
4043
|
"endedAt",
|
|
3942
4044
|
"durationMs",
|
|
@@ -3975,16 +4077,19 @@ async function querySpans(db, plan) {
|
|
|
3975
4077
|
endedAt: endedAt.toISOString()
|
|
3976
4078
|
}));
|
|
3977
4079
|
const page = rows.slice(0, plan.limit);
|
|
3978
|
-
if (!page.length) return
|
|
4080
|
+
if (!page.length) return buildSpanQueryResponse(plan, [], []);
|
|
3979
4081
|
const payloadValues = [];
|
|
3980
4082
|
const payloadWhere = page.map((row) => {
|
|
3981
4083
|
const key = keys([row], payloadValues);
|
|
3982
4084
|
payloadValues.push(row.cursorId, row.endedAt);
|
|
3983
4085
|
return `(${key} AND cursorId IS NOT DISTINCT FROM ? AND endedAt = ?)`;
|
|
3984
4086
|
}).join(" OR ");
|
|
3985
|
-
const
|
|
4087
|
+
const previewRows = await query(`SELECT DISTINCT ${identities},
|
|
4088
|
+
CASE WHEN json_type(attributes, '$.model') = 'VARCHAR' THEN json_extract_string(attributes, '$.model') END AS model,
|
|
4089
|
+
CASE WHEN json_type(attributes, '$.provider') = 'VARCHAR' THEN json_extract_string(attributes, '$.provider') END AS provider,
|
|
3986
4090
|
${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)
|
|
4091
|
+
FROM span_events WHERE ${payloadWhere}`, payloadValues);
|
|
4092
|
+
const payloads = previewRows.map((row) => {
|
|
3988
4093
|
const payload = {
|
|
3989
4094
|
organizationId: row.organizationId,
|
|
3990
4095
|
resourceId: row.resourceId,
|
|
@@ -4000,15 +4105,24 @@ async function querySpans(db, plan) {
|
|
|
4000
4105
|
}
|
|
4001
4106
|
return payload;
|
|
4002
4107
|
});
|
|
4003
|
-
const
|
|
4004
|
-
const
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
if (
|
|
4011
|
-
|
|
4108
|
+
const metadata = new Map(previewRows.map((row) => [coreStorage.spanQueryIdentityKey(row), row]));
|
|
4109
|
+
const hydrated = selected.map((row) => ({
|
|
4110
|
+
...row,
|
|
4111
|
+
model: metadata.get(coreStorage.spanQueryIdentityKey(row))?.model ?? null,
|
|
4112
|
+
provider: metadata.get(coreStorage.spanQueryIdentityKey(row))?.provider ?? null
|
|
4113
|
+
}));
|
|
4114
|
+
let metrics = [];
|
|
4115
|
+
if (!coreStorage.SPAN_QUERY_FIELD_REGISTRY) {
|
|
4116
|
+
const metricValues = [];
|
|
4117
|
+
const metricWhere = keys(page, metricValues);
|
|
4118
|
+
metrics = await query(`SELECT ${identities}, name, estimatedCost, costUnit,
|
|
4119
|
+
json_extract_string(costMetadata, '$.allocation') AS allocation,
|
|
4120
|
+
COALESCE(json_exists(costMetadata, '$.error'), false) AS costError
|
|
4121
|
+
FROM metric_events WHERE (${metricWhere}) AND name LIKE 'mastra_model_%'
|
|
4122
|
+
LIMIT ${coreStorage.SPAN_QUERY_MAX_COST_METRICS + 1}`, metricValues);
|
|
4123
|
+
if (metrics.length > coreStorage.SPAN_QUERY_MAX_COST_METRICS) throw new coreStorage.TraceQueryResourceLimitError();
|
|
4124
|
+
}
|
|
4125
|
+
return buildSpanQueryResponse(plan, hydrated, payloads, metrics);
|
|
4012
4126
|
}
|
|
4013
4127
|
//#endregion
|
|
4014
4128
|
//#region src/storage/domains/observability/trace-aggregate.ts
|
|
@@ -5966,4 +6080,4 @@ var ObservabilityStorageDuckDB = class ObservabilityStorageDuckDB extends Observ
|
|
|
5966
6080
|
//#endregion
|
|
5967
6081
|
export { ObservabilityStorageDuckDB };
|
|
5968
6082
|
|
|
5969
|
-
//# sourceMappingURL=observability-
|
|
6083
|
+
//# sourceMappingURL=observability-DTTykJwa.js.map
|