Skip to content

Docker Compose crashes when using @sentry/nextjs #9405

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
fimbres opened this issue Oct 28, 2023 · 5 comments
Closed
3 tasks done

Docker Compose crashes when using @sentry/nextjs #9405

fimbres opened this issue Oct 28, 2023 · 5 comments
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Stale

Comments

@fimbres
Copy link

fimbres commented Oct 28, 2023

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

^7.74.1

Framework Version

Next.js 13.5.5, React: 18.2.0

Link to Sentry event

No response

SDK Setup

sentry config:
`/ This file configures the initialization of Sentry on the client.
// The config you add here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

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

Sentry.init({
dsn: "https://f24c7de63b0064121f43c8c8c83dc047@o4506087957921792.ingest.sentry.io/4506087959429120",

// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,

replaysOnErrorSampleRate: 1.0,

// This sets the sample rate to be 10%. You may want this to be 100% while
// in development and sample at a lower rate in production
replaysSessionSampleRate: 0.1,

// You can remove this option if you're not planning to use the Sentry Session Replay feature:
integrations: [
new Sentry.Replay({
// Additional Replay configuration goes in here, for example:
maskAllText: true,
blockAllMedia: true,
}),
],
});
`

Steps to Reproduce

  1. following up the automatically setup from sentry.io in the webapp.
  2. implement docker to deploy the app
  3. use docker compose
  4. the app first crashes getting the error Module not found: Can't resolve '@sentry/utils/esm/buildPolyfills',
  5. then I install @sentry/utils
  6. the app crashes again getting the error Sentry CLI Plugin: Command failed: /dility/node_modules/.pnpm/@[email protected][email protected]/node_modules/@sentry/cli/sentry-cli releases new qocVBIgiVuEmOR8MUS5Ey 16.79 /dility/node_modules/.pnpm/@[email protected][email protected]/node_modules/@sentry/cli/sentry-cli: 2: Syntax error: "(" unexpected
  7. adding RUN pnpm add @sentry/cli in Dockerfile to see if that works but it throws the same error.

Dockerfile and docker compose files:
`FROM node:latest

WORKDIR /dility
COPY package.json pnpm-lock.yaml /dility/
RUN npm install -g pnpm
&& pnpm install
RUN pnpm add @sentry/utils
RUN pnpm add @sentry/cli

COPY . .
RUN pnpm run build
EXPOSE 3000
CMD ["pnpm", "start"]
`

version: '3' services: app: build: context: . dockerfile: Dockerfile ports: - '3000:3000' volumes: - .:/dility environment: - NODE_ENV=production

Expected Result

Getting my app deployed

Actual Result

My app is crashing with this error:
Sentry CLI Plugin: Command failed: /dility/node_modules/.pnpm/@[email protected][email protected]/node_modules/@sentry/cli/sentry-cli releases new qocVBIgiVuEmOR8MUS5Ey 16.79 /dility/node_modules/.pnpm/@[email protected][email protected]/node_modules/@sentry/cli/sentry-cli: 2: Syntax error: "(" unexpected

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Oct 28, 2023
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label Oct 28, 2023
@lforst
Copy link
Member

lforst commented Oct 30, 2023

Hi, since this might have to do with some dependencies clashing in your lockfile, would you mind providing a small repro repo we can clone to effectively debug this? Thanks.

As a workaround in the meanwhile you could set:

disableServerWebpackPlugin: true,
disableClientWebpackPlugin: true,

in you next.config.js. Note that this will prevent source maps from being uploaded.

@getsantry
Copy link

getsantry bot commented Nov 21, 2023

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 remove the label Waiting for: Community, I will leave it alone ... forever!


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

@getsantry getsantry bot added the Stale label Nov 21, 2023
@getsantry getsantry bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2023
@SanderCokart
Copy link

Have you fixed this issue yet? Running into the same issue.

@fimbres
Copy link
Author

fimbres commented Feb 9, 2024

The issue still happens. My workaround was using this node image node:18.15.0, if I use alpine or any other node image it crashes

@SanderCokart
Copy link

I FIGURED IT OUT.

You have to add the ca-certificates package from apt to the ubuntu instance.

Jetbrains AI to the rescue when I asked it the following:

Question

I am trying to authenticate sentry in a dockerfile for nextjs but I get the following error:
caused by: [60] SSL peer certificate or SSH remote key was not OK (SSL certificate problem: unable to get local issuer certificate)

It responsed with:

Answer

Based on the error message you provided, it appears your Docker image is experiencing problems authenticating the SSL certificate for Sentry during the build process. This is commonly because it can't verify the SSL certificate's issuer.

Here are a few things you can check and attempt to solve this:

  1. Check your Clock and TimeZone: SSL certificates are sensitive to time. Please make sure your local machine and Docker container timezone settings and clock are correct.

  2. Investigate a Proxy or Firewall Issue: If you're connected to the internet via a proxy server or you have a firewall active, it might be blocking your SSL handshake. You might have to configure the proxy settings for Docker or temporarily disable your firewall to see if this is causing the problem.

  3. Installing Certificate on Docker: You might need to install (or update) the CA certificates package in your Dockerfile. Don't forget that this will increase the build time of your image, as it needs to install the certificates before anything else:
    Here's an example of what you can add to your Dockerfile:
    FROM node:14 RUN apt-get update && apt-get install -y ca-certificates

  4. Disable SSL Verification (not recommended): This is generally not a recommended solution, as it would bypass SSL certificate verification and could expose your data transfer to potential risks. It's more suitable for a local development or testing environment, not for a production environment. Depending on your Sentry client, this option might differ, refer to the respective Sentry SDK to see if it provides an option to disable SSL verification.

Remember, changes in Dockerfile would require you to rebuild your image.
Given that SSL certificate errors may reveal a more serious problem, it would be best to diagnose and correct the SSL issue, rather than simply bypassing the certificate error.

Final Dockerfile

FROM node:21-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
COPY . /app

RUN apt-get update -y
RUN apt-get install -y ca-certificates

FROM base AS build
WORKDIR /app

ARG NPM_TOKEN
RUN echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile

# Write to .env
ARG NEXT_PUBLIC_API_URL="http://127.0.0.1:5000/tracking"
RUN echo "NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}" >> .env
ARG NEXT_OUTPUT="standalone"
RUN echo "NEXT_OUTPUT=${NEXT_OUTPUT}" >> .env
ARG SENTRY_AUTH_TOKEN
RUN echo "SENTRY_AUTH_TOKEN=${SENTRY_AUTH_TOKEN}" >> .env

# Disable telemetry during build time
ENV NEXT_TELEMETRY_DISABLED 1

RUN npm run build

FROM base
WORKDIR /app
COPY --from=build /app/node_modules /app/node_modules

# Disable telemetry during runtime
ENV NEXT_TELEMETRY_DISABLED 1

# Add nextjs user and group
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=build --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=build --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000

CMD ["node", "server.js"]

Final docker-compose.yml

version: "3"

services:
  nextjs:
    container_name: next-app
    build:
      dockerfile: ./Dockerfile
      context: .
      args:
        - NPM_TOKEN=
        - NEXT_PUBLIC_API_URL=
        - SENTRY_AUTH_TOKEN=
    ports:
      - 3000:3000

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

No branches or pull requests

3 participants