Skip to content

fix(node): Bootstrap Mastra observability under ESM - #24177

Open
mydea wants to merge 2 commits into
developfrom
fix/mastra-deps-node-engine
Open

fix(node): Bootstrap Mastra observability under ESM#24177
mydea wants to merge 2 commits into
developfrom
fix/mastra-deps-node-engine

Conversation

@mydea

@mydea mydea commented Sep 7, 2026

Copy link
Copy Markdown
Member

The Mastra integration failed to auto-bootstrap @mastra/observability under ESM when the app configured no observability of its own. loadMastraObservability() anchored module resolution on process.cwd() and the CJS require.cache, but an ESM-loaded @mastra/core never lands in that cache, leaving cwd as the only anchor. When the app's dependencies don't live under cwd — a serverless/monorepo layout, or concretely the per-suite temp install the integration tests use — resolution failed silently: no exporter was attached and no gen_ai spans were produced, so the ESM scenario-auto test timed out.

The runtime injection hook already receives the resolved file: URL of every module it instruments and was throwing it away. We now record it on __SENTRY_ORCHESTRION__.runtimeFiles and let the Mastra integration anchor @mastra/observability resolution on the app's actual @mastra/core file. This works under both ESM and CJS and no longer depends on cwd; the CJS-cache and cwd lookups remain as fallbacks.

Decisions:

  • Anchor on @mastra/core, not @mastra/observability. The latter is never loaded in the failing case — that is precisely why the SDK has to bootstrap it — so there is nothing to hook there. @mastra/core is always loaded when the integration runs.
  • Fix it in SDK code rather than by changing the scenario child's cwd in the test runner. The cwd approach would have papered over a real production gap (ESM apps whose cwd is not the app directory, e.g. serverless) that the code's own comments already acknowledged.

This also moves @mastra/core and @mastra/observability out of the node-integration-tests workspace devDependencies into the runner's per-suite additionalDependencies. @mastra/core declares engines.node >= 22.13, so a workspace devDependency broke yarn install on the Node 20.19 CI matrix even though the suite is gated behind conditionalTest({ min: 22 }). Installing them into the test's temp dir at run time means Node 20 never resolves them, while Node 22+ runs get them exactly as before.

Root cause: cwd/require.cache-based resolution has no valid anchor for an optional peer dependency of an ESM-loaded module when the app's node_modules is not under process.cwd().

🤖 Generated with Claude Code

@mydea mydea changed the title fix(node-integration-tests): Don't install @mastra/core as a workspace dependency chore(node-integration-tests): Don't install @mastra/core as a workspace dependency Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 28.8 kB - -
@sentry/browser - with treeshaking flags 27.11 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27 kB - -
@sentry/browser (incl. Tracing) 49.22 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 49.22 kB - -
@sentry/browser (incl. Tracing, Profiling) 52.12 kB - -
@sentry/browser (incl. Tracing, Replay) 88.76 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.95 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 93.44 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 106.37 kB - -
@sentry/browser (incl. Feedback) 46.3 kB - -
@sentry/browser (incl. sendFeedback) 33.86 kB - -
@sentry/browser (incl. FeedbackAsync) 38.97 kB - -
@sentry/browser (incl. Metrics) 29.82 kB - -
@sentry/browser (incl. Logs) 30.09 kB - -
@sentry/browser (incl. Metrics & Logs) 30.75 kB - -
@sentry/react 30.55 kB - -
@sentry/react (incl. Tracing) 51.56 kB - -
@sentry/vue 36.05 kB - -
@sentry/vue (incl. Tracing) 51.48 kB - -
@sentry/svelte 28.83 kB - -
CDN Bundle 30.55 kB - -
CDN Bundle (incl. Tracing) 49.74 kB - -
CDN Bundle (incl. Logs, Metrics) 32.82 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 51.7 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.48 kB - -
CDN Bundle (incl. Tracing, Replay) 87.29 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 89.18 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 93.22 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 95.21 kB - -
CDN Bundle - uncompressed 90.46 kB - -
CDN Bundle (incl. Tracing) - uncompressed 148.17 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.03 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 154.14 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 226.29 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 267.76 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 273.71 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 281.46 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 287.4 kB - -
@sentry/nextjs (client) 54.03 kB - -
@sentry/sveltekit (client) 49.65 kB - -
@sentry/core/server 36.99 kB - -
@sentry/core/browser 13.55 kB - -
@sentry/node 127.73 kB +0.1% +122 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.61 kB +0.04% +32 B 🔺
@sentry/node - without tracing 88.73 kB +0.05% +44 B 🔺
@sentry/node - without channel injection 106.98 kB +0.09% +93 B 🔺
@sentry/aws-serverless 97.12 kB +0.06% +53 B 🔺
@sentry/cloudflare (withSentry) - minified 201.95 kB - -
@sentry/cloudflare (withSentry) 502.67 kB - -

View base workflow run

mydea and others added 2 commits September 7, 2026 16:32
…e dependency

`@mastra/core` declares `engines.node >= 22.13`, so having it in the
node-integration-tests `devDependencies` broke `yarn install` on the
Node 20.19 CI matrix with "The engine \"node\" is incompatible with this module".

Move `@mastra/core` and `@mastra/observability` into per-suite
`additionalDependencies` on the Mastra runner instead. Those are only
installed when the suite runs, and the suite is already gated behind
`conditionalTest({ min: 22 })`, so Node 20 never touches them.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mydea
mydea force-pushed the fix/mastra-deps-node-engine branch from a9e0103 to d28f3f3 Compare September 7, 2026 14:33
@mydea mydea changed the title chore(node-integration-tests): Don't install @mastra/core as a workspace dependency fix(node): Bootstrap Mastra observability under ESM Sep 7, 2026
@mydea
mydea requested review from RulaKhaled and timfish September 7, 2026 14:35
@mydea
mydea marked this pull request as ready for review September 7, 2026 14:45
@mydea
mydea requested review from a team as code owners September 7, 2026 14:45
@mydea
mydea requested review from andreiborza and isaacs and removed request for a team September 7, 2026 14:45

@RulaKhaled RulaKhaled left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! thank you for fixing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants