mastra-ai/mastra · error · MastraError

OBSERVABILITY_STORAGE_BATCH_CREATE_METRICS_NOT_IMPLEMENTED

OBSERVABILITY_STORAGE_BATCH_CREATE_METRICS_NOT_IMPLEMENTED

Error message

This storage provider does not support batch creating metrics

What it means

This error is thrown by the base MastraObservabilityStorage class's batchCreateMetrics method, a default implementation that always throws. It means the storage provider has not implemented persisting multiple metric observations in a single batch. The library throws to signal the optional capability is unavailable rather than silently dropping metrics.

Source

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

   */
  async listLogs(_args: ListLogsArgs): Promise<ListLogsResponse> {
    throw new MastraError({
      id: 'OBSERVABILITY_STORAGE_LIST_LOGS_NOT_IMPLEMENTED',
      domain: ErrorDomain.MASTRA_OBSERVABILITY,
      category: ErrorCategory.SYSTEM,
      text: 'This storage provider does not support listing logs',
    });
  }

  // ============================================================================
  // Metrics
  // ============================================================================

  /**
   * Creates multiple metric observations in a single batch.
   */
  async batchCreateMetrics(_args: BatchCreateMetricsArgs): Promise<void> {
    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({

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Switch to a storage provider that implements batchCreateMetrics.
  2. Fall back to creating metric observations one at a time via the single-record create API if available.
  3. If you own the provider, override batchCreateMetrics with a bulk insert.
  4. Catch this error in the metrics flush loop and fall back to sequential writes (or skip with a warning if metrics are best-effort).

Example fix

// before
await storage.batchCreateMetrics({ metrics });
// after
try {
  await storage.batchCreateMetrics({ metrics });
} catch (e) {
  if (e instanceof MastraError && e.id === 'OBSERVABILITY_STORAGE_BATCH_CREATE_METRICS_NOT_IMPLEMENTED') {
    for (const m of metrics) await storage.createMetric(m);
  } else {
    throw e;
  }
}
Defensive patterns

Strategy: try-catch

Validate before calling

const supportsBatchCreateMetrics = typeof storage.batchCreateMetrics === 'function' && storage.batchCreateMetrics !== MastraObservabilityStorage.prototype.batchCreateMetrics;
if (!supportsBatchCreateMetrics) { /* flush metrics individually or skip */ }

Type guard

function supportsBatchCreateMetrics(s: unknown): s is MastraObservabilityStorage & { batchCreateMetrics: (a: BatchCreateMetricsArgs) => Promise<void> } {
  return s instanceof MastraObservabilityStorage && (s as any).batchCreateMetrics !== MastraObservabilityStorage.prototype.batchCreateMetrics;
}

Try / catch

try {
  await storage.batchCreateMetrics({ metrics });
} catch (e) {
  if (e instanceof MastraError && e.id === 'OBSERVABILITY_STORAGE_BATCH_CREATE_METRICS_NOT_IMPLEMENTED') {
    for (const m of metrics) await storage.createMetric(m);
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Calling storage.batchCreateMetrics(args) (BatchCreateMetricsArgs) on a provider that inherits the base default, e.g. an OpenTelemetry-style metrics exporter flushing a batch of observations through the observability storage domain.

Common situations: Enabling metrics collection with a minimal storage adapter that only supports traces/spans; a custom driver extending the base class without overriding batch methods; buffered metric exporters that assume batch writes are supported; upgrading to a Mastra version that routes metrics through the batch API while the provider lags behind.

Related errors


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