Skip to content

@sentry/nextjs automatic ai instrumentation breaks ai/rsc #16725

Closed

Description

@billyjanitsch

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/nextjs

SDK Version

9.31.0

Framework Version

Next.js 15.3.3

Link to Sentry event

No response

Reproduction Example/SDK Setup

See https://github.com/billyjanitsch/sentry-nextjs-ai-bug for a minimal reproduction.

Steps to Reproduce

See repro readme.

Expected Result

In a server actions file, I expect to be able to import and use server exports from ai/rsc:

"use server";

import { createStreamableValue } from "ai/rsc";

assert(typeof createStreamableValue === 'function')

This works fine in vanilla Next.js.

Actual Result

When Sentry's Next.js config is enabled, the above code breaks. ai/rsc resolves to the client implementation instead of the server one, where createStreamableValue is undefined.

This happens from 9.30.0 onwards, presumably because this version enabled automatic instrumentation of the ai library.

cc @AbhiPrasad @mydea

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jun 24, 2025
  2. self-assigned this
    on Jun 25, 2025
  3. RulaKhaled commented on Jun 25, 2025

    @RulaKhaled
    Collaborator

    Thank you for reaching out and reporting this issue!

    The problem stems from a recent change we made where we added the ai package to our list of externalized packages for instrumentation purposes. Unfortunately this causes Next.js to incorrectly evaluate the Vercel AI SDK's conditional exports, specifically the react-server export condition isn't properly handled when the package is externalized, resulting in client-side code being loaded in server components instead of the server-side functions.

    I've identified a potential fix and will be working on it, we'll ping you with updates.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jun 25, 2025
  5. alvarlagerlof commented on Jun 25, 2025

    @alvarlagerlof

    @RulaKhaled Do you think that your potential fix would fix this too?

  6. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jun 25, 2025
  7. RulaKhaled commented on Jun 26, 2025

    @RulaKhaled
    Collaborator

    @alvarlagerlof I'm not sure. We will look at the other issue and evaluate it.

    @billyjanitsch Regarding this, I merged the fix removing the package from the list of externalized packages. With the upcoming release could you please test this and see if it works?

  8. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jun 26, 2025
  9. mydea commented on Jun 27, 2025

    @mydea
    Member

    We have released 9.33.0 which removes ai from externals again, which should fix the problem. Please reopen the issue if you still run into any issues!

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

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions