# Observability Instances

## `DefaultObservabilityInstance`

Default implementation of the ObservabilityInstance interface.

### Constructor

```typescript
new DefaultObservabilityInstance(config: ObservabilityInstanceConfig)
```

Creates a new DefaultObservabilityInstance with the specified configuration.

### Properties

Inherits all properties and methods from BaseObservabilityInstance.

## `BaseObservabilityInstance`

Base class for custom ObservabilityInstance implementations.

### Methods

#### `getConfig`

```typescript
getConfig(): Readonly<Required<ObservabilityInstanceConfig>>
```

Returns the current observability configuration.

#### `getExporters`

```typescript
getExporters(): readonly ObservabilityExporter[]
```

Returns all configured exporters.

#### `getSpanOutputProcessors`

```typescript
getSpanOutputProcessors(): readonly SpanOutputProcessor[]
```

Returns all configured span output processors.

#### `getLogger`

```typescript
getLogger(): IMastraLogger
```

Returns the logger instance for exporters and other components.

#### `startSpan`

```typescript
startSpan<TType extends SpanType>(
  options: StartSpanOptions<TType>
): Span<TType>
```

Start a new span of a specific SpanType. Creates the root span of a trace if no parent is provided.

#### shutdown

```typescript
async shutdown(): Promise<void>
```

Shuts down all exporters and processors, cleaning up resources.

## Custom implementation

To create a custom ObservabilityInstance implementation, extend BaseObservabilityInstance:

```typescript
class CustomObservabilityInstance extends BaseObservabilityInstance {
  constructor(config: ObservabilityInstanceConfig) {
    super(config)
    // Custom initialization
  }

  // Override methods as needed
  startSpan<TType extends SpanType>(options: StartSpanOptions<TType>): Span<TType> {
    // Custom span creation logic
    return super.startSpan(options)
  }
}
```

## See also

### Documentation

- [Tracing Overview](https://mastra.ai/docs/observability/tracing/overview) - Concepts and usage guide
- [Configuration Reference](https://mastra.ai/reference/observability/tracing/configuration) - Configuration options
- [Interfaces Reference](https://mastra.ai/reference/observability/tracing/interfaces) - Type definitions
- [Spans Reference](https://mastra.ai/reference/observability/tracing/spans) - Span lifecycle and methods

### Exporters

- [DefaultExporter](https://mastra.ai/reference/observability/tracing/exporters/default-exporter) - Storage persistence
- [CloudExporter](https://mastra.ai/reference/observability/tracing/exporters/cloud-exporter) - Mastra Cloud integration
- [ConsoleExporter](https://mastra.ai/reference/observability/tracing/exporters/console-exporter) - Debug output