AITracing
DefaultAITracing
Default implementation of the AITracing interface.
Constructor
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
getConfig(): Readonly<Required<TracingConfig>>
Returns the current tracing configuration.
getExporters
getExporters(): readonly AITracingExporter[]
Returns all configured exporters.
getProcessors
getProcessors(): readonly AISpanProcessor[]
Returns all configured processors.
getLogger
getLogger(): IMastraLogger
Returns the logger instance for exporters and other components.
startSpan
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.
shutdown
async shutdown(): Promise<void>
Shuts down all exporters and processors, cleaning up resources.
Custom Implementation
To create a custom AI tracing implementation, extend BaseAITracing:
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
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
returnsfalse
end()
,error()
,update()
do nothingcreateChildSpan()
returns another NO-OP span
See Also
Documentation
- AI Tracing Overview - Concepts and usage guide
- Configuration Reference - Configuration options
- Interfaces Reference - Type definitions
- Span Reference - Span lifecycle and methods
Examples
- Basic AI Tracing - Getting started example
Exporters
- DefaultExporter - Storage persistence
- CloudExporter - Mastra Cloud integration
- ConsoleExporter - Debug output