@mastra/core
Version:
146 lines • 8.67 kB
TypeScript
import { TokenMetrics } from '../../../observability/types/metrics.js';
import type { TraceQueryMetadataField } from './trace-query.js';
export interface TraceAggregateDimensionRule {
valueKind: 'string';
}
/**
* Trace-scope groupable dimensions for `aggregateTraces()`.
* Key order is the spec order and is the order discovery lists them in. Top-level
* `metadata.<key>` paths are also groupable; see `isTraceAggregateDimension`.
*/
export declare const TRACE_AGGREGATE_DIMENSION_REGISTRY: {
readonly entityType: TraceAggregateDimensionRule;
readonly entityName: TraceAggregateDimensionRule;
readonly name: TraceAggregateDimensionRule;
readonly spanType: TraceAggregateDimensionRule;
readonly entityId: TraceAggregateDimensionRule;
readonly environment: TraceAggregateDimensionRule;
readonly status: TraceAggregateDimensionRule;
readonly outcome: TraceAggregateDimensionRule;
readonly stopReason: TraceAggregateDimensionRule;
readonly serviceName: TraceAggregateDimensionRule;
readonly executionSource: TraceAggregateDimensionRule;
readonly threadId: TraceAggregateDimensionRule;
readonly resourceId: TraceAggregateDimensionRule;
readonly userId: TraceAggregateDimensionRule;
readonly sessionId: TraceAggregateDimensionRule;
readonly organizationId: TraceAggregateDimensionRule;
readonly experimentId: TraceAggregateDimensionRule;
};
export declare const TRACE_AGGREGATE_METADATA_DIMENSION_RULE: TraceAggregateDimensionRule;
/** Identity fields excluded from grouping: grouping by identity is not grouping. */
export declare const TRACE_AGGREGATE_IDENTITY_FIELDS: readonly ['traceId', 'spanId', 'runId', 'requestId'];
export type TraceAggregateCanonicalDimension = keyof typeof TRACE_AGGREGATE_DIMENSION_REGISTRY;
export type TraceAggregateDimension = TraceAggregateCanonicalDimension | TraceQueryMetadataField;
export type TraceAggregateCountDistinctField = TraceAggregateDimension | 'traceId';
export declare function isTraceAggregateCanonicalDimension(path: string): path is TraceAggregateCanonicalDimension;
/**
* Whether an already-normalized path may appear in `groupBy`. Callers unwrap
* `${...}` templates and trim before calling; this predicate does no normalization.
*/
export declare function isTraceAggregateDimension(path: string): path is TraceAggregateDimension;
export declare function isTraceAggregateCountDistinctField(path: string): path is TraceAggregateCountDistinctField;
export declare function getTraceAggregateDimensionRule(path: string): TraceAggregateDimensionRule | undefined;
export type TraceAggregateMeasureKind = 'count' | 'duration' | 'error' | 'tokens' | 'cost' | 'timeToFirstToken' | 'timeToFirstChunk';
export type TraceAggregateMeasureStatistic = 'avg' | 'min' | 'max' | 'p50' | 'p90' | 'p95' | 'p99' | 'sum' | 'count';
export type TraceAggregateMeasureUnit = 'count' | 'milliseconds' | 'ratio' | 'tokens' | 'currency';
export interface TraceAggregateMeasureRule {
kind: TraceAggregateMeasureKind;
statistic?: TraceAggregateMeasureStatistic;
unit: TraceAggregateMeasureUnit;
/** Percentiles tolerate backend-native approximation; counts, sums, and rates never do. */
approximate: boolean;
/**
* Token metric rows the measure is computed from. For `tokens.*` the per-trace
* value is the sum of these rows' `value`; for `cost.*` it is the sum of their priced
* `estimatedCost`. Absent for measures computed from the trace root.
*/
metricNames?: readonly TokenMetrics[];
/**
* Nullable span column the measure reads, for `timeToFirstToken.*` and `timeToFirstChunk.*`.
* Rows without a value are skipped, never read as 0; `.count` counts the rows that have one.
*/
field?: TraceAggregateTimeToFirstField;
}
export type TraceAggregateTimeToFirstField = 'timeToFirstTokenMs' | 'timeToFirstChunkMs';
/**
* Token metric rows that carry the per-call cost. Each total row already holds the sum of its
* detail rows' costs, so cost is summed over these rows only.
*/
export declare const TRACE_AGGREGATE_COST_METRIC_NAMES: readonly ["mastra_model_total_input_tokens", "mastra_model_total_output_tokens"];
/** Every token metric name a token or cost measure reads; store compilers prune metric rows to these. */
export declare const TRACE_AGGREGATE_USAGE_METRIC_NAMES: readonly ["mastra_model_total_input_tokens", "mastra_model_total_output_tokens", "mastra_model_output_reasoning_tokens", "mastra_model_input_cache_read_tokens"];
/**
* Measures for `aggregateTraces()`: the measures computed from the trace root, followed by the
* token and cost measures, then time to first token/chunk. Time-to-first measures read the root
* span's value in `aggregateTraces()` (the value `queryTraces()` returns) and each span's own value
* in `aggregateSpans()`; they need the `aggregate-time-to-first-measures` store feature.
* `countDistinct.<field>` is a family keyed by field and is handled by
* `parseTraceAggregateMeasure` rather than listed here.
*/
export declare const TRACE_AGGREGATE_MEASURE_REGISTRY: {
readonly count: TraceAggregateMeasureRule;
readonly 'duration.avg': TraceAggregateMeasureRule;
readonly 'duration.min': TraceAggregateMeasureRule;
readonly 'duration.max': TraceAggregateMeasureRule;
readonly 'duration.p50': TraceAggregateMeasureRule;
readonly 'duration.p90': TraceAggregateMeasureRule;
readonly 'duration.p95': TraceAggregateMeasureRule;
readonly 'duration.p99': TraceAggregateMeasureRule;
readonly errorCount: TraceAggregateMeasureRule;
readonly errorRate: TraceAggregateMeasureRule;
readonly 'tokens.input.sum': TraceAggregateMeasureRule;
readonly 'tokens.input.avg': TraceAggregateMeasureRule;
readonly 'tokens.output.sum': TraceAggregateMeasureRule;
readonly 'tokens.output.avg': TraceAggregateMeasureRule;
readonly 'tokens.total.sum': TraceAggregateMeasureRule;
readonly 'tokens.total.avg': TraceAggregateMeasureRule;
readonly 'tokens.reasoning.sum': TraceAggregateMeasureRule;
readonly 'tokens.reasoning.avg': TraceAggregateMeasureRule;
readonly 'tokens.cached.sum': TraceAggregateMeasureRule;
readonly 'tokens.cached.avg': TraceAggregateMeasureRule;
readonly 'cost.sum': TraceAggregateMeasureRule;
readonly 'cost.avg': TraceAggregateMeasureRule;
readonly 'timeToFirstToken.avg': TraceAggregateMeasureRule;
readonly 'timeToFirstToken.min': TraceAggregateMeasureRule;
readonly 'timeToFirstToken.max': TraceAggregateMeasureRule;
readonly 'timeToFirstToken.p50': TraceAggregateMeasureRule;
readonly 'timeToFirstToken.p90': TraceAggregateMeasureRule;
readonly 'timeToFirstToken.p95': TraceAggregateMeasureRule;
readonly 'timeToFirstToken.p99': TraceAggregateMeasureRule;
readonly 'timeToFirstToken.count': TraceAggregateMeasureRule;
readonly 'timeToFirstChunk.avg': TraceAggregateMeasureRule;
readonly 'timeToFirstChunk.min': TraceAggregateMeasureRule;
readonly 'timeToFirstChunk.max': TraceAggregateMeasureRule;
readonly 'timeToFirstChunk.p50': TraceAggregateMeasureRule;
readonly 'timeToFirstChunk.p90': TraceAggregateMeasureRule;
readonly 'timeToFirstChunk.p95': TraceAggregateMeasureRule;
readonly 'timeToFirstChunk.p99': TraceAggregateMeasureRule;
readonly 'timeToFirstChunk.count': TraceAggregateMeasureRule;
};
export type TraceAggregateCanonicalMeasure = keyof typeof TRACE_AGGREGATE_MEASURE_REGISTRY;
export type TraceAggregateCountDistinctMeasure = `countDistinct.${TraceAggregateCountDistinctField}`;
export type ParsedTraceAggregateMeasure = {
type: 'canonical';
measure: TraceAggregateCanonicalMeasure;
rule: TraceAggregateMeasureRule;
} | {
type: 'countDistinct';
field: TraceAggregateCountDistinctField;
};
export declare function isTraceAggregateCanonicalMeasure(name: string): name is TraceAggregateCanonicalMeasure;
export declare function parseTraceAggregateMeasure(name: string): ParsedTraceAggregateMeasure | undefined;
export interface TraceAggregateDimensionDescriptor {
path: TraceAggregateCanonicalDimension;
valueKind: TraceAggregateDimensionRule['valueKind'];
}
export interface TraceAggregateMeasureDescriptor {
name: TraceAggregateCanonicalMeasure;
kind: TraceAggregateMeasureKind;
statistic?: TraceAggregateMeasureStatistic;
unit: TraceAggregateMeasureUnit;
approximate: boolean;
}
export declare function getTraceAggregateDimensionDescriptors(): TraceAggregateDimensionDescriptor[];
export declare function getTraceAggregateMeasureDescriptors(): TraceAggregateMeasureDescriptor[];
//# sourceMappingURL=trace-aggregate-registry.d.ts.map