Conversation

mydea

This PR improves the handling of the ai instrumentation to always be enabled when we detect the ai module is installed.

For this, we leverage the modulesIntegration. This PR should make usage of ai instrumentation in Next.js "automatically" again - BUT users will have to specific experimental_telemetry: { isEnabled: true }, at each call manually for the time being.

@mydeamydea requested a review from AbhiPrasad June 12, 2025 12:01
@mydeamydea self-assigned this Jun 12, 2025
@github-actionsGitHub Actions

size-limit report 📦

PathSize% ChangeChange
@sentry/browser23.99 kB--
@sentry/browser - with treeshaking flags23.76 kB--
@sentry/browser (incl. Tracing)38.69 kB--
@sentry/browser (incl. Tracing, Replay)76.78 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags69.87 kB-0.01%-1 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas)81.54 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)93.6 kB--
@sentry/browser (incl. Feedback)40.73 kB--
@sentry/browser (incl. sendFeedback)28.7 kB--
@sentry/browser (incl. FeedbackAsync)33.59 kB--
@sentry/react25.76 kB--
@sentry/react (incl. Tracing)40.67 kB--
@sentry/vue28.36 kB--
@sentry/vue (incl. Tracing)40.55 kB-0.01%-1 B 🔽
@sentry/svelte24.01 kB--
CDN Bundle25.48 kB--
CDN Bundle (incl. Tracing)38.77 kB--
CDN Bundle (incl. Tracing, Replay)74.64 kB-0.01%-1 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback)80.1 kB--
CDN Bundle - uncompressed74.48 kB--
CDN Bundle (incl. Tracing) - uncompressed114.89 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed228.86 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed241.69 kB--
@sentry/nextjs (client)42.33 kB--
@sentry/sveltekit (client)39.17 kB--
@sentry/node150.56 kB+0.04%+53 B 🔺
@sentry/node - without tracing98.4 kB+0.03%+22 B 🔺
@sentry/aws-serverless124.15 kB+0.02%+13 B 🔺

View base workflow run

mydea added a commit that referenced this pull request Jun 13, 2025
…16566)

Extracted out from
#16565

I noticed that our `modulesIntegration` is pretty limited:

1. It does nothing on EMS
2. It does not work on Next.js (even though that is CJS)

This PR makes this a bit more robust (not perfect):

1. It generally now also tries to look at `process.cwd() +
'package.json'` and take the dependencies and devDependencies from
there. this should generally work in esm apps now as well, at least at a
basic level. You do not get all dependencies and versions may be ranges,
but better than nothing.
2. For Next.js, we inject a modules list based off the package.json at
build time, as we do not have proper access to this at runtime.
@mydeamydea force-pushed the fn/better-ai-check branch from 8468a42 to c95356d Compare June 13, 2025 06:37
@mydeamydea marked this pull request as ready for review June 13, 2025 06:38
@mydeamydea merged commit d35030d into develop Jun 13, 2025
145 checks passed
@mydeamydea deleted the fn/better-ai-check branch June 13, 2025 14:21
@alvarlagerlof

Would you consider adding a way to disable this? We have some legacy ai sdk code and we hit a build error. I don't have time to create a repro at this time.

@matsmart/web-app:build: [Error: Failed to collect configuration for /[market]/[lang]/[isApp]/[cartStatus]/chat] {
@matsmart/web-app:build:   [cause]: TypeError: (0 , s.createAI) is not a function
@matsmart/web-app:build:       at <unknown> (.next/server/app/[market]/[lang]/[isApp]/[cartStatus]/(all)/chat/page.js:22:1447)
@matsmart/web-app:build: }

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

Successfully merging this pull request may close these issues.