mastra-ai/mastra · error · MastraError

OBSERVABILITY_STORAGE_GET_METRIC_AGGREGATE_NOT_IMPLEMENTED

OBSERVABILITY_STORAGE_GET_METRIC_AGGREGATE_NOT_IMPLEMENTED

Error message

This storage provider does not support metric aggregation

What it means

MastraError OBSERVABILITY_STORAGE_GET_METRIC_AGGREGATE_NOT_IMPLEMENTED is thrown by the default getMetricAggregate() implementation in the observability storage base class (packages/core/src/storage/domains/observability/base.ts:450). It indicates the active storage adapter does not implement metric aggregation (e.g. sum/count/avg over metric observations). The base class throws for every unimplemented method so adapters only need to override what they support.

Source

Thrown at packages/core/src/storage/domains/observability/base.ts:450

    throw new MastraError({
      id: 'OBSERVABILITY_STORAGE_BATCH_CREATE_METRICS_NOT_IMPLEMENTED',
      domain: ErrorDomain.MASTRA_OBSERVABILITY,
      category: ErrorCategory.SYSTEM,
      text: 'This storage provider does not support batch creating metrics',
    });
  }

  async listMetrics(_args: ListMetricsArgs): Promise<ListMetricsResponse> {
    throw new MastraError({
      id: 'OBSERVABILITY_STORAGE_LIST_METRICS_NOT_IMPLEMENTED',
      domain: ErrorDomain.MASTRA_OBSERVABILITY,
      category: ErrorCategory.SYSTEM,
      text: 'This storage provider does not support listing metrics',
    });
  }

  async getMetricAggregate(_args: GetMetricAggregateArgs): Promise<GetMetricAggregateResponse> {
    throw new MastraError({
      id: 'OBSERVABILITY_STORAGE_GET_METRIC_AGGREGATE_NOT_IMPLEMENTED',
      domain: ErrorDomain.MASTRA_OBSERVABILITY,
      category: ErrorCategory.SYSTEM,
      text: 'This storage provider does not support metric aggregation',
    });
  }

  async getMetricBreakdown(_args: GetMetricBreakdownArgs): Promise<GetMetricBreakdownResponse> {
    throw new MastraError({
      id: 'OBSERVABILITY_STORAGE_GET_METRIC_BREAKDOWN_NOT_IMPLEMENTED',
      domain: ErrorDomain.MASTRA_OBSERVABILITY,
      category: ErrorCategory.SYSTEM,
      text: 'This storage provider does not support metric breakdown',
    });
  }

  async getMetricTimeSeries(_args: GetMetricTimeSeriesArgs): Promise<GetMetricTimeSeriesResponse> {
    throw new MastraError({

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Use a storage adapter that implements getMetricAggregate or upgrade the existing adapter package to a version that does.
  2. Change storage configuration to a metrics-capable provider (e.g. PostgreSQL) if you need metric aggregates.
  3. If you own a custom adapter, implement getMetricAggregate returning the computed GetMetricAggregateResponse for your backend.
  4. Guard the call site: detect missing support (instance does not override getMetricAggregate) and return null/empty instead of throwing.

Example fix

// before
await storage.getMetricAggregate({ metricName: 'agent_tokens' }); // throws
// after
const aggregate = storage.getMetricAggregate !== MastraStorage.prototype.getMetricAggregate
  ? await storage.getMetricAggregate({ metricName: 'agent_tokens' })
  : null;
Defensive patterns

Strategy: fallback

Validate before calling

import { MastraStorage } from '@mastra/core/storage';

function supportsMetricAggregate(storage: unknown): boolean {
  return (
    storage instanceof MastraStorage &&
    (storage as MastraStorage).getMetricAggregate !== MastraStorage.prototype.getMetricAggregate
  );
}

if (!supportsMetricAggregate(storage)) {
  console.warn('Aggregate metric queries unsupported by this storage adapter');
}

Type guard

function supportsMetricAggregate(s: unknown): s is MastraStorage & { getMetricAggregate: (a: GetMetricAggregateArgs) => Promise<GetMetricAggregateResponse> } {
  return s instanceof MastraStorage && s.getMetricAggregate !== MastraStorage.prototype.getMetricAggregate;
}

Try / catch

import { MastraError } from '@mastra/core/error';

try {
  const agg = await storage.getMetricAggregate(args);
} catch (err) {
  if (err instanceof MastraError && err.id === 'OBSERVABILITY_STORAGE_GET_METRIC_AGGREGATE_NOT_IMPLEMENTED') {
    const agg = null; // render 'aggregates unavailable' instead of failing
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: Calling getMetricAggregate(args) on a storage adapter that has not overridden it — typically through the metrics API/Studio metric summary view while connected to a provider lacking metrics aggregation support.

Common situations: Requesting an aggregate (count/sum/avg) for a metric in Studio against an adapter that only stores spans; custom MastraStorage subclass missing getMetricAggregate; mixing a newer core version that queries aggregates with an older storage package.

Related errors


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