Skip to content

Source files with debug ids are not uploaded to SentryΒ #13634

@jdwitten

Description

@jdwitten

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.28.0

Framework Version

Next 14.2.3

Link to Sentry event

https://cargado.sentry.io/issues/5764333237/?project=4506304797278208&query=is%3Aunresolved+issue.priority%3A%5Bhigh%2C+medium%5D&referrer=issue-stream&statsPeriod=90d&stream_index=23

Reproduction Example/SDK Setup

next.config.js

const { withSentryConfig } = require('@sentry/nextjs');

module.exports = withSentryConfig(
  module.exports,
  {
    // For all available options, see:
    // https://github.com/getsentry/sentry-webpack-plugin#options

    // Suppresses source map uploading logs during build
    silent: false,
    org: process.env.SENTRY_ORG,
    project: process.env.SENTRY_PROJECT,
  },
  {
    // For all available options, see:
    // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

    // Upload a larger set of source maps for prettier stack traces (increases build time)
    widenClientFileUpload: true,

    // Transpiles SDK to be compatible with IE11 (increases bundle size)
    transpileClientSDK: true,

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

    // Automatically tree-shake Sentry logger statements to reduce bundle size
    disableLogger: true,

    productionBrowserSourceMaps: true,
  },
);

sentry.client.config.ts

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

if (process.env.NEXT_PUBLIC_SENTRY_DSN != null) {
  Sentry.init({
    dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
    tracesSampleRate: 0.1,
    debug: false,
    replaysOnErrorSampleRate: 0.1,
    replaysSessionSampleRate: 0.1,
    integrations: [
      Sentry.replayIntegration({
        maskAllText: true,
        blockAllMedia: true,
      }),
    ],
  });
}

src/instrumentation.ts

import { Attributes, Context, Link, SpanKind } from '@opentelemetry/api';
import { W3CTraceContextPropagator } from '@opentelemetry/core';
import {
  Sampler,
  SamplingDecision,
  SamplingResult,
} from '@opentelemetry/sdk-trace-base';
import { SEMRESATTRS_DEPLOYMENT_ENVIRONMENT } from '@opentelemetry/semantic-conventions';
import * as Sentry from '@sentry/nextjs';
import { registerOTel } from '@vercel/otel';

import { getAppVariant, getFullConfig } from './config/util/getConfig';

export const TRACER_NAME = 'salsa';

export function register() {
  const {
    public: { sentry },
  } = getFullConfig();

  registerOTel({
    serviceName: <redacted_service_name>
    propagators: [new W3CTraceContextPropagator()],
    traceSampler: excludeHealthChecks,
    attributes: {
      [SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: getAppVariant(),
    },
  });

  if (sentry.enabled) {
    const nextRuntime = process.env.NEXT_RUNTIME;
    if (nextRuntime === 'nodejs' || nextRuntime === 'edge') {
      Sentry.init({
        dsn: sentry.dsn,
        tracesSampleRate: sentry.tracesSampleRate,
        debug: sentry.debug,
      });
    }
  }
}

const excludeHealthChecks: Sampler = {
  shouldSample: function (
    _context: Context,
    _traceId: string,
    spanName: string,
    _spanKind: SpanKind,
    _attributes: Attributes,
    _links: Link[],
  ): SamplingResult {
    if (/api\/health/.test(spanName)) {
      return { decision: SamplingDecision.NOT_RECORD };
    }
    return { decision: SamplingDecision.RECORD_AND_SAMPLED };
  },
};

Steps to Reproduce

We have some (not all) issues in Sentry with missing stack frames because there is no uploaded source file with the same debug id. What's interesting is that the debug ids do exist in the stack frame but it just looks like they can't be matched up with source files that should have been uploaded with next build. Some potential clues I've noticed:

  1. All of the issues with unlinked stack traces seem to be originating from the client bundle - issues in server side code seems to be getting linked correctly
  2. Most of the errors (potentially all, but it's difficult to verify) with missing source files are originating in framework or dependency code. But my understanding is that even dependencies should be uploaded to Sentry if they end up in your production bundle (please correct me if I'm wrong about this).

Some more info on our setup:

  • We are running next.js in a Docker container on ECS
  • Source maps and source files are being uploaded in our CI/CD production build on CircleCI. I did turn on verbose logging here silent: false in the Sentry config to see if there were any issues. I did notice some warnings like - warning: could not determine a source map reference (Could not auto-detect referenced sourcemap for ~/<replace_with_uuid>.js) but when I investigated into those files it seems like it was just for a file with a default export and no real JS code so I think it was a bit of a red herring. Also it was complaining about the missing source map NOT the source file which is different than the described problem in the UI.
  • I have verified that we do have some sourcemaps and source files uploaded to Sentry under Settings > Projects > Source Maps > Artifact Bundles but I'm a bit stumped on how to debug further why not ALL of the source files are getting uploaded. Or more generally how could there be a debug ID in the stack trace but missing a matching source file in Sentry?

Expected Result

I expect the stack frame to be correctly linked to source code like other issues in our project:
Image

Actual Result

Image
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPackage: nextjsIssues related to the Sentry Nextjs SDK

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions