docs/src/content/en/reference/observability/tracing/instances.mdx
import PropertiesTable from "@site/src/components/PropertiesTable";
DefaultObservabilityInstanceDefault implementation of the ObservabilityInstance interface.
new DefaultObservabilityInstance(config: ObservabilityInstanceConfig)
Creates a new DefaultObservabilityInstance with the specified configuration.
Inherits all properties and methods from BaseObservabilityInstance.
BaseObservabilityInstanceBase class for custom ObservabilityInstance implementations.
getConfiggetConfig(): Readonly<Required<ObservabilityInstanceConfig>>
Returns the current observability configuration.
getExportersgetExporters(): readonly ObservabilityExporter[]
Returns all configured exporters.
getSpanOutputProcessorsgetSpanOutputProcessors(): readonly SpanOutputProcessor[]
Returns all configured span output processors.
getLoggergetLogger(): IMastraLogger
Returns the logger instance for exporters and other components.
startSpanstartSpan<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.
<PropertiesTable props={[ { name: 'type', type: 'SpanType', description: 'Type of span to create', required: true, }, { name: 'name', type: 'string', description: 'Name of the span', required: true, }, { name: 'parent', type: 'AnySpan', description: 'Parent span (if not root)', required: false, }, { name: 'attributes', type: 'SpanTypeMap[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, }, ]} />
async shutdown(): Promise<void>
Shuts down all exporters and processors, cleaning up resources.
To create a custom ObservabilityInstance implementation, extend BaseObservabilityInstance:
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)
}
}