mastra-ai/mastra · error
getMetricsByType() has been removed: metricType is no longer
Error message
getMetricsByType() has been removed: metricType is no longer stored. Use getMetricsByName(metricName) instead to filter metrics by name.
What it means
TestExporter previously keyed stored metrics by metricType; the metrics format no longer stores metricType, so this public method was turned into a hard-throwing tombstone. It exists purely to point migrators to the replacement API getMetricsByName(metricName).
Source
Thrown at observability/mastra/src/exporters/test.ts:701
/**
* Get all collected metrics (unwrapped from events)
*/
getAllMetrics(): ExportedMetric[] {
return this.#metricEvents.map(e => e.metric);
}
/**
* Get metrics filtered by name
*/
getMetricsByName(name: string): ExportedMetric[] {
return this.#metricEvents.filter(e => e.metric.name === name).map(e => e.metric);
}
/**
* @deprecated MetricType is no longer stored. Use getMetricsByName() instead.
*/
getMetricsByType(_metricType: string): ExportedMetric[] {
throw new Error(
'getMetricsByType() has been removed: metricType is no longer stored. ' +
'Use getMetricsByName(metricName) instead to filter metrics by name.',
);
}
// ============================================================================
// Score Query Methods
// ============================================================================
/**
* Get all collected score events
*/
getScoreEvents(): ScoreEvent[] {
return [...this.#scoreEvents];
}
/**
* Get all collected scores (unwrapped from events)View on GitHub (pinned to 75dd419e61)
Solutions
- Replace the call with getMetricsByName(metricName) to filter by metric name
- If type-based filtering is needed, collect metrics via the export path and filter the returned ExportedMetric objects yourself
- Remove the call if the type filter was vestigial
Example fix
// before
const counters = exporter.getMetricsByType('counter');
// after
const counters = exporter.getMetricsByName('my.counter').filter(m => m.type === 'counter'); Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof (exporter as any).getMetricsByName !== 'function') {
throw new Error('TestExporter version without getMetricsByName; upgrade before using name-based filtering.');
} Type guard
function supportsGetMetricsByName(e: unknown): e is { getMetricsByName(name: string): unknown[] } {
return typeof e === 'object' && e !== null && typeof (e as any).getMetricsByName === 'function';
} Try / catch
let metrics: ExportedMetric[];
try {
metrics = exporter.getMetricsByName('my.metric');
} catch (err) {
if ((err as Error).message.startsWith('getMetricsByType() has been removed')) {
metrics = []; // migrate call site
} else throw err;
} Prevention
- Search the codebase for getMetricsByType before upgrading
- Use getMetricsByName as the canonical filter API
- Wrap deprecated APIs behind a small adapter you migrate in one place
When it happens
Trigger: Calling exporter.getMetricsByType(anyType) on a TestExporter instance after upgrading to the version that removed metricType storage.
Common situations: Post-upgrade test suites or custom reporters filtering exported metrics by type; stale utilities written against the old metric storage format.
Related errors
- WORKFLOW_WAIT_FOR_EVENT_REMOVED
- toAISdkFormat() has been deprecated. Please use toAISdkStrea
- tagWorker method is no longer supported. Use the Cloudflare
- MastraFactory: 'sandbox' is now a callback, not an options o
- Repository ${id} not found in organization ${orgId}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/505ce45db0c97dca.
Report an issue: GitHub.