Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues running @vercel/og when @sentry/nextjs is installed #5964

Closed
3 tasks done
jcblw opened this issue Oct 14, 2022 · 9 comments · Fixed by #6207
Closed
3 tasks done

Issues running @vercel/og when @sentry/nextjs is installed #5964

jcblw opened this issue Oct 14, 2022 · 9 comments · Fixed by #6207
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug

Comments

@jcblw
Copy link

jcblw commented Oct 14, 2022

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

7.15.0

Framework Version

7.15.0

Link to Sentry event

No response

Steps to Reproduce

  1. Installed @vercel/og
  2. Run the local server yarn dev
  3. Error happens with auto instrumentation. It does not like the exported config needed
  4. Turn off auto instrumentation.
  5. See image work locally, deploy to Vercel
  6. Attempt to view the image on preview ( 500 crash of edge function ).

Expected Result

I should be able to use @sentry/nextjs and @vercel/og in the same project. The only way I could get images generated on Vercel was to remove the integration altogether.

Actual Result

I run into initial issues with auto instrumentation due to the config exports. If I remove the export, it no longer throws a Sentry issue but another error due to missing dependencies on the edge function. Here is that original error.

Screen Shot 2022-10-14 at 9 22 54 AM

The error on Vercel after turning off auto instrumentation. /api/sponsor is the route of the image. I think Sentry assumes this is a client view since it's using browser tracing and attempting to access document.getElementById. Also, this file extension is a TSX file

Screen Shot 2022-10-14 at 8 59 38 AM

Thanks, and let me know if I am just misconfiguring this!

@lforst
Copy link
Member

lforst commented Oct 17, 2022

Are you using Vercel's edge runtime? If yes, the Sentry SDK doesn't currently support it. Can you try the same thing using ordinary Node.js as a runtime? Thanks!

@lforst lforst added Status: Needs Reproduction Package: nextjs Issues related to the Sentry Nextjs SDK and removed Status: Untriaged labels Oct 17, 2022
@jcblw
Copy link
Author

jcblw commented Oct 20, 2022

@lforst the package mentioned above only works on the edge runtime. I initially hoped to turn it off for just one route, but it seems like the only way I could get any of this to work was by completely uninstalling the package. I'll get a test repo up for you.

@jcblw
Copy link
Author

jcblw commented Oct 20, 2022

I have been having issues replicating this with a new repo.

https:/jcblw/sentry-vercel-og-issue

It seems like, for some reason, on my private repo, Sentry thinks the Image responses are React components, so the client performance library runs.

Going to close for now until I can get that repo to throw the error.

@jcblw jcblw closed this as completed Oct 20, 2022
@nathanhammond
Copy link

nathanhammond commented Oct 31, 2022

Reproduction: https:/nathanhammond/turbo/tree/open-graph-image

Create a Vercel project for the /docs directory and it will throw this error:

TypeError: uh.withSentryAPI is not a function
    at pages/api/og.tsx:41:51
    at webpack/bootstrap:21:0
    at .:6:18
    at webpack/bootstrap:21:0
    at ../node_modules/.pnpm/[email protected]/node_modules/react/jsx-runtime.js:4:2
    at ../node_modules/.pnpm/[email protected]/node_modules/react/jsx-runtime.js:4:2
    at webpack/runtime/jsonp chunk loading:34:0
    at api/og:middleware.js:1:17

It appears to be inserting instrumentation for fetch (at build time?) in a way that the Vercel edge runtime does not support, and Sentry itself isn't being included in the built assets. (This is calculated by https:/vercel/nft)

Further notes: autoInstrumentServerFunctions is true.

@nathanhammond
Copy link

nathanhammond commented Oct 31, 2022

ignore doesn't work as an option, as specified here:

// TODO: merge default SentryWebpackPlugin ignore with their SentryWebpackPlugin ignore or ignoreFile

This means I can't work around it with any other method except by toggling autoInstrumentServerFunctions:

if (userSentryOptions.autoInstrumentServerFunctions !== false) {

@jcblw
Copy link
Author

jcblw commented Nov 1, 2022

Going to reopen with @nathanhammond comments.

@jcblw jcblw reopened this Nov 1, 2022
@MAfzalKhan1997
Copy link

any update on this ? I'm facing this issue
image

@lforst
Copy link
Member

lforst commented Nov 14, 2022

any update on this ?

We're working on an option to turn off auto-instrumentation for individual API routes. Support for the Edge runtime currently isn't planned any time soon. For now, to get this working, you can set autoInstrumentServerFunctions: false in your Next.js config and manually instrument all other routes with withSentry().

lobsterkatie added a commit that referenced this issue Nov 15, 2022
Currently, in the nextjs SDK, we inject the user's `Sentry.init()` code (by way of their `sentry.server.config.js` file) into all serverside routes. This adds a new option to the `sentry` object in `next.config.js` which allows users to prevent specific routes from being instrumented in this way. In this option, excluded routes can be specified using either strings (which need to exactly match the route) or regexes.

Note: Heavily inspired by #6125. h/t to @lforst for his work there. Compared to that PR, this one allows non-API routes to be excluded and allows excluded pages to be specified as routes rather than filepaths. (Using routes a) obviates the need for users to add `pages/` to the beginning of every entry, b) abstracts away the differences between windows and POSIX paths, and c) futureproofs users' config values against underlying changes to project file organization.)

Docs for this feature are being added in getsentry/sentry-docs#5789.

Fixes #6119.
Fixes #5964.
@lobsterkatie
Copy link
Member

This should be released as part of 7.20 later this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants