OtelConfig
The OtelConfig
object is used to configure OpenTelemetry instrumentation, tracing, and exporting behavior within your application. By adjusting its properties, you can control how telemetry data (such as traces) is collected, sampled, and exported.
To use the OtelConfig
within Mastra, pass it as the value of the telemetry
key when initializing Mastra. This will configure Mastra to use your custom OpenTelemetry settings for tracing and instrumentation.
import { Mastra } from 'mastra';
const otelConfig: OtelConfig = {
serviceName: 'my-awesome-service',
enabled: true,
sampling: {
type: 'ratio',
probability: 0.5,
},
export: {
type: 'otlp',
endpoint: 'https://otel-collector.example.com/v1/traces',
headers: {
Authorization: 'Bearer YOUR_TOKEN_HERE',
},
},
};
Properties
serviceName?:
string
Human-readable name used to identify your service in telemetry backends.
enabled?:
boolean
Whether telemetry collection and export are enabled.
sampling?:
SamplingStrategy
Defines the sampling strategy for traces, controlling how much data is collected.
'ratio' | 'always_on' | 'always_off' | 'parent_based'
number (0.0 to 1.0)
object
export?:
object
Configuration for exporting collected telemetry data.
'otlp' | 'console'
string
Record<string, string>