From f7d6371ab51a94101105209fe527d56279cf5471 Mon Sep 17 00:00:00 2001 From: Christian Stroet Date: Tue, 6 Oct 2026 16:17:01 +0200 Subject: [PATCH] fix(mastra): turn Mastra's PostHog telemetry off by default @mastra/core sends usage events to us.posthog.com from every Mastra instance unless MASTRA_TELEMETRY_DISABLED is set, and the mastra CLI does the same for Studio. Nothing in the scaffold set it, so every deployed app reported to a US processor that no project declares. Keur flagged this on a client app as SCH-LEG-003 (PostHog reachable via posthog-node, undeclared). The runtime default lives in server/mastra/index.ts, before new Mastra(), so it covers Nitro, Studio and the production image alike; the Studio task passes the same default to the CLI. Both use ??=, so a project can still opt in with MASTRA_TELEMETRY_DISABLED=false. --- packages/preset-nuxt4/src/features/mastra.ts | 4 +++- .../preset-nuxt4/templates/mastra/server/mastra/index.ts | 3 +++ packages/preset-nuxt4/test/ai-gateway-templates.test.ts | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/preset-nuxt4/src/features/mastra.ts b/packages/preset-nuxt4/src/features/mastra.ts index c7b4882b..b8a03205 100644 --- a/packages/preset-nuxt4/src/features/mastra.ts +++ b/packages/preset-nuxt4/src/features/mastra.ts @@ -29,7 +29,7 @@ import { /** Mastra AI runtime. Talks to an OpenAI-compatible AI gateway (sluis.ai preset, or any compatible URL) via `@ai-sdk/openai-compatible`. */ export const mastraFeature: Feature = { id: 'nuxt4:mastra', - version: '2.1.1', + version: '2.1.2', label: 'Mastra AI runtime', frameworks: ['nuxt4'], stage: STAGE.AI_CORE, @@ -305,6 +305,8 @@ export const mastraFeature: Feature = { const env: Record = {} for (const [k, v] of await readDotEnv(ctx.projectDir)) env[k] = v env.PORT = String(port) + // The CLI reports its own analytics to PostHog; same opt-out as the runtime in server/mastra/index.ts. + env.MASTRA_TELEMETRY_DISABLED ??= 'true' // `mastra dev` reads PORT from env, defaulting to 4111. await run(pm, ['exec', 'mastra', 'dev', '--dir', 'server/mastra'], { cwd: ctx.projectDir, diff --git a/packages/preset-nuxt4/templates/mastra/server/mastra/index.ts b/packages/preset-nuxt4/templates/mastra/server/mastra/index.ts index f58cf664..2210dff1 100644 --- a/packages/preset-nuxt4/templates/mastra/server/mastra/index.ts +++ b/packages/preset-nuxt4/templates/mastra/server/mastra/index.ts @@ -14,6 +14,9 @@ if (!databaseUrl) { throw new Error('NUXT_DATABASE_URL is not set in `.env`.') } +// Mastra sends usage telemetry to PostHog (US) unless told not to; opt back in with `MASTRA_TELEMETRY_DISABLED=false`. +process.env.MASTRA_TELEMETRY_DISABLED ??= 'true' + const storage = new PostgresStore({ id: 'mastra-storage', connectionString: databaseUrl, diff --git a/packages/preset-nuxt4/test/ai-gateway-templates.test.ts b/packages/preset-nuxt4/test/ai-gateway-templates.test.ts index acaee866..8b33d14e 100644 --- a/packages/preset-nuxt4/test/ai-gateway-templates.test.ts +++ b/packages/preset-nuxt4/test/ai-gateway-templates.test.ts @@ -134,3 +134,12 @@ describe('no legacy gateway wiring remains anywhere in templates', () => { expect(src).not.toMatch(LEGACY) }) }) + +describe('Mastra telemetry', () => { + it('is off by default before the Mastra instance is created', async () => { + const src = await read('mastra', 'server', 'mastra', 'index.ts') + const optOut = src.indexOf("process.env.MASTRA_TELEMETRY_DISABLED ??= 'true'") + expect(optOut).toBeGreaterThan(-1) + expect(optOut).toBeLessThan(src.indexOf('new Mastra(')) + }) +})