Skip to content

feat: NextJS initialization config #3285

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

Merged
merged 27 commits into from
Mar 1, 2021

Conversation

iker-barriocanal
Copy link
Contributor

@iker-barriocanal iker-barriocanal commented Feb 26, 2021

This PR focuses on the initialization of the NextJS SDK.

Main changes

  1. Added entry points in package.json for browser and node environments.
  2. options.ts has been refactored. The NextjsOptions interface and MetadataBuilder are now in separate files in /utils, instead of being in the same one.
  3. The SDK is not always initialized. utils/initDecider is responsible for this, and by default only initializes the SDK when it's run in production; although the initialization in non-production environments can be forced by setting dev: true (see example below).

Why is the SDK by default only initialized in production?

The code that is being run in development mode is not the same as the one in production mode. NextJS requires building the app before running it in production mode (docs), which besides performing some optimizations, does some checks (e.g. compilation errors). Some of these errors, which won't ever be run in production due to the building phase, can actually be run in development; they break the app and Sentry doesn't deal with them (at the moment). Thus, the SDK is only initialized by default in production environments.

However, some users might be interested in running Sentry in development. The SDK initialization can be forced by setting dev to true (false by default) in init, as follows:

import * as Sentry from '@sentry/nextjs';

Sentry.init({
  dsn: '__DSN__',
  dev: true,
  // ...
});

This will initialize the SDK in non-production modes. Note, however, that this doesn't change the actual behavior; so there might be cases where what described above happens. If this is the case: try to build the app, fix the errors, and once it's built, run it again.

@iker-barriocanal iker-barriocanal requested a review from a team February 26, 2021 15:58
Copy link
Member

@HazAT HazAT left a comment

Choose a reason for hiding this comment

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

I think this PR contains the changes of the branch or it was not based of the feat/next-js branch. Something is odd with the diff.

@iker-barriocanal iker-barriocanal requested a review from HazAT March 1, 2021 15:35
@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2021

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 20.27 KB (+0.02% 🔺)
@sentry/browser - Webpack 21.18 KB (0%)
@sentry/react - Webpack 21.2 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 27.37 KB (+0.02% 🔺)

This file was supposes to be deleted in a prior refactor, but it was messed up in a merge.
@iker-barriocanal iker-barriocanal merged commit 7f70aff into feat/next-js Mar 1, 2021
@iker-barriocanal iker-barriocanal deleted the feat/next-js-config-init branch March 1, 2021 16:10
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.

2 participants