I figured out that when run from the CLI, I need to load the OpenTelemetry instrumentation before importing Mastra as follows:
// CRITICAL: Load OpenTelemetry instrumentation for AI tracing // This must be loaded before any Mastra imports const instrumentationPath = path.resolve(process.cwd(), '.mastra', 'output', 'instrumentation.mjs'); try { if (fsSync.existsSync(instrumentationPath)) { await import(instrumentationPath); console.log(' AI tracing instrumentation loaded'); } } catch (error: any) { console.warn(' AI tracing instrumentation not available:', error?.message || error); }
—————————————————-
PROBLEM:
I am not able to see AI Tracing from my local workflows and agents when running Mastra from the CLI.
My CLI command starts Mastra Studio, waits for the studio to complete initialization, then executes the workflow. Storage is configured via SQLite at the default location shown in the docs so that both the studio and my agents use .mastra/output/mastra.db.
My agents are created with a custom factory and registered with Mastra. I am not currently using Mastra.getAgent() to create my agents.
The Mastra Studio is accessible at the default 4111 port and properly displays my workflow and agents. My workflow runs successfully to completion over the course of about 10 minutes but studio shows no AI Tracing.