Skip to main content

DefaultExporter

Deprecated in @mastra/observability@1.12.0 in favor of MastraStorageExporter.

Deprecated

DefaultExporter is retained for backward compatibility and will be removed in a future major version. Use MastraStorageExporter for new projects. Both classes share the same constructor and runtime behavior, except on Mastra Platform: DefaultExporter is always disabled there, while MastraStorageExporter can be kept with retainStorageExporterOnPlatform: true and a remote observability store. DefaultExporter accepts the same configuration except byteBatching, which only MastraStorageExporter supports. DefaultExporter keeps its original mastra-default-observability-exporter exporter name so monitoring rules built against it keep working.

Persists observability events to Mastra Storage with automatic batching and retry logic.

Constructor
Direct link to Constructor

new DefaultExporter(config?: DefaultExporterConfig)

DefaultExporterConfig
Direct link to defaultexporterconfig

interface DefaultExporterConfig extends BaseExporterConfig {
/** Maximum number of spans per batch. Default: 1000 */
maxBatchSize?: number

/** Maximum total buffer size before emergency flush. Default: 10000 */
maxBufferSize?: number

/** Maximum time to wait before flushing batch in milliseconds. Default: 5000 */
maxBatchWaitMs?: number

/** Maximum number of retry attempts. Default: 4 */
maxRetries?: number

/** Base retry delay in milliseconds (uses exponential backoff). Default: 500 */
retryDelayMs?: number

/** Tracing storage strategy or 'auto' for automatic selection. Default: 'auto' */
strategy?: TracingStorageStrategy | 'auto'
}

Extends BaseExporterConfig, which includes:

  • logger?: IMastraLogger - Logger instance
  • logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error' - Log level (default: INFO)

TracingStorageStrategy
Direct link to tracingstoragestrategy

type TracingStorageStrategy = 'realtime' | 'batch-with-updates' | 'insert-only' | 'event-sourced'

Strategy behaviors
Direct link to Strategy behaviors

  • realtime: Immediately persists each event to storage
  • batch-with-updates: Batches creates and updates separately, applies in order
  • insert-only: Only processes SPAN_ENDED events, ignores updates

Properties
Direct link to Properties

readonly name = 'mastra-default-observability-exporter';

Methods
Direct link to Methods

init
Direct link to init

init(options: InitExporterOptions): Promise<void>

Initializes the exporter after dependencies are ready. Resolves tracing strategy based on storage capabilities.

exportTracingEvent
Direct link to exporttracingevent

async exportTracingEvent(event: TracingEvent): Promise<void>

Processes a tracing event according to the resolved strategy.

flush
Direct link to flush

async flush(): Promise<void>

Force flushes any buffered events to storage without shutting down the exporter. Useful in serverless environments where you need to ensure spans are exported before the runtime terminates.

shutdown
Direct link to shutdown

async shutdown(): Promise<void>

Flushes remaining buffered events and performs cleanup.

Automatic strategy selection
Direct link to Automatic strategy selection

When strategy: 'auto' (default), the exporter queries the storage adapter for its capabilities:

interface TracingStrategy {
/** Strategies supported by this adapter */
supported: TracingStorageStrategy[]

/** Preferred strategy for optimal performance */
preferred: TracingStorageStrategy
}

The exporter will:

  1. Use the storage adapter's preferred strategy when strategy is 'auto'
  2. Use a user-specified strategy if the storage adapter supports it
  3. Log a warning and fall back to the preferred strategy if a user-specified strategy isn't supported

Batching behavior
Direct link to Batching behavior

Flush triggers
Direct link to Flush triggers

The buffer flushes when any of these conditions are met:

  • Buffer size reaches maxBatchSize
  • Time since first buffered event exceeds maxBatchWaitMs
  • Buffer size reaches maxBufferSize (emergency flush)
  • shutdown() is called

Retry logic
Direct link to Retry logic

Failed flushes are retried with exponential backoff:

  • Retry delay: retryDelayMs * 2^(attempt - 1). The first retry waits retryDelayMs.
  • Maximum attempts: maxRetries
  • Batch is dropped after all retries fail

When storage doesn't support a signal or retries are exhausted, DefaultExporter emits an ObservabilityDropEvent through onDroppedEvent handlers registered on exporters and bridges. The drop event includes the signal, reason, count, exporter name, storage name when known, and sanitized error details.

Out-of-order handling
Direct link to Out-of-order handling

For batch-with-updates strategy:

  • Tracks which spans have been created
  • Defers updates/ends for spans not yet created and retries them on a later flush. Each deferral counts toward maxRetries. When the deferral count exceeds maxRetries, the update is dropped and reported as a retry-exhausted drop event. If storage doesn't support tracing, deferred updates are dropped immediately with an unsupported-storage drop event and aren't retried
  • Logs warnings for out-of-order events
  • Maintains sequence numbers for ordered updates

Usage
Direct link to Usage

import { DefaultExporter } from '@mastra/observability'

// Default configuration
const exporter = new DefaultExporter()

// Custom batching configuration
const customExporter = new DefaultExporter({
maxBatchSize: 500,
maxBatchWaitMs: 2000,
strategy: 'batch-with-updates',
logLevel: 'debug',
})

See also
Direct link to See also

Documentation
Direct link to Documentation

Other exporters
Direct link to Other exporters

Reference
Direct link to Reference