Skip to content

Sentry/Next.js: tags are not added for exceptions logged in app/error.tsx #13944

@christianvuerings

Description

@christianvuerings

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

Framework Version

Next.js 14.2.12

Link to Sentry event

https://cambly-inc.sentry.io/issues/5978793591/?project=234235&query=TEST_ERROR_DEFG_1234&referrer=issue-stream&statsPeriod=7d&stream_index=0

Reproduction Example/SDK Setup

import { type Options, type Integration } from "@sentry/types";

const sentryConfig: Options & { integrations: Integration[] } = {
  dsn: "https://[email protected]/234235",
  release: `cambly-frontend@development`,
  environment: "development",
  debug: true,
  allowUrls: [
    "webpack-internal://",
    "localhost:8080",
    "localhost:8084",
  ],
  integrations: [],
  beforeSend: (event) => {
    // For debugging
    console.log("///// event beforeSend", {
      tags: event.tags ? JSON.stringify(Object.keys(event.tags)) : null,
    });

    return event;
  },
  tracesSampler(): number {
    return process.env.NODE_ENV !== "production" ? 1 : 0.05;
  },
};

Steps to Reproduce

  1. Create a app/error.tsx file:
"use client";

import { useEffect, type ReactElement } from "react";
import * as Sentry from "@sentry/nextjs";

export default function Error({
  error,
  reset,
}: {
  error: Error & { digest?: string };
  reset: () => void;
}): ReactElement {
  console.log("///// captured before", error.__sentry_captured__);
  useEffect(() => {
    Sentry.withScope((scope) => {
      scope.clear();
      scope.setTag("cambly.captureLocationTemp", "nextjsPageErrorAppError");
      Sentry.captureException(error);
    });
  }, [error]);

  return (
    <h2>
      Something went wrong{" "}
      <button onClick={() => reset()} type="button">
        Reset
      </button>
    </h2>
  );
}
  1. Create a page route app/page.tsx:
"use client";

import { type ReactElement } from "react";
import { useSearchParams } from "next/navigation";

export default function Page(): ReactElement {

  const throwErrorIntentionally = useSearchParams().get("throwErrorIntentionally");
  if (throwErrorIntentionally === "true") {
    throw new Error("TEST_ERROR_DEFG_1234");
  }

  return (
   <h1>Test</h1>
  );
}
  1. Go to http://localhost:8080?throwErrorIntentionally=true

Expected Result

Error contains cambly.captureLocationTemp tag

Actual Result

Error does not contain cambly.captureLocationTemp

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPackage: nextjsIssues related to the Sentry Nextjs SDK

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions