# AITracing
[EN] Source: https://mastra.ai/reference/observability/ai-tracing/ai-tracing

## DefaultAITracing

Default implementation of the AITracing interface.

### Constructor

```typescript
new DefaultAITracing(config: TracingConfig)
```

Creates a new DefaultAITracing instance with the specified configuration.

### Properties

Inherits all properties and methods from BaseAITracing.

## BaseAITracing

Base class for custom AI tracing implementations.

### Methods

#### getConfig

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

Returns the current tracing configuration.

#### getExporters

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

Returns all configured exporters.

#### getProcessors

```typescript
getProcessors(): readonly AISpanProcessor[]
```

Returns all configured processors.

#### getLogger

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

Returns the logger instance for exporters and other components.

#### startSpan

```typescript
startSpan<TType extends AISpanType>(
  options: StartSpanOptions<TType>
): AISpan<TType>
```

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

<PropertiesTable
  props={[
    {
      name: "type",
      type: "AISpanType",
      description: "Type of span to create",
      required: true,
    },
    {
      name: "name",
      type: "string",
      description: "Name of the span",
      required: true,
    },
    {
      name: "parent",
      type: "AnyAISpan",
      description: "Parent span (if not root)",
      required: false,
    },
    {
      name: "attributes",
      type: "AISpanTypeMap[TType]",
      description: "Type-specific attributes",
      required: false,
    },
    {
      name: "metadata",
      type: "Record<string, any>",
      description: "User-defined metadata",
      required: false,
    },
    {
      name: "input",
      type: "any",
      description: "Initial input data",
      required: false,
    },
    {
      name: "customSamplerOptions",
      type: "CustomSamplerOptions",
      description: "Options for custom sampler",
      required: false,
    },
  ]}
/>

#### shutdown

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

Shuts down all exporters and processors, cleaning up resources.

## Custom Implementation

To create a custom AI tracing implementation, extend BaseAITracing:

```typescript
class CustomAITracing extends BaseAITracing {
  constructor(config: TracingConfig) {
    super(config);
    // Custom initialization
  }

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

## NO-OP Spans

When tracing is disabled (sampling returns false), NO-OP spans are returned:

### NoOpAISpan

```typescript
class NoOpAISpan<TType extends AISpanType> extends BaseAISpan<TType>
```

A span that performs no operations. All methods are no-ops:

- `id` returns `'no-op'`
- `traceId` returns `'no-op-trace'`
- `isValid` returns `false`
- `end()`, `error()`, `update()` do nothing
- `createChildSpan()` returns another NO-OP span

## See Also

### Documentation

- [AI Tracing Overview](/docs/observability/ai-tracing/overview) - Concepts and usage guide
- [Configuration Reference](/reference/observability/ai-tracing/configuration) - Configuration options
- [Interfaces Reference](/reference/observability/ai-tracing/interfaces) - Type definitions
- [Span Reference](/reference/observability/ai-tracing/span) - Span lifecycle and methods

### Examples

- [Basic AI Tracing](/examples/observability/basic-ai-tracing) - Getting started example

### Exporters

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


---
title: "Reference: Configuration | Observability"
description: AI Tracing configuration types and registry functions
---

import PropertiesTable from "@site/src/components/PropertiesTable";