@mastra/core
Version:
332 lines • 21.7 kB
TypeScript
import { StorageDomain } from '../base.js';
import type { GetEntityTypesArgs, GetEntityTypesResponse, GetEntityNamesArgs, GetEntityNamesResponse, GetServiceNamesArgs, GetServiceNamesResponse, GetEnvironmentsArgs, GetEnvironmentsResponse, GetTagsArgs, GetTagsResponse, GetMetricNamesArgs, GetMetricNamesResponse, GetMetricLabelKeysArgs, GetMetricLabelKeysResponse, GetMetricLabelValuesArgs, GetMetricLabelValuesResponse } from './discovery.js';
import type { BatchCreateFeedbackArgs, DeleteFeedbackArgs, CreateFeedbackArgs, ListFeedbackArgs, ListFeedbackResponse, GetFeedbackAggregateArgs, GetFeedbackAggregateResponse, GetFeedbackBreakdownArgs, GetFeedbackBreakdownResponse, GetFeedbackTimeSeriesArgs, GetFeedbackTimeSeriesResponse, GetFeedbackPercentilesArgs, GetFeedbackPercentilesResponse, UpdateFeedbackReviewStatusArgs, FeedbackRecord } from './feedback.js';
import type { BatchCreateLogsArgs, ListLogsArgs, ListLogsResponse } from './logs.js';
import type { BatchCreateMetricsArgs, ListMetricsArgs, ListMetricsResponse, GetMetricAggregateArgs, GetMetricAggregateResponse, GetMetricBreakdownArgs, GetMetricBreakdownResponse, GetMetricTimeSeriesArgs, GetMetricTimeSeriesResponse, GetMetricPercentilesArgs, GetMetricPercentilesResponse } from './metrics.js';
import type { BatchCreateScoresArgs, DeleteScoresArgs, CreateScoreArgs, ListScoresArgs, ListScoresResponse, ScoreRecord, GetScoreAggregateArgs, GetScoreAggregateResponse, GetScoreBreakdownArgs, GetScoreBreakdownResponse, GetScoreTimeSeriesArgs, GetScoreTimeSeriesResponse, GetScorePercentilesArgs, GetScorePercentilesResponse } from './scores.js';
import type { SpanAggregateResponse, TrustedSpanAggregatePlan } from './span-aggregate.js';
import type { SpanQueryResponse, TrustedSpanQueryPlan } from './span-query.js';
import type { ThreadQueryResponse, TrustedThreadRowsQueryPlan } from './thread-query.js';
import type { TraceAggregateResponse } from './trace-aggregate.js';
import type { TrustedTraceAggregatePlan } from './trace-aggregate-planner.js';
import type { GetTraceQueryValuesResponse, QueryThreadsResult, TraceQueryObservedFieldsResult, TraceQueryResponse, TrustedThreadQueryPlan, TrustedTraceQueryObservedFieldsPlan, TrustedTraceQueryPlan, TrustedTraceQueryValuesPlan } from './trace-query.js';
import type { BatchCreateSpansArgs, BatchDeleteTracesArgs, BatchUpdateSpansArgs, BatchUpdateUnendedSpansResponse, CreateSpanArgs, GetBranchArgs, GetBranchResponse, GetRootSpanArgs, GetRootSpanResponse, GetSpanArgs, GetSpanResponse, GetSpansArgs, GetSpansResponse, GetStructureResponse, GetTraceArgs, GetTraceResponse, GetTraceLightResponse, ListBranchesArgs, ListBranchesResponse, ListTracesArgs, ListTracesLightResponse, ListTracesResponse, UpdateSpanArgs } from './tracing.js';
import type { ObservabilityStorageStrategy, TracingStorageStrategy } from './types.js';
/**
* Optional observability APIs a store can declare via {@link ObservabilityStorage.getFeatures}.
*
* - `delta-polling`: cursor-based `mode: 'delta'` on list endpoints
* - `metrics`: metric list/aggregate/breakdown/timeseries/percentiles
* - `logs`: `listLogs`
* - `entity-type-discovery`, `entity-name-discovery`, `service-name-discovery`,
* `environment-discovery`, `tag-discovery`: the matching `get*` filter discovery method
* - `metric-discovery`: `getMetricNames`, `getMetricLabelKeys`, `getMetricLabelValues`
* - `span-query`: `querySpans` over completed spans
* - `span-query-duration-sort`: ordering completed spans by `durationMs`
* - `span-query-model-provider-sort`: ordering completed spans by their model/provider columns
* - `span-query-context-fields`: identity, context and parent/root entity predicates added to `querySpans`
* - `span-query-token-search`: token matching in `querySpans`
* - `trace-query-token-search`: token matching across any span in `queryTraces`
* - `span-query-model-fields`: `model` and `provider` predicates in `querySpans` and `aggregateSpans`
* - `trace-aggregate-token-search`: token matching across any span in `aggregateTraces`
* - `span-aggregate-token-search`: token matching in `aggregateSpans`
* - `span-aggregate`: `aggregateSpans`, including every `querySpans` predicate field
* - `span-aggregate-model-dimensions`: `model` and `provider` in `aggregateSpans` `groupBy` and `countDistinct`
* - `trace-query`: `queryTraces`
* - `trace-aggregate`: `aggregateTraces`
* - `trace-query-root-duration`: `durationMs` predicates in trace/thread queries
* - `trace-query-context-ids`: `runId`, `sessionId`, `userId` and `organizationId` predicates in trace/thread queries
* - `trace-query-context-fields`: `requestId`, `serviceName` and `experimentId` predicates in trace queries (trace scope and `spans.some`/`spans.none`)
* - `trace-query-time-to-first-chunk`: `timeToFirstChunkMs` on trace and span query results and predicates
* - `trace-query-root-span-fields`: root span `name` and `spanType` in trace-scope predicates, aggregate `groupBy` and `countDistinct`
* - `trace-query-root-entity-id`: root span `entityId` in trace-scope predicates, aggregate `groupBy` and `countDistinct`
* - `trace-query-time-to-first-chunk-sort`: `orderBy` on `timeToFirstChunkMs` in trace and span queries
* - `trace-query-time-to-first-token`: `timeToFirstTokenMs` on trace, thread and span query results and predicates
* - `trace-query-time-to-first-token-sort`: `orderBy` on `timeToFirstTokenMs` in trace and span queries
* - `span-query-outcome-fields`: `outcome` and `stopReason` predicates in `querySpans` and `aggregateSpans`
* (including `groupBy` and `countDistinct`), and `outcome`, `stopReason` and `stopReasonContext` on span rows
* - `trace-query-outcome-fields`: the root span's `outcome` and `stopReason` in trace-scope predicates and
* trace aggregate `groupBy`/`countDistinct`, both fields in `spans.some`/`spans.none` predicates, and the root
* span's `outcome`, `stopReason` and `stopReasonContext` on trace rows
* - `trace-query-discovery`: `getTraceQueryObservedFields`, `getTraceQueryValues`
* - `aggregate-time-to-first-measures`: `timeToFirstToken.*` and `timeToFirstChunk.*` measures in
* `aggregateTraces` (root span value) and `aggregateSpans` (each span's value)
* - `thread-query`: `queryThreads`
* - `trace-query-tenant-scope`: enforcing a trusted tenant scope on trace/thread queries
* - `feedback`: the feedback CRUD, review-status and analytics methods
* - `feedback-replacement`: full replacement and create-with-ignore-conflicts support
*/
export type ObservabilityStorageFeature = 'delta-polling' | 'metrics' | 'logs' | 'entity-type-discovery' | 'entity-name-discovery' | 'service-name-discovery' | 'environment-discovery' | 'tag-discovery' | 'metric-discovery' | 'span-query' | 'span-query-duration-sort' | 'span-query-model-provider-sort' | 'span-query-context-fields' | 'span-query-token-search' | 'trace-query-token-search' | 'trace-aggregate-token-search' | 'span-aggregate-token-search' | 'span-query-model-fields' | 'span-aggregate' | 'span-aggregate-model-dimensions' | 'trace-query' | 'trace-aggregate' | 'trace-query-root-duration' | 'trace-query-discovery' | 'thread-query' | 'thread-query-rows' | 'trace-query-tenant-scope' | 'feedback' | 'feedback-replacement' | 'trace-query-context-ids' | 'trace-query-context-fields' | 'trace-query-time-to-first-chunk' | 'trace-query-root-span-fields' | 'trace-query-root-entity-id' | 'trace-query-time-to-first-chunk-sort' | 'trace-query-time-to-first-token' | 'trace-query-time-to-first-token-sort' | 'span-query-outcome-fields' | 'trace-query-outcome-fields' | 'aggregate-time-to-first-measures';
/**
* Base storage class for observability data (traces, metrics, logs, scores, feedback).
* Not abstract -- provides default implementations that throw "not implemented" errors.
* Storage adapters override only the methods they support.
*/
export declare class ObservabilityStorage extends StorageDomain {
/**
* Where this domain writes data. Local includes embedded files, in-memory
* databases, and local replicas that sync remotely. Remote stores write
* through a database service. Undefined means the adapter does not report it.
* Platform exporters use this capability to avoid local observability writes.
*/
get persistenceLocation(): 'local' | 'remote' | undefined;
constructor();
dangerouslyClearAll(): Promise<void>;
/**
* Provides hints for tracing strategy selection by the MastraStorageExporter.
* Storage adapters can override this to specify their preferred and supported strategies.
*/
get observabilityStrategy(): {
preferred: ObservabilityStorageStrategy;
supported: ObservabilityStorageStrategy[];
};
/**
* Provides hints for tracing strategy selection by the MastraStorageExporter.
* Storage adapters can override this to specify their preferred and supported strategies.
* @deprecated Use {@link observabilityStrategy} instead.
* @see {@link observabilityStrategy} for the replacement property.
*/
get tracingStrategy(): {
preferred: TracingStorageStrategy;
supported: TracingStorageStrategy[];
};
/**
* Reports the tracing strategy currently in effect for this attached observability store.
*
* Single-strategy stores can rely on the default implementation. Multi-strategy stores
* should override this getter only when they can determine the actual configured mode
* from storage-owned configuration, not exporter state.
*/
get runtimeTracingStrategy(): TracingStorageStrategy | undefined;
/**
* Optional feature list for observability storage APIs.
* Stores should override this to opt in to the APIs they support explicitly.
* Older stores and older package versions will simply omit it, which keeps page mode working.
*/
getFeatures(): readonly ObservabilityStorageFeature[] | undefined;
/**
* Creates a single Span record in the storage provider.
*/
createSpan(_args: CreateSpanArgs): Promise<void>;
/**
* Updates a single Span with partial data. Primarily used for realtime trace creation.
*
* @deprecated This method only works with stores that support span updates,
* It will be removed in the future. Instead try to add all data to a span before
* ending it.
*/
updateSpan(_args: UpdateSpanArgs): Promise<void>;
/**
* Retrieves a single span.
*/
getSpan(_args: GetSpanArgs): Promise<GetSpanResponse | null>;
/**
* Retrieves a single root span.
*/
getRootSpan(_args: GetRootSpanArgs): Promise<GetRootSpanResponse | null>;
/**
* Retrieves a single trace with all its associated spans.
*/
getTrace(_args: GetTraceArgs): Promise<GetTraceResponse | null>;
/**
* Retrieves the structural skeleton of a trace -- parent/child links, span
* type, timing, and status -- with heavy fields (input, output, attributes,
* metadata, tags, links) excluded. Intended for waterfall/timeline rendering
* where the full payload would be wasteful.
*
* Default implementation forwards to {@link getTraceLight} (the legacy
* override surface). Backends should override either method -- the response
* shape is identical, and the unimplemented one delegates to the
* implemented one. The cycle guard is what makes that safe.
*/
getStructure(args: GetTraceArgs): Promise<GetStructureResponse | null>;
/**
* @deprecated Use {@link getStructure} instead. Default implementation
* forwards to {@link getStructure} so backends that only override the
* canonical name still work for legacy callers.
*/
getTraceLight(args: GetTraceArgs): Promise<GetTraceLightResponse | null>;
/**
* Retrieves the subtree of spans rooted at a given span, optionally bounded
* to `depth` levels of descendants.
*
* Default implementation prefers a two-step path: fetch the lightweight
* structure to determine which spans belong to the branch, then batch-fetch
* only those with full data. This avoids pulling the entire trace when the
* branch is a small slice of a large trace. Backends that don't yet
* implement {@link getStructure} or {@link getSpans} fall back to fetching
* the full trace and walking it in memory.
*/
getBranch(args: GetBranchArgs): Promise<GetBranchResponse | null>;
/**
* Batch-fetches spans by spanId within a single trace. Used by the
* optimized {@link getBranch} path to fetch only the spans that belong to
* the requested branch (after walking the lightweight structure to identify
* them) instead of pulling the entire trace.
*/
getSpans(_args: GetSpansArgs): Promise<GetSpansResponse>;
/**
* Retrieves a list of traces with optional filtering.
*/
listTraces(_args: ListTracesArgs): Promise<ListTracesResponse>;
/**
* Retrieves a lightweight list of traces with optional filtering.
*
* Defaults to {@link listTraces} with each row projected down, so every backend
* serves the same response shape whether or not it has a dedicated implementation.
* Backends that can push the projection into the query should override this --
* that is what actually keeps the blob columns off the read path -- but the
* fallback stays correct, just not cheaper than `listTraces`.
*/
listTracesLight(args: ListTracesArgs): Promise<ListTracesLightResponse>;
/** Executes a validated span-row query; unsupported stores fail explicitly. */
querySpans(_plan: TrustedSpanQueryPlan): Promise<SpanQueryResponse>;
/**
* Executes a validated advanced trace-query plan.
*/
queryTraces(_plan: TrustedTraceQueryPlan): Promise<TraceQueryResponse>;
/**
* Executes a validated trace-aggregate plan.
*/
aggregateTraces(_plan: TrustedTraceAggregatePlan): Promise<TraceAggregateResponse>;
/**
* Executes a validated span-aggregate plan.
*/
aggregateSpans(_plan: TrustedSpanAggregatePlan): Promise<SpanAggregateResponse>;
/**
* Discovers observed metadata fields over a validated trace population.
*/
getTraceQueryObservedFields(_plan: TrustedTraceQueryObservedFieldsPlan): Promise<TraceQueryObservedFieldsResult>;
/**
* Discovers values for an eligible field over a validated trace population.
*/
getTraceQueryValues(_plan: TrustedTraceQueryValuesPlan): Promise<GetTraceQueryValuesResponse>;
/**
* Executes a validated thread-query plan.
* Keep the base return type compatible with identity-only adapters. The server
* checks `thread-query-rows` before sending a row plan; capable concrete adapters
* provide the more specific row overload.
*/
queryThreads(_plan: TrustedThreadQueryPlan | TrustedThreadRowsQueryPlan): Promise<QueryThreadsResult | ThreadQueryResponse>;
/**
* Lists trace branches across all traces. Unlike {@link listTraces} (which
* returns one row per root-rooted trace), each row here is a single branch
* anchor span, including ones nested under a different root entity -- useful
* for "show me every run of agent X" regardless of caller. Pairs with
* {@link getBranch} to expand a single branch into its subtree.
*/
listBranches(_args: ListBranchesArgs): Promise<ListBranchesResponse>;
/**
* Creates multiple Spans in a single batch.
*/
batchCreateSpans(_args: BatchCreateSpansArgs): Promise<void>;
/**
* Updates multiple Spans in a single batch.
*/
batchUpdateSpans(_args: BatchUpdateSpansArgs): Promise<void>;
/**
* Optional. Updates multiple spans, but only rows that already exist and haven't
* ended (`endedAt` is null). Never inserts. Returns the spans whose rows changed,
* so callers can tell which updates didn't apply.
*
* Lets an exporter end a span that a different process started (for example, a
* durable agent recovering after a crash) without reading the row first, while
* keeping ended spans immutable. Stores that don't implement it leave it
* undefined, so callers must check that it exists before calling it.
*/
batchUpdateUnendedSpans?(args: BatchUpdateSpansArgs): Promise<BatchUpdateUnendedSpansResponse>;
/**
* Deletes multiple traces, all their associated spans, and any trace-linked signal
* events (metrics, logs, scores, feedback) in a single batch operation.
*
* Signal rows without a traceId are never affected. When the optional tenant scope
* (`organizationId` / `resourceId`) is provided, only rows matching that scope are
* deleted; stores without tenant columns must reject scoped calls.
*/
batchDeleteTraces(_args: BatchDeleteTracesArgs): Promise<void>;
/**
* Guard for stores without tenant columns: throws when a tenant scope is provided
* to batchDeleteTraces, instead of silently performing an unscoped delete.
*/
protected assertUnscopedBatchDeleteTraces(args: BatchDeleteTracesArgs): void;
/**
* Creates multiple log records in a single batch.
*/
batchCreateLogs(_args: BatchCreateLogsArgs): Promise<void>;
/**
* Retrieves a list of logs with optional filtering.
*/
listLogs(_args: ListLogsArgs): Promise<ListLogsResponse>;
/**
* Creates multiple metric observations in a single batch.
*/
batchCreateMetrics(_args: BatchCreateMetricsArgs): Promise<void>;
listMetrics(_args: ListMetricsArgs): Promise<ListMetricsResponse>;
getMetricAggregate(_args: GetMetricAggregateArgs): Promise<GetMetricAggregateResponse>;
getMetricBreakdown(_args: GetMetricBreakdownArgs): Promise<GetMetricBreakdownResponse>;
getMetricTimeSeries(_args: GetMetricTimeSeriesArgs): Promise<GetMetricTimeSeriesResponse>;
getMetricPercentiles(_args: GetMetricPercentilesArgs): Promise<GetMetricPercentilesResponse>;
getMetricNames(_args: GetMetricNamesArgs): Promise<GetMetricNamesResponse>;
getMetricLabelKeys(_args: GetMetricLabelKeysArgs): Promise<GetMetricLabelKeysResponse>;
getMetricLabelValues(_args: GetMetricLabelValuesArgs): Promise<GetMetricLabelValuesResponse>;
getEntityTypes(_args: GetEntityTypesArgs): Promise<GetEntityTypesResponse>;
getEntityNames(_args: GetEntityNamesArgs): Promise<GetEntityNamesResponse>;
getServiceNames(_args: GetServiceNamesArgs): Promise<GetServiceNamesResponse>;
getEnvironments(_args: GetEnvironmentsArgs): Promise<GetEnvironmentsResponse>;
getTags(_args: GetTagsArgs): Promise<GetTagsResponse>;
/**
* Creates a single score record.
*/
createScore(_args: CreateScoreArgs): Promise<void>;
/**
* Creates multiple score observations in a single batch.
*/
batchCreateScores(_args: BatchCreateScoresArgs): Promise<void>;
/**
* Retrieves a list of scores with optional filtering.
*/
listScores(_args: ListScoresArgs): Promise<ListScoresResponse>;
/**
* Retrieves a single score by its score ID.
*/
getScoreById(_scoreId: string): Promise<ScoreRecord | null>;
getScoreAggregate(_args: GetScoreAggregateArgs): Promise<GetScoreAggregateResponse>;
getScoreBreakdown(_args: GetScoreBreakdownArgs): Promise<GetScoreBreakdownResponse>;
getScoreTimeSeries(_args: GetScoreTimeSeriesArgs): Promise<GetScoreTimeSeriesResponse>;
getScorePercentiles(_args: GetScorePercentilesArgs): Promise<GetScorePercentilesResponse>;
/**
* Deletes score records by id. Idempotent: deleting missing ids succeeds; an
* empty ids array is a no-op. When `organizationId`/`resourceId` are provided,
* only scores matching that tenant scope are deleted.
*/
deleteScores(args: DeleteScoresArgs): Promise<void>;
/**
* Creates a single feedback record.
*/
createFeedback(_args: CreateFeedbackArgs): Promise<void>;
/** Replace a complete feedback record, preserving its identity. Missing records are created. */
replaceFeedback(args: CreateFeedbackArgs): Promise<void>;
/** Adapters with atomic writes override this fallback; ClickHouse retains sequential protection. */
protected writeFeedbackReplacement({ feedback }: CreateFeedbackArgs): Promise<void>;
protected assertFeedbackReplacementIdentity(feedback: CreateFeedbackArgs['feedback'], existing: FeedbackRecord | null | undefined): void;
/** Creates multiple feedback observations in a single batch. */
batchCreateFeedback(_args: BatchCreateFeedbackArgs): Promise<void>;
/**
* Retrieves a list of feedback with optional filtering.
*/
listFeedback(_args: ListFeedbackArgs): Promise<ListFeedbackResponse>;
/** Retrieves one feedback record by ID, or null when it does not exist. */
getFeedbackById(_feedbackId: string): Promise<FeedbackRecord | null>;
updateFeedbackReviewStatus(_args: UpdateFeedbackReviewStatusArgs): Promise<FeedbackRecord>;
getFeedbackAggregate(_args: GetFeedbackAggregateArgs): Promise<GetFeedbackAggregateResponse>;
getFeedbackBreakdown(_args: GetFeedbackBreakdownArgs): Promise<GetFeedbackBreakdownResponse>;
getFeedbackTimeSeries(_args: GetFeedbackTimeSeriesArgs): Promise<GetFeedbackTimeSeriesResponse>;
getFeedbackPercentiles(_args: GetFeedbackPercentilesArgs): Promise<GetFeedbackPercentilesResponse>;
/**
* Deletes feedback records by id. Idempotent: deleting missing ids succeeds;
* an empty ids array is a no-op. When `organizationId`/`resourceId` are
* provided, only feedback matching that tenant scope is deleted.
*/
deleteFeedback(args: DeleteFeedbackArgs): Promise<void>;
}
//# sourceMappingURL=base.d.ts.map