@mastra/server 1.75.0-alpha.3 → 1.75.0-alpha.4
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/{api-schema-manifest-D9_jxxNw.cjs → api-schema-manifest-BmNlBOvP.cjs} +2 -2
- package/dist/{api-schema-manifest-D9_jxxNw.cjs.map → api-schema-manifest-BmNlBOvP.cjs.map} +1 -1
- package/dist/{api-schema-manifest-B0p6nxU1.js → api-schema-manifest-Bsnp8kpD.js} +2 -2
- package/dist/{api-schema-manifest-B0p6nxU1.js.map → api-schema-manifest-Bsnp8kpD.js.map} +1 -1
- package/dist/docs/SKILL.md +2 -2
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-observability-tracing-trace-query.md +65 -4
- package/dist/{observability-new-endpoints-lNC3o66-.js → observability-new-endpoints-DQuhr8aL.js} +114 -4
- package/dist/observability-new-endpoints-DQuhr8aL.js.map +1 -0
- package/dist/{observability-new-endpoints-7Zd6uEZf.cjs → observability-new-endpoints-Kphyk3do.cjs} +118 -2
- package/dist/observability-new-endpoints-Kphyk3do.cjs.map +1 -0
- package/dist/{routes-CJygX0-a.js → routes--Al6ya95.js} +3 -2
- package/dist/routes--Al6ya95.js.map +1 -0
- package/dist/{routes-BuiLQCOQ.cjs → routes-CeYKJ-Re.cjs} +3 -2
- package/dist/routes-CeYKJ-Re.cjs.map +1 -0
- package/dist/server/handlers/observability-new-endpoints.cjs +2 -1
- package/dist/server/handlers/observability-new-endpoints.d.ts +260 -0
- package/dist/server/handlers/observability-new-endpoints.d.ts.map +1 -1
- package/dist/server/handlers/observability-new-endpoints.js +2 -2
- package/dist/server/handlers/observability-shared.cjs +19 -0
- package/dist/server/handlers/observability-shared.cjs.map +1 -1
- package/dist/server/handlers/observability-shared.d.ts +10 -0
- package/dist/server/handlers/observability-shared.d.ts.map +1 -1
- package/dist/server/handlers/observability-shared.js +18 -1
- package/dist/server/handlers/observability-shared.js.map +1 -1
- package/dist/server/handlers/observability.cjs +3 -1
- package/dist/server/handlers/observability.cjs.map +1 -1
- package/dist/server/handlers/observability.js +3 -2
- package/dist/server/handlers/observability.js.map +1 -1
- package/dist/server/handlers/system.cjs +2 -2
- package/dist/server/handlers/system.d.ts +2 -0
- package/dist/server/handlers/system.d.ts.map +1 -1
- package/dist/server/handlers/system.js +2 -2
- package/dist/server/schemas/index.cjs +1 -1
- package/dist/server/schemas/index.js +1 -1
- package/dist/server/schemas/system.d.ts +2 -0
- package/dist/server/schemas/system.d.ts.map +1 -1
- package/dist/server/server-adapter/index.cjs +1 -1
- package/dist/server/server-adapter/index.js +1 -1
- package/dist/server/server-adapter/routes/observability.d.ts +129 -0
- package/dist/server/server-adapter/routes/observability.d.ts.map +1 -1
- package/dist/server/server-adapter/routes/system.d.ts +2 -0
- package/dist/server/server-adapter/routes/system.d.ts.map +1 -1
- package/dist/{system-CskEzH1o.cjs → system-Be5n6H_z.cjs} +2 -1
- package/dist/system-Be5n6H_z.cjs.map +1 -0
- package/dist/{system-6qFm79mm.js → system-BtGAJr9R.js} +2 -1
- package/dist/system-BtGAJr9R.js.map +1 -0
- package/package.json +6 -6
- package/dist/observability-new-endpoints-7Zd6uEZf.cjs.map +0 -1
- package/dist/observability-new-endpoints-lNC3o66-.js.map +0 -1
- package/dist/routes-BuiLQCOQ.cjs.map +0 -1
- package/dist/routes-CJygX0-a.js.map +0 -1
- package/dist/system-6qFm79mm.js.map +0 -1
- package/dist/system-CskEzH1o.cjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require("./rolldown-runtime-Bd6kNlEP.cjs");
|
|
2
2
|
const require_route_builder = require("./route-builder-2yrD15TL.cjs");
|
|
3
|
-
const require_routes = require("./routes-
|
|
3
|
+
const require_routes = require("./routes-CeYKJ-Re.cjs");
|
|
4
4
|
//#region src/server/server-adapter/api-schema-manifest.ts
|
|
5
5
|
function convertSchema(schema) {
|
|
6
6
|
return schema ? require_route_builder.schemaToJsonSchema(schema) : void 0;
|
|
@@ -53,4 +53,4 @@ function buildApiSchemaManifest(routes = require_routes.SERVER_ROUTES) {
|
|
|
53
53
|
//#endregion
|
|
54
54
|
exports.buildApiSchemaManifest = buildApiSchemaManifest;
|
|
55
55
|
|
|
56
|
-
//# sourceMappingURL=api-schema-manifest-
|
|
56
|
+
//# sourceMappingURL=api-schema-manifest-BmNlBOvP.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-schema-manifest-
|
|
1
|
+
{"version":3,"file":"api-schema-manifest-BmNlBOvP.cjs","names":["schemaToJsonSchema","SERVER_ROUTES"],"sources":["../src/server/server-adapter/api-schema-manifest.ts"],"sourcesContent":["import type { JSONSchema7 } from '@mastra/schema-compat';\nimport { schemaToJsonSchema } from './openapi-utils';\nimport { SERVER_ROUTES } from './routes/index';\nimport type { ServerRoute } from './routes/index';\n\nexport interface ApiSchemaResponseShape {\n kind: 'array' | 'record' | 'object-property' | 'single' | 'unknown';\n listProperty?: string;\n paginationProperty?: string;\n}\n\nexport interface ApiSchemaManifestRoute {\n method: string;\n path: string;\n responseType: string;\n pathParamSchema?: JSONSchema7;\n queryParamSchema?: JSONSchema7;\n bodySchema?: JSONSchema7;\n responseSchema?: JSONSchema7;\n responseShape: ApiSchemaResponseShape;\n}\n\nexport interface ApiSchemaManifest {\n version: 1;\n routes: ApiSchemaManifestRoute[];\n}\n\nfunction convertSchema(schema: ServerRoute['bodySchema']): JSONSchema7 | undefined {\n return schema ? schemaToJsonSchema(schema) : undefined;\n}\n\nfunction asJsonSchema(value: unknown): JSONSchema7 | undefined {\n return value && typeof value === 'object' && !Array.isArray(value) ? (value as JSONSchema7) : undefined;\n}\n\nfunction schemaType(schema: JSONSchema7 | undefined): JSONSchema7['type'] | undefined {\n const type = schema?.type;\n return Array.isArray(type) ? type.find(Boolean) : type;\n}\n\nfunction inferResponseShape(responseSchema: JSONSchema7 | undefined): ApiSchemaResponseShape {\n if (!responseSchema) return { kind: 'unknown' };\n\n const type = schemaType(responseSchema);\n if (type === 'array') return { kind: 'array' };\n if (type !== 'object') return { kind: 'single' };\n\n const properties =\n responseSchema.properties && !Array.isArray(responseSchema.properties) ? responseSchema.properties : {};\n const propertyNames = Object.keys(properties);\n const paginationProperty = 'page' in properties ? 'page' : 'pagination' in properties ? 'pagination' : undefined;\n const listProperty = Object.entries(properties).find(\n ([, property]) => schemaType(asJsonSchema(property)) === 'array',\n )?.[0];\n\n if (listProperty && (paginationProperty || propertyNames.length <= 2)) {\n return { kind: 'object-property', listProperty, paginationProperty };\n }\n if (responseSchema.additionalProperties && propertyNames.length === 0) return { kind: 'record' };\n return { kind: 'single' };\n}\n\nfunction isManifestRoute(route: ServerRoute): boolean {\n return route.responseType === 'json' && !route.deprecated;\n}\n\nexport function buildApiSchemaManifest(routes: readonly ServerRoute[] = SERVER_ROUTES): ApiSchemaManifest {\n return {\n version: 1,\n routes: routes.filter(isManifestRoute).map(route => {\n const responseSchema = convertSchema(route.responseSchema);\n return {\n method: route.method,\n path: route.path,\n responseType: route.responseType,\n pathParamSchema: convertSchema(route.pathParamSchema),\n queryParamSchema: convertSchema(route.queryParamSchema),\n bodySchema: convertSchema(route.bodySchema),\n responseSchema,\n responseShape: inferResponseShape(responseSchema),\n };\n }),\n };\n}\n"],"mappings":";;;;AA2BA,SAAS,cAAc,QAA4D;CACjF,OAAO,SAASA,sBAAAA,mBAAmB,MAAM,IAAI,KAAA;AAC/C;AAEA,SAAS,aAAa,OAAyC;CAC7D,OAAO,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAAK,QAAwB,KAAA;AAChG;AAEA,SAAS,WAAW,QAAkE;CACpF,MAAM,OAAO,QAAQ;CACrB,OAAO,MAAM,QAAQ,IAAI,IAAI,KAAK,KAAK,OAAO,IAAI;AACpD;AAEA,SAAS,mBAAmB,gBAAiE;CAC3F,IAAI,CAAC,gBAAgB,OAAO,EAAE,MAAM,UAAU;CAE9C,MAAM,OAAO,WAAW,cAAc;CACtC,IAAI,SAAS,SAAS,OAAO,EAAE,MAAM,QAAQ;CAC7C,IAAI,SAAS,UAAU,OAAO,EAAE,MAAM,SAAS;CAE/C,MAAM,aACJ,eAAe,cAAc,CAAC,MAAM,QAAQ,eAAe,UAAU,IAAI,eAAe,aAAa,CAAC;CACxG,MAAM,gBAAgB,OAAO,KAAK,UAAU;CAC5C,MAAM,qBAAqB,UAAU,aAAa,SAAS,gBAAgB,aAAa,eAAe,KAAA;CACvG,MAAM,eAAe,OAAO,QAAQ,UAAU,CAAC,CAAC,MAC7C,GAAG,cAAc,WAAW,aAAa,QAAQ,CAAC,MAAM,OAC3D,CAAC,GAAG;CAEJ,IAAI,iBAAiB,sBAAsB,cAAc,UAAU,IACjE,OAAO;EAAE,MAAM;EAAmB;EAAc;CAAmB;CAErE,IAAI,eAAe,wBAAwB,cAAc,WAAW,GAAG,OAAO,EAAE,MAAM,SAAS;CAC/F,OAAO,EAAE,MAAM,SAAS;AAC1B;AAEA,SAAS,gBAAgB,OAA6B;CACpD,OAAO,MAAM,iBAAiB,UAAU,CAAC,MAAM;AACjD;AAEA,SAAgB,uBAAuB,SAAiCC,eAAAA,eAAkC;CACxG,OAAO;EACL,SAAS;EACT,QAAQ,OAAO,OAAO,eAAe,CAAC,CAAC,KAAI,UAAS;GAClD,MAAM,iBAAiB,cAAc,MAAM,cAAc;GACzD,OAAO;IACL,QAAQ,MAAM;IACd,MAAM,MAAM;IACZ,cAAc,MAAM;IACpB,iBAAiB,cAAc,MAAM,eAAe;IACpD,kBAAkB,cAAc,MAAM,gBAAgB;IACtD,YAAY,cAAc,MAAM,UAAU;IAC1C;IACA,eAAe,mBAAmB,cAAc;GAClD;EACF,CAAC;CACH;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as schemaToJsonSchema } from "./route-builder-lBil8Cvo.js";
|
|
2
|
-
import { t as SERVER_ROUTES } from "./routes
|
|
2
|
+
import { t as SERVER_ROUTES } from "./routes--Al6ya95.js";
|
|
3
3
|
//#region src/server/server-adapter/api-schema-manifest.ts
|
|
4
4
|
function convertSchema(schema) {
|
|
5
5
|
return schema ? schemaToJsonSchema(schema) : void 0;
|
|
@@ -52,4 +52,4 @@ function buildApiSchemaManifest(routes = SERVER_ROUTES) {
|
|
|
52
52
|
//#endregion
|
|
53
53
|
export { buildApiSchemaManifest };
|
|
54
54
|
|
|
55
|
-
//# sourceMappingURL=api-schema-manifest-
|
|
55
|
+
//# sourceMappingURL=api-schema-manifest-Bsnp8kpD.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-schema-manifest-
|
|
1
|
+
{"version":3,"file":"api-schema-manifest-Bsnp8kpD.js","names":[],"sources":["../src/server/server-adapter/api-schema-manifest.ts"],"sourcesContent":["import type { JSONSchema7 } from '@mastra/schema-compat';\nimport { schemaToJsonSchema } from './openapi-utils';\nimport { SERVER_ROUTES } from './routes/index';\nimport type { ServerRoute } from './routes/index';\n\nexport interface ApiSchemaResponseShape {\n kind: 'array' | 'record' | 'object-property' | 'single' | 'unknown';\n listProperty?: string;\n paginationProperty?: string;\n}\n\nexport interface ApiSchemaManifestRoute {\n method: string;\n path: string;\n responseType: string;\n pathParamSchema?: JSONSchema7;\n queryParamSchema?: JSONSchema7;\n bodySchema?: JSONSchema7;\n responseSchema?: JSONSchema7;\n responseShape: ApiSchemaResponseShape;\n}\n\nexport interface ApiSchemaManifest {\n version: 1;\n routes: ApiSchemaManifestRoute[];\n}\n\nfunction convertSchema(schema: ServerRoute['bodySchema']): JSONSchema7 | undefined {\n return schema ? schemaToJsonSchema(schema) : undefined;\n}\n\nfunction asJsonSchema(value: unknown): JSONSchema7 | undefined {\n return value && typeof value === 'object' && !Array.isArray(value) ? (value as JSONSchema7) : undefined;\n}\n\nfunction schemaType(schema: JSONSchema7 | undefined): JSONSchema7['type'] | undefined {\n const type = schema?.type;\n return Array.isArray(type) ? type.find(Boolean) : type;\n}\n\nfunction inferResponseShape(responseSchema: JSONSchema7 | undefined): ApiSchemaResponseShape {\n if (!responseSchema) return { kind: 'unknown' };\n\n const type = schemaType(responseSchema);\n if (type === 'array') return { kind: 'array' };\n if (type !== 'object') return { kind: 'single' };\n\n const properties =\n responseSchema.properties && !Array.isArray(responseSchema.properties) ? responseSchema.properties : {};\n const propertyNames = Object.keys(properties);\n const paginationProperty = 'page' in properties ? 'page' : 'pagination' in properties ? 'pagination' : undefined;\n const listProperty = Object.entries(properties).find(\n ([, property]) => schemaType(asJsonSchema(property)) === 'array',\n )?.[0];\n\n if (listProperty && (paginationProperty || propertyNames.length <= 2)) {\n return { kind: 'object-property', listProperty, paginationProperty };\n }\n if (responseSchema.additionalProperties && propertyNames.length === 0) return { kind: 'record' };\n return { kind: 'single' };\n}\n\nfunction isManifestRoute(route: ServerRoute): boolean {\n return route.responseType === 'json' && !route.deprecated;\n}\n\nexport function buildApiSchemaManifest(routes: readonly ServerRoute[] = SERVER_ROUTES): ApiSchemaManifest {\n return {\n version: 1,\n routes: routes.filter(isManifestRoute).map(route => {\n const responseSchema = convertSchema(route.responseSchema);\n return {\n method: route.method,\n path: route.path,\n responseType: route.responseType,\n pathParamSchema: convertSchema(route.pathParamSchema),\n queryParamSchema: convertSchema(route.queryParamSchema),\n bodySchema: convertSchema(route.bodySchema),\n responseSchema,\n responseShape: inferResponseShape(responseSchema),\n };\n }),\n };\n}\n"],"mappings":";;;AA2BA,SAAS,cAAc,QAA4D;CACjF,OAAO,SAAS,mBAAmB,MAAM,IAAI,KAAA;AAC/C;AAEA,SAAS,aAAa,OAAyC;CAC7D,OAAO,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAAK,QAAwB,KAAA;AAChG;AAEA,SAAS,WAAW,QAAkE;CACpF,MAAM,OAAO,QAAQ;CACrB,OAAO,MAAM,QAAQ,IAAI,IAAI,KAAK,KAAK,OAAO,IAAI;AACpD;AAEA,SAAS,mBAAmB,gBAAiE;CAC3F,IAAI,CAAC,gBAAgB,OAAO,EAAE,MAAM,UAAU;CAE9C,MAAM,OAAO,WAAW,cAAc;CACtC,IAAI,SAAS,SAAS,OAAO,EAAE,MAAM,QAAQ;CAC7C,IAAI,SAAS,UAAU,OAAO,EAAE,MAAM,SAAS;CAE/C,MAAM,aACJ,eAAe,cAAc,CAAC,MAAM,QAAQ,eAAe,UAAU,IAAI,eAAe,aAAa,CAAC;CACxG,MAAM,gBAAgB,OAAO,KAAK,UAAU;CAC5C,MAAM,qBAAqB,UAAU,aAAa,SAAS,gBAAgB,aAAa,eAAe,KAAA;CACvG,MAAM,eAAe,OAAO,QAAQ,UAAU,CAAC,CAAC,MAC7C,GAAG,cAAc,WAAW,aAAa,QAAQ,CAAC,MAAM,OAC3D,CAAC,GAAG;CAEJ,IAAI,iBAAiB,sBAAsB,cAAc,UAAU,IACjE,OAAO;EAAE,MAAM;EAAmB;EAAc;CAAmB;CAErE,IAAI,eAAe,wBAAwB,cAAc,WAAW,GAAG,OAAO,EAAE,MAAM,SAAS;CAC/F,OAAO,EAAE,MAAM,SAAS;AAC1B;AAEA,SAAS,gBAAgB,OAA6B;CACpD,OAAO,MAAM,iBAAiB,UAAU,CAAC,MAAM;AACjD;AAEA,SAAgB,uBAAuB,SAAiC,eAAkC;CACxG,OAAO;EACL,SAAS;EACT,QAAQ,OAAO,OAAO,eAAe,CAAC,CAAC,KAAI,UAAS;GAClD,MAAM,iBAAiB,cAAc,MAAM,cAAc;GACzD,OAAO;IACL,QAAQ,MAAM;IACd,MAAM,MAAM;IACZ,cAAc,MAAM;IACpB,iBAAiB,cAAc,MAAM,eAAe;IACpD,kBAAkB,cAAc,MAAM,gBAAgB;IACtD,YAAY,cAAc,MAAM,UAAU;IAC1C;IACA,eAAe,mBAAmB,cAAc;GAClD;EACF,CAAC;CACH;AACF"}
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-server
|
|
|
3
3
|
description: Documentation for @mastra/server. Use when working with @mastra/server APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/server"
|
|
6
|
-
version: "1.75.0-alpha.
|
|
6
|
+
version: "1.75.0-alpha.4"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -24,7 +24,7 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
24
24
|
|
|
25
25
|
### Reference
|
|
26
26
|
|
|
27
|
-
- [Advanced trace queries](references/reference-observability-tracing-trace-query.md) - Query completed traces
|
|
27
|
+
- [Advanced trace queries](references/reference-observability-tracing-trace-query.md) - Query completed traces, thread identities, and spans with recursive predicates, numbered pages, keyset cursors, and delta polling.
|
|
28
28
|
- [Reference: createRoute()](references/reference-server-create-route.md) - Use createRoute() to define type-safe Mastra server routes with Zod validation for requests and responses, plus handler context and OpenAPI metadata.
|
|
29
29
|
- [Reference: MastraServer](references/reference-server-mastra-server.md) - The MastraServer abstract class is the base for all server adapters. Extend this class to create adapters for frameworks other than Hono or Express.
|
|
30
30
|
- [Reference: Server routes](references/reference-server-routes.md) - Server adapters register these routes when you call server.init(). All routes are prefixed with the prefix option if configured.
|
|
@@ -6,13 +6,74 @@
|
|
|
6
6
|
|
|
7
7
|
Use `queryTraces()` or `POST /api/observability/traces/query` to find completed logical traces that match trace fields and related span, score, or feedback records. Use `queryTraceThreads()` or `POST /api/observability/threads/query` to find thread identities that qualify across multiple eligible traces.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Use `querySpans()` or `POST /api/observability/spans/query` to list the individual completed spans that match a span predicate.
|
|
10
|
+
|
|
11
|
+
All three endpoints use the same authentication as other observability routes and require the `observability:read` permission. The configured observability store must support the requested trace-query, thread-query, or span-query operation.
|
|
10
12
|
|
|
11
13
|
> **Thread grouping is deprecated:** The `group` option remains supported until the next major release. Use [`queryTraceThreads()`](https://mastra.ai/reference/client-js/observability) to retrieve matching thread identities in new code.
|
|
12
14
|
|
|
13
|
-
## Query individual spans
|
|
15
|
+
## Query individual spans
|
|
16
|
+
|
|
17
|
+
`querySpans()` returns one row per matching completed span across traces, including matching child spans. Use it to list the spans themselves, for example every failed tool call in the last day.
|
|
18
|
+
|
|
19
|
+
`queryTraces()` with a `spans.some` predicate answers a different question. It returns the traces that contain at least one matching span, and it doesn't identify which spans matched. Both use the same span fields and operators.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
const timeRange = {
|
|
23
|
+
from: '2026-10-01T00:00:00.000Z',
|
|
24
|
+
to: '2026-10-02T00:00:00.000Z',
|
|
25
|
+
}
|
|
26
|
+
const where = {
|
|
27
|
+
op: 'and',
|
|
28
|
+
args: [
|
|
29
|
+
{ op: 'eq', left: { path: 'spanType' }, right: { literal: 'tool_call' } },
|
|
30
|
+
{ op: 'eq', left: { path: 'status' }, right: { literal: 'error' } },
|
|
31
|
+
],
|
|
32
|
+
} as const
|
|
33
|
+
|
|
34
|
+
const firstPage = await mastraClient.querySpans({
|
|
35
|
+
timeRange,
|
|
36
|
+
where,
|
|
37
|
+
orderBy: [{ field: 'startedAt', direction: 'desc' }],
|
|
38
|
+
page: { limit: 50 },
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
if (firstPage.page.next) {
|
|
42
|
+
const secondPage = await mastraClient.querySpans({
|
|
43
|
+
timeRange,
|
|
44
|
+
where,
|
|
45
|
+
orderBy: [{ field: 'startedAt', direction: 'desc' }],
|
|
46
|
+
page: { limit: 50, after: firstPage.page.next },
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The HTTP route accepts the same body:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
curl --request POST \
|
|
55
|
+
--url http://localhost:4111/api/observability/spans/query \
|
|
56
|
+
--header 'Authorization: Bearer <token>' \
|
|
57
|
+
--header 'Content-Type: application/json' \
|
|
58
|
+
--data '{
|
|
59
|
+
"timeRange": {
|
|
60
|
+
"from": "2026-10-01T00:00:00.000Z",
|
|
61
|
+
"to": "2026-10-02T00:00:00.000Z"
|
|
62
|
+
},
|
|
63
|
+
"where": { "op": "eq", "left": { "path": "spanType" }, "right": { "literal": "tool_call" } },
|
|
64
|
+
"page": { "limit": 50 }
|
|
65
|
+
}'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Span queries are optional for observability stores. Call `mastraClient.getObservabilityCapabilities()` and check `capabilities.spanQuery` before showing a span list. Treat a missing `spanQuery` value as unsupported, because older servers don't report it. A server whose store or `@mastra/core` version doesn't support span queries returns `501` with code `SPAN_QUERY_UNSUPPORTED`.
|
|
69
|
+
|
|
70
|
+
The other statuses match trace queries: `400` for malformed JSON or a malformed cursor, `409` for a cursor that doesn't match the query, `413` for a body over 256 KiB, `422` with code `TRACE_QUERY_INVALID` and structured `issues` for an invalid query, `503` with code `TRACE_QUERY_RESOURCE_LIMIT` when a page exceeds a resource limit, and `504` with code `TRACE_QUERY_EXECUTION_TIMEOUT` when the database deadline is exceeded.
|
|
71
|
+
|
|
72
|
+
The server applies [trusted tenant scope](#trusted-tenant-scope) to span queries the same way it does for trace queries. A cursor created under one scope and reused under another returns `409`.
|
|
73
|
+
|
|
74
|
+
### Query individual spans through storage
|
|
14
75
|
|
|
15
|
-
The observability domain in DuckDB and the PostgreSQL and ClickHouse v-next stores supports `querySpans(plan)`.
|
|
76
|
+
The observability domain in DuckDB and the PostgreSQL and ClickHouse v-next stores supports `querySpans(plan)`. Check `storage.getFeatures()?.includes('span-query')` before using this optional storage method.
|
|
16
77
|
|
|
17
78
|
Build the plan in trusted backend code:
|
|
18
79
|
|
|
@@ -768,7 +829,7 @@ PostgreSQL and ClickHouse stop advanced trace and thread queries after 15 second
|
|
|
768
829
|
|
|
769
830
|
## Limitations
|
|
770
831
|
|
|
771
|
-
|
|
832
|
+
Trace and thread queries consider completed traces only, and span queries consider completed spans only. They don't support running traces, custom projections, embedded evidence, summaries, aggregations, measures, or custom grouping. Numbered trace pages include a total count.
|
|
772
833
|
|
|
773
834
|
## Related
|
|
774
835
|
|
package/dist/{observability-new-endpoints-lNC3o66-.js → observability-new-endpoints-DQuhr8aL.js}
RENAMED
|
@@ -3,8 +3,8 @@ import { a as wrapSchemaForQueryParams, i as pickParams, n as createRoute } from
|
|
|
3
3
|
import { d as MASTRA_USER_ROLES_KEY, l as MASTRA_USER_KEY, m as isStudioClientTypeHeader } from "./constants-0jFCWoex.js";
|
|
4
4
|
import { handleError } from "./server/handlers/error.js";
|
|
5
5
|
import { paginationArgsSchema as paginationArgsSchema$1 } from "./server/handlers/observability-list-query-schemas.js";
|
|
6
|
-
import { NEW_ROUTE_DEFS, NO_OBSERVABILITY_STORAGE_CAPABILITIES, OBSERVABILITY_LIST_ENDPOINTS, OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_UPGRADE_MESSAGE, assertObservabilityDeltaSupported, assertObservabilityThreadQuerySupported, assertObservabilityTraceAggregateSupported, assertObservabilityTraceQueryContextIdsSupported, assertObservabilityTraceQueryDiscoverySupported, assertObservabilityTraceQueryRootDurationSupported, assertObservabilityTraceQuerySupported, assertObservabilityTraceQueryTenantScopeSupported, createObservabilityListQuerySchema, getObservabilityStorageCapabilities, getObservabilityStore, isTraceQueryContextIdField, supportsObservabilityTraceQueryContextIds, supportsObservabilityTraceQueryRootDuration, supportsTraceAggregateCore, supportsTraceQueryDiscoveryCore, withDiscoveryFallback } from "./server/handlers/observability-shared.js";
|
|
7
|
-
import { l as observabilityStorageCapabilitiesSchema } from "./system-
|
|
6
|
+
import { NEW_ROUTE_DEFS, NO_OBSERVABILITY_STORAGE_CAPABILITIES, OBSERVABILITY_LIST_ENDPOINTS, OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_UPGRADE_MESSAGE, assertObservabilityDeltaSupported, assertObservabilitySpanQuerySupported, assertObservabilityThreadQuerySupported, assertObservabilityTraceAggregateSupported, assertObservabilityTraceQueryContextIdsSupported, assertObservabilityTraceQueryDiscoverySupported, assertObservabilityTraceQueryRootDurationSupported, assertObservabilityTraceQuerySupported, assertObservabilityTraceQueryTenantScopeSupported, createObservabilityListQuerySchema, getObservabilityStorageCapabilities, getObservabilityStore, isTraceQueryContextIdField, supportsObservabilityTraceQueryContextIds, supportsObservabilityTraceQueryRootDuration, supportsSpanQueryCore, supportsTraceAggregateCore, supportsTraceQueryDiscoveryCore, withDiscoveryFallback } from "./server/handlers/observability-shared.js";
|
|
7
|
+
import { l as observabilityStorageCapabilitiesSchema } from "./system-BtGAJr9R.js";
|
|
8
8
|
import { prepareAuthorEnrichment } from "./server/handlers/author-enrichment.js";
|
|
9
9
|
import { getCallerPermissions } from "./server/handlers/authorship.js";
|
|
10
10
|
import { z } from "zod/v4";
|
|
@@ -1176,6 +1176,115 @@ if (AGGREGATE_TRACES.openapi) {
|
|
|
1176
1176
|
content: { "application/json": { schema: traceQueryTimeoutErrorSchema } }
|
|
1177
1177
|
};
|
|
1178
1178
|
}
|
|
1179
|
+
const spanQueryUnsupportedErrorSchema = z.object({
|
|
1180
|
+
code: z.literal("SPAN_QUERY_UNSUPPORTED"),
|
|
1181
|
+
message: z.string()
|
|
1182
|
+
}).strict();
|
|
1183
|
+
const spanQueryValidationError = (error) => ({
|
|
1184
|
+
status: 422,
|
|
1185
|
+
body: {
|
|
1186
|
+
code: "TRACE_QUERY_INVALID",
|
|
1187
|
+
message: "The span query is invalid",
|
|
1188
|
+
issues: error.issues.map((issue) => ({
|
|
1189
|
+
code: "invalid_request",
|
|
1190
|
+
path: issue.path.map((part) => typeof part === "symbol" ? String(part) : part),
|
|
1191
|
+
message: issue.message
|
|
1192
|
+
}))
|
|
1193
|
+
}
|
|
1194
|
+
});
|
|
1195
|
+
const QUERY_SPANS = createNewRoute(NEW_ROUTE_DEFS.QUERY_SPANS, {
|
|
1196
|
+
bodySchema: coreStorage.spanQueryRequestSchema,
|
|
1197
|
+
responseSchema: coreStorage.spanQueryResponseSchema,
|
|
1198
|
+
onValidationError: spanQueryValidationError,
|
|
1199
|
+
maxBodySize: 256 * 1024,
|
|
1200
|
+
preserveHttpExceptions: true,
|
|
1201
|
+
isCoreSupported: supportsSpanQueryCore,
|
|
1202
|
+
onUnsupportedCore: () => throwTraceQueryError(501, {
|
|
1203
|
+
code: "SPAN_QUERY_UNSUPPORTED",
|
|
1204
|
+
message: "Span queries require a newer @mastra/core. Please upgrade."
|
|
1205
|
+
}),
|
|
1206
|
+
handler: async ({ mastra, requestContext, timeRange, where, orderBy, page }) => {
|
|
1207
|
+
let plan;
|
|
1208
|
+
try {
|
|
1209
|
+
plan = coreStorage.planSpanQuery({
|
|
1210
|
+
timeRange,
|
|
1211
|
+
where,
|
|
1212
|
+
orderBy,
|
|
1213
|
+
page
|
|
1214
|
+
}, { scope: resolveTraceQueryScope(requestContext, "SPAN_QUERY_UNSUPPORTED") });
|
|
1215
|
+
} catch (error) {
|
|
1216
|
+
if (error instanceof coreStorage.TraceQueryValidationError) throwTraceQueryError(422, {
|
|
1217
|
+
code: error.code,
|
|
1218
|
+
message: "The span query is invalid",
|
|
1219
|
+
issues: error.issues
|
|
1220
|
+
});
|
|
1221
|
+
if (error instanceof coreStorage.TraceQueryCursorError) throwTraceQueryError(error.code === "TRACE_QUERY_CURSOR_CONFLICT" ? 409 : 400, {
|
|
1222
|
+
code: error.code,
|
|
1223
|
+
message: error.message
|
|
1224
|
+
});
|
|
1225
|
+
throw error;
|
|
1226
|
+
}
|
|
1227
|
+
let observabilityStore;
|
|
1228
|
+
try {
|
|
1229
|
+
observabilityStore = await getObservabilityStore(mastra);
|
|
1230
|
+
assertObservabilitySpanQuerySupported(observabilityStore);
|
|
1231
|
+
assertObservabilityTraceQueryTenantScopeSupported(observabilityStore, plan.scope);
|
|
1232
|
+
} catch (error) {
|
|
1233
|
+
if (error instanceof HTTPException && error.status === 501) throwTraceQueryError(501, {
|
|
1234
|
+
code: "SPAN_QUERY_UNSUPPORTED",
|
|
1235
|
+
message: error.message
|
|
1236
|
+
});
|
|
1237
|
+
throw error;
|
|
1238
|
+
}
|
|
1239
|
+
try {
|
|
1240
|
+
return await observabilityStore.querySpans(plan);
|
|
1241
|
+
} catch (error) {
|
|
1242
|
+
if (error instanceof coreStorage.TraceQueryCursorError) throwTraceQueryError(error.code === "TRACE_QUERY_CURSOR_CONFLICT" ? 409 : 400, {
|
|
1243
|
+
code: error.code,
|
|
1244
|
+
message: error.message
|
|
1245
|
+
});
|
|
1246
|
+
if (error instanceof coreStorage.TraceQueryResourceLimitError) throwTraceQueryError(503, {
|
|
1247
|
+
code: error.code,
|
|
1248
|
+
message: error.message
|
|
1249
|
+
});
|
|
1250
|
+
if (error instanceof coreStorage.TraceQueryExecutionError) throwTraceQueryError(504, {
|
|
1251
|
+
code: error.code,
|
|
1252
|
+
message: error.message
|
|
1253
|
+
});
|
|
1254
|
+
throw error;
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
if (QUERY_SPANS.openapi) {
|
|
1259
|
+
QUERY_SPANS.openapi.responses[400] = {
|
|
1260
|
+
description: "Malformed JSON or malformed cursor",
|
|
1261
|
+
content: { "application/json": { schema: z.union([traceQueryMalformedBodyErrorSchema, traceQueryMalformedCursorErrorSchema]) } }
|
|
1262
|
+
};
|
|
1263
|
+
QUERY_SPANS.openapi.responses[409] = {
|
|
1264
|
+
description: "Cursor does not match the normalized query",
|
|
1265
|
+
content: { "application/json": { schema: traceQueryCursorConflictErrorSchema } }
|
|
1266
|
+
};
|
|
1267
|
+
QUERY_SPANS.openapi.responses[413] = {
|
|
1268
|
+
description: "Request body exceeds 256 KiB",
|
|
1269
|
+
content: { "application/json": { schema: traceQueryBodyTooLargeErrorSchema } }
|
|
1270
|
+
};
|
|
1271
|
+
QUERY_SPANS.openapi.responses[422] = {
|
|
1272
|
+
description: "Structurally or semantically invalid span query",
|
|
1273
|
+
content: { "application/json": { schema: traceQueryValidationResponseSchema } }
|
|
1274
|
+
};
|
|
1275
|
+
QUERY_SPANS.openapi.responses[501] = {
|
|
1276
|
+
description: "The configured observability store does not support span queries",
|
|
1277
|
+
content: { "application/json": { schema: spanQueryUnsupportedErrorSchema } }
|
|
1278
|
+
};
|
|
1279
|
+
QUERY_SPANS.openapi.responses[503] = {
|
|
1280
|
+
description: "Span query exceeded a bounded execution resource limit",
|
|
1281
|
+
content: { "application/json": { schema: traceQueryResourceLimitErrorSchema } }
|
|
1282
|
+
};
|
|
1283
|
+
QUERY_SPANS.openapi.responses[504] = {
|
|
1284
|
+
description: "Span query exceeded the configured database execution timeout",
|
|
1285
|
+
content: { "application/json": { schema: traceQueryTimeoutErrorSchema } }
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1179
1288
|
const GET_TRACE_QUERY_FIELDS = createNewRoute(NEW_ROUTE_DEFS.GET_TRACE_QUERY_FIELDS, {
|
|
1180
1289
|
bodySchema: coreStorage.getTraceQueryFieldsArgsSchema,
|
|
1181
1290
|
responseSchema: coreStorage.getTraceQueryFieldsResponseSchema,
|
|
@@ -1753,6 +1862,7 @@ const GET_CAPABILITIES = createRoute({
|
|
|
1753
1862
|
const NEW_ROUTES = {
|
|
1754
1863
|
QUERY_TRACES,
|
|
1755
1864
|
QUERY_THREADS,
|
|
1865
|
+
QUERY_SPANS,
|
|
1756
1866
|
LIST_LOGS,
|
|
1757
1867
|
LIST_SCORES,
|
|
1758
1868
|
CREATE_SCORE,
|
|
@@ -1786,6 +1896,6 @@ const NEW_ROUTES = {
|
|
|
1786
1896
|
GET_CAPABILITIES
|
|
1787
1897
|
};
|
|
1788
1898
|
//#endregion
|
|
1789
|
-
export { LIST_FEEDBACK as A, GET_SCORE_BREAKDOWN as C, GET_TAGS as D, GET_SERVICE_NAMES as E,
|
|
1899
|
+
export { LIST_FEEDBACK as A, GET_SCORE_BREAKDOWN as C, GET_TAGS as D, GET_SERVICE_NAMES as E, QUERY_SPANS as F, QUERY_THREADS as I, QUERY_TRACES as L, LIST_METRICS as M, LIST_SCORES as N, GET_TRACE_QUERY_FIELDS as O, NEW_ROUTES as P, UPDATE_FEEDBACK_REVIEW_STATUS as R, GET_SCORE_AGGREGATE as S, GET_SCORE_TIME_SERIES as T, GET_METRIC_LABEL_VALUES as _, DELETE_SCORES as a, GET_METRIC_TIME_SERIES as b, GET_ENTITY_TYPES as c, GET_FEEDBACK_BREAKDOWN as d, GET_FEEDBACK_PERCENTILES as f, GET_METRIC_LABEL_KEYS as g, GET_METRIC_BREAKDOWN as h, DELETE_FEEDBACK as i, LIST_LOGS as j, GET_TRACE_QUERY_VALUES as k, GET_ENVIRONMENTS as l, GET_METRIC_AGGREGATE as m, CREATE_FEEDBACK as n, GET_CAPABILITIES as o, GET_FEEDBACK_TIME_SERIES as p, CREATE_SCORE as r, GET_ENTITY_NAMES as s, AGGREGATE_TRACES as t, GET_FEEDBACK_AGGREGATE as u, GET_METRIC_NAMES as v, GET_SCORE_PERCENTILES as w, GET_SCORE as x, GET_METRIC_PERCENTILES as y };
|
|
1790
1900
|
|
|
1791
|
-
//# sourceMappingURL=observability-new-endpoints-
|
|
1901
|
+
//# sourceMappingURL=observability-new-endpoints-DQuhr8aL.js.map
|