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

@sentry/nextjs and nextjs custom server #3782

Closed
marexandre opened this issue Jul 7, 2021 · 9 comments
Closed

@sentry/nextjs and nextjs custom server #3782

marexandre opened this issue Jul 7, 2021 · 9 comments
Labels
hacktoberfest Meta: Help Wanted Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@marexandre
Copy link

Hi,

Are there any documentation on how to setup @sentry/nextjs with https://nextjs.org/docs/advanced-features/custom-server ?

Thanks!

@lobsterkatie
Copy link
Member

That's not a use case we've investigated yet, so no, there aren't currently any docs. For API routes, nothing should be different - withSentry should work out of the box. Non-API routes, on the other hand, I would expect not to be traced or have their errors caught, as the code we have for that relies on monkeypatching the built-in server.

Before I give any advice on how to implement that yourself, though, I'm actually planning this sprint or next to re-evaluate the way that we do that, as there appear to be environments where it only works inconsistently. So for the moment, I'd suggest starting with your API routes (and your frontend). Once I get a better handle on whether we might take a different approach to non-API routes, I'll better be able to advise you on that score.

@github-actions
Copy link
Contributor

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@vladanpaunovic
Copy link
Contributor

Instead of adopting our SDK, I suggest we treat this a combination of @sentry/node + @sentry/react or @sentry/nextjs. It could be sufficient to update our docs to describe this use case.

This will probably give up on some (small) functionality using a custom server which should be fine as a custom server itself reduces the functionality of nextjs.

@rbabayoff
Copy link

Hey @vladanpaunovic so if I only need this for api routes, will the @sentry/next package work out of the box?

@vladanpaunovic
Copy link
Contributor

@rbabayoff I will assume that by "this" you meant a custom server.

If so, then @sentry/nextjs on client + @sentry/node on your server should do the job.

@sentry/nextjs will cover the frontend and most of the features from Next.js. If that proves to be buggy for your custom use case, I suggest you fall back to @sentry/react for a more controlled but also more manual instrumentation.

@sentry/node will instrument your custom node server

@rbabayoff
Copy link

rbabayoff commented Jul 10, 2022

Hey @vladanpaunovic , thanks for your answer. My use case is a bit more complicated - in the same app, one of my endpoints is a long running api endpoint for file uploads, which I need to run on a custom server. Everything else should work on vercel.

A couple of questions:

  1. How do I force the upload of source maps when I run next build when using only @sentry/nextjs? It doesn't seem to happen.

  2. I want to keep @sentry/nextjs for the vercel deployment, but when running next build when deploying the custom server, I'd like to be able to replace all @sentry/nextjs on the server side with @sentry/node and still force source map uploads.

Will this work with a custom webpack config in the next.config.js that sentry generated with npx @sentry/wizard -i nextjs (EF_IS_UPLOAD_SERVER is our env var for custom server builds):

const moduleExports = {
	webpack: (config, options) => {
		// Next.js will call this webpack function twice, once for the
		// server and once for the client. Read more:
		// https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config
		if (process.env.EF_IS_UPLOAD_SERVER && options.isServer) {
			config.resolve.alias["@sentry/nextjs"] = "@sentry/node";
		}

		return config;
	},
};

Thanks in advance

@rbabayoff
Copy link

Hey @vladanpaunovic , simplifying my question - how can I force the generation and upload of source maps to sentry while still using @sentry/nextjs and next build, taking into account that I'll use the custom server only for api endpoints?

@vladanpaunovic
Copy link
Contributor

I think what you can do is play a bit with sentry-webpack-plugin configuration. We have a docs on source maps here https://docs.sentry.io/platforms/javascript/sourcemaps/generating/ but you can always check the repo https://github.com/getsentry/sentry-webpack-plugin

@github-actions
Copy link
Contributor

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Meta: Help Wanted Package: nextjs Issues related to the Sentry Nextjs SDK
Projects
None yet
Development

No branches or pull requests

6 participants