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

  1. Replace the call with getMetricsByName(metricName) to filter by metric name
  2. If type-based filtering is needed, collect metrics via the export path and filter the returned ExportedMetric objects yourself
  3. 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

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


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/505ce45db0c97dca. Report an issue: GitHub.