Skip to content

Next.js docs for v8.0.0 #12044

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

Closed
3 tasks done
dorin-flooz opened this issue May 15, 2024 · 18 comments · Fixed by getsentry/sentry-docs#10040
Closed
3 tasks done

Next.js docs for v8.0.0 #12044

dorin-flooz opened this issue May 15, 2024 · 18 comments · Fixed by getsentry/sentry-docs#10040
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@dorin-flooz
Copy link

dorin-flooz commented May 15, 2024

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

8.0.0

Framework Version

React latest

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

After upgrading to @sentry/nextjs 8.0.0, we get the following message in our yarn next build log:

Creating an optimized production build ...
[@sentry/nextjs] It appears you've configured a `sentry.server.config.ts` file. Please ensure to put this file's content into the `register()` function of a Next.js instrumentation hook instead. To ensure correct functionality of the SDK, `Sentry.init` must be called inside `instrumentation.ts`. Learn more about setting up an instrumentation hook in Next.js: https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation. You can safely delete the `sentry.server.config.ts` file afterward.
[@sentry/nextjs] It appears you've configured a `sentry.edge.config.ts` file. Please ensure to put this file's content into the `register()` function of a Next.js instrumentation hook instead. To ensure correct functionality of the SDK, `Sentry.init` must be called inside `instrumentation.ts`. Learn more about setting up an instrumentation hook in Next.js: https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation. You can safely delete the `sentry.edge.config.ts` file afterward.
[@sentry/nextjs - Node.js] Info: Sending error and performance telemetry data to Sentry. To disable telemetry, set `options.telemetry` to `false`.

We tried following the documentation at https://docs.sentry.io/platforms/javascript/guides/nextjs to fix these issues, but it seems to be out of sync:

Expected Result

  • up to date docs following the release
  • version selector in the docs - without this it's impossible for users to follow version-specific documentation or to even determine if documentation is available for a specific version

Actual Result

...

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 May 15, 2024
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label May 15, 2024
@mydea mydea changed the title Documentation for v8.0.0 Next.js docs for v8.0.0 May 15, 2024
@HazAT
Copy link
Member

HazAT commented May 15, 2024

Hey, sorry about that - we are jumping on this as we speak.

in the meantime, to unblock you, can you create a file instrumentation.ts and do this:

export async function register() {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    await import('./sentry.server.config');
  }

  if (process.env.NEXT_RUNTIME === 'edge') {
    await import('./sentry.edge.config');
  }
}

as outlined here
https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#create-initialization-config-files

@s1gr1d
Copy link
Member

s1gr1d commented May 15, 2024

@dorin-flooz Thanks for pointing this out! I updated the docs so they are in line with v8.

I guess the warning won't go away if you import the files like in the snippet @HazAT suggested. You have to delete the server.config and edge.config files. The contents of the files need to be added to the register() function like this:

export async function register() {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    Sentry.init({
      dsn: env.DSN
      tracesSampleRate: 1.0,
    });
  }

  if (process.env.NEXT_RUNTIME === 'edge') {
    Sentry.init({
      dsn: env.DSN
      tracesSampleRate: 1.0,
    });
  }
}

@dorin-flooz
Copy link
Author

hey @HazAT / @s1gr1d, thanks for the quick reply! What about versioned docs - any plans to have that implemented?
We have postponed the upgrade to 8.0.0 due to the issues above, but if I understand correctly you have now overwritten https://docs.sentry.io/platforms/javascript/guides/nextjs to match the v8.0.0 API - in this case how would we access the v7.00-specific documentation until we upgrade?

@HazAT
Copy link
Member

HazAT commented May 16, 2024

@dorin-flooz we discussed this internally and probably going to work on them
but since this is a bit of a larger project it will take a while but keep an eye out.
Thanks for the feedback!

@kbsali
Copy link

kbsali commented Jun 10, 2024

the doc concerning "telemetry" is still missing, no?
How to tackle To disable telemetry, set options.telemetrytofalse. ?

Thanks for the hints

@s1gr1d
Copy link
Member

s1gr1d commented Jun 11, 2024

@kbsali
Copy link

kbsali commented Jun 11, 2024

@s1gr1d this is specific to Astro/vite apparently, we are running a nextjs project

@s1gr1d
Copy link
Member

s1gr1d commented Jun 11, 2024

@kbsali I am not 100% sure if we are talking about the same thing. You are right, it is currently not directly documented when the Next.js docs talk about extending the configuration. However, Astro and Next.js both use the vite-plugin and provide the same build options (you can find them here for vite and here for webpack). Is this what you were searching for? We can elaborate on this in the docs.

@kbsali
Copy link

kbsali commented Jun 11, 2024

as far as I can tell

  • @sentry/nextjs uses @sentry/webpack-plugin
  • @sentry/astro uses @sentry/vite-plugin

I see options for webpack-plugin but i'm not sure how to apply it in the context of @sentry/nextjs

@s1gr1d
Copy link
Member

s1gr1d commented Jun 12, 2024

Oh yes, Next.js is using webpack, but the options are the same. The options specifically for the webpack plugin are defined here. And the docs show you how to configure your build options (the link I posted in my previous comment).

I think, what you want to achieve is this in your next.config.ts:

export default withSentryConfig(nextConfig, {
  // your other options...
  telemetry: false
});

Is this helping you? If yes, we will add this to the docs.

cumet04 added a commit to cumet04/switchbot-logger that referenced this issue Jun 16, 2024
関連してそう getsentry/sentry-javascript#12044
あとedgeは必要無いので削除。ビルドwarnが出なければそのままでヨシ
@briantweed
Copy link

Adding the following to next.config.js solved my issue. Don't see this mentioned on the installation page but it is on the migrate from 7 to 8 docs

experimental: {
instrumentationHook: true
}

@s1gr1d
Copy link
Member

s1gr1d commented Aug 26, 2024

Thanks @briantweed, this will be added to the "Manual Setup" docs as well: getsentry/sentry-docs#11140

@OmBharti999
Copy link

I pasted this part in my next.config.js file

/** @type {import('next').NextConfig} */
const { withSentryConfig } = require("@sentry/nextjs");
const nextConfig = {
//your additional configs
}

const sentryWebpackPluginOptions = {
  org: "grippi-frontend",
  project: "javascript-nextjs",
  telemetry: false,
};

const sentryOptions = {
  // Upload additional client files (increases upload size)
  widenClientFileUpload: true,

  // Hides source maps from generated client bundles
  hideSourceMaps: true,
};

module.exports = withSentryConfig(
  nextConfig,
  sentryWebpackPluginOptions,
  sentryOptions
);

guesung added a commit to guesung/Web-Memo that referenced this issue Jan 27, 2025
guesung added a commit to guesung/Web-Memo that referenced this issue Jan 29, 2025
* chore: onSuccess 제거

* refactor: 불필요한 h-full 제거

* chore: onSuccess 제거

* fix: sentry 설정을 instrumentation에서 수행

ref : getsentry/sentry-javascript#12044

* feat: GTM 추가

ref : https://nextjs.org/docs/app/building-your-application/optimizing/third-party-libraries

* refactor: 불필요한 속성 및 컴포넌트 제거

* docs: 주석으로 코드에 대한 설명 추가

* refactor: InitSentryUserInfo 컴포넌트 이동

* feat: eslint-plugin-unused-imports 설치 및 세팅

* refactor: 네이밍 앞에 -Memo-` prefix로 통일

* refactor: Header를 주로 사용하는 측인 layout/[lng]에 위치

* refactor: 불필요한 파일 제거

* refactor: 불필요한 함수 래퍼 제거 및 변수명 수정

* refactor: handleRequestAppend 함수 분리

* refactor: `groupKey` 기본값 설정

* refactor: 불필요한 단언문(!) 제거

* chore: sentry의 silent옵션 제거

* refactor: `ExtensionDialog` 이동

* fix: 확장 프로그램이 설치된 경우에만 가이드 실행

* refactor: ExtensionInstallCheckDialog 분리

* feat: ExtensionInstallCheckDialog 동적 import

* refactor: 기명 함수로 수정

* chore: placeholder 시간 최소화

* refactor: 변수명, 함수명을 직관적으로 수정

* refactor: queries와 mutations 분리

* feat: 공통 훅을 shared폴더로 묶기

* refactor: 순서 변경

* refactor: 불필요한 훅 제거

* refactor: `useKeyboardBind`를 isMetaKey도 받을 수 있도록 확장

* fix: 메타키 이슈 해결

* chore: type import

* refactor: 사용하지 않는 타입 제거

* refactor: 컨벤션에 맞는 폴더로 이동

* refactor: 폴더 구조 컨벤션에 맞게 수정

* refactor: 불필요한 컴포넌트 depth 제거

* refactor: Header를 공통 컴포넌트로 이동

* refactor: container에서 section 네이밍으로 통일

* refactor: 컴포넌트 파일을 재 역할에 맞는 폴더로 이동

* refactor: server.ts와 client.ts에 `util`을 앞에 붙여주기

* refactor: 불필요한 import 및 컴포넌트 제거

* chore: type imports eslint rules 추가

* style: type import eslint 적용

* chore: web의 eslintl 제거

* fix: eslint-import-resolver-typescript로 eslint typescript resolve

ref : import-js/eslint-plugin-import#2969 (comment)

* fix: fix the lint

* fix: 잘못된 import경로 수정
@devuxer
Copy link

devuxer commented May 4, 2025

Hey, sorry about that - we are jumping on this as we speak.

in the meantime, to unblock you, can you create a file instrumentation.ts and do this:

export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('./sentry.server.config');
}

if (process.env.NEXT_RUNTIME === 'edge') {
await import('./sentry.edge.config');
}
}
as outlined here https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#create-initialization-config-files

@HazAT, What you are saying here matches the docs, but it appears these sentry.*.config files are not compatible with NextJS 15, at least with Turbopack.

@s1gr1d
Copy link
Member

s1gr1d commented May 5, 2025

Hello, please check this issue regarding Turbopack support: #8105

You can add your Sentry server configuration in instrumentation.ts and your client-side instrumentation in instrumentation-client.ts which is available after v15.3 (Next.js docs).

If something does not work with this setup please open a new issue describing your problem as this is not connected to this issue title anymore.

@devuxer
Copy link

devuxer commented May 5, 2025

Hello, please check this issue regarding Turbopack support: #8105

You can add your Sentry server configuration in instrumentation.ts and your client-side instrumentation in instrumentation-client.ts which is available after v15.3 (Next.js docs).

If something does not work with this setup please open a new issue describing your problem as this is not connected to this issue title anymore.

Thank you, @s1gr1d, are there docs on good Sentry defaults to use for instrumentation.ts and intrumentation-client.ts?

I have my instrumentation.ts set up like this so far:

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

const dsn = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;

export function register() {
    switch (process.env.NEXT_RUNTIME) {
        case "nodejs":
            Sentry.init({ dsn, sendDefaultPii: true });
            break;
        case "edge":
            Sentry.init({ dsn, sendDefaultPii: true });
            break;
    }
}

export const onRequestError = Sentry.captureRequestError;

Is this a good starting point?

How would my instrumentation-client.ts file differ?

@s1gr1d
Copy link
Member

s1gr1d commented May 8, 2025

You can find all the information about setting up the instrumentation filed in the docs here: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#initialize-sentry-client-side-and-server-side-sdks

@devuxer
Copy link

devuxer commented May 9, 2025

You can find all the information about setting up the instrumentation filed in the docs here: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#initialize-sentry-client-side-and-server-side-sdks

Hi @s1gr1d,

I have referred to those docs several times, but they do not seem to cover my use case, which is Turbopack for development + Webpack for production + Pages router.

I believe I need two files: instrumentation.ts and instrumentation-client.ts. (And note that I get errors if I try include a sentry.server.config.ts or sentry.edge.config.ts file.)

From the NextJS docs, it looks like I am not supposed to export a register function from instrumentation-client.ts.

From the Sentry docs, it looks like there are two different event handlers (onRequestError for the server and onRouterTransitionStart for the client), but onRequestError only applies if using the App Router (not the Pages Router).

If the above is correct, a basic setup would look like this:

instrumentation.ts:

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

const dsn = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;

export function register() {
    Sentry.init({ dsn, sendDefaultPii: true });

    /* for custom setup for Node vs. Edge, use this:
        switch (process.env.NEXT_RUNTIME) {
            case "nodejs":
            case "edge":
        }
    */
}

instrumentation-client.ts:

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

const dsn = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;

Sentry.init({ dsn, sendDefaultPii: true });

export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;

Does this seem correct?

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
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

7 participants