Skip to main content

Tracing Mastra

Mastra Tracing

MLflow Tracing provides automatic tracing capability for Mastra, a flexible and modular AI agents framework developed by Mastra. MLflow supports tracing for Mastra through the OpenTelemetry integration.

Step 1: Create a new Mastra agent

bash
npm create mastra@laster

This will create a new TypeScript project with a simple tool calling agent implementation.

Step 2: Start the MLflow Tracking Server

Start the MLflow Tracking Server with a SQL-based backend store:

bash
mlflow server --backend-store-uri sqlite:///mlflow.db --port 5000

This example uses SQLite as the backend store. To use other types of SQL databases such as PostgreSQL, MySQL, and MSSQL, change the store URI as described in the backend store documentation. OpenTelemetry ingestion is not supported with file-based backend stores.

Step 3: Configure OpenTelemetry

Configure the OpenTelemetry tracer in your Mastra agent to export traces to the MLflow Tracking Server endpoint.

Open the src/mastra/index.ts file and add the observability configuration to the Mastra agent instantiation.

typescript
export const mastra = new Mastra({
workflows: { weatherWorkflow },
...

// Add the following observability configuration to enable OpenTelemetry tracing.
observability: {
configs: {
otel: {
serviceName: "maestra-app",
exporters: [new OtelExporter({
provider: {
custom: {
// Specify tracking server URI with the `/v1/traces` path.
endpoint: "http://localhost:5000/v1/traces",
// Set the MLflow experiment ID in the header.
headers: { "x-mlflow-experiment-id": "<your-experiment-id>"},
// MLflow support HTTP/Protobuf protocol.
protocol: "http/protobuf"
}
}
})]
}
}
},
});

Step 4: Run the Agent

Start the Mastra agent with the npm run dev command. The playground URL will be displayed in the console.

Mastra Playground

After chatting with the agent, open the MLflow UI at http://localhost:5000 and navigate to the experiment to see the traces like the screenshot at the top of this page.

Next Steps