Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
🔇 Drop unsymbolicated minified iOS exceptions before send (#3006)
posthog-eu[bot]bb4f6985ac38
diff --git a/packages/posthog/src/client.ts b/packages/posthog/src/client.tsindex d91ff55e0..0a8dbae78 100644--- a/packages/posthog/src/client.ts+++ b/packages/posthog/src/client.ts@@ -8,6 +8,7 @@ import {isGlobalPrivacyControlEnabled,isInjectedExtensionException,isResizeObserverLoopError,+ isUnsymbolicatedMinifiedException,} from "./utils";if (typeof window !== "undefined" && process.env.NEXT_PUBLIC_POSTHOG_API_KEY) {@@ -30,7 +31,8 @@ if (typeof window !== "undefined" && process.env.NEXT_PUBLIC_POSTHOG_API_KEY) {event?.event === "$exception" &&(isInjectedExtensionException(event) ||isAbortError(event) ||- isResizeObserverLoopError(event))+ isResizeObserverLoopError(event) ||+ isUnsymbolicatedMinifiedException(event))) {return null;}diff --git a/packages/posthog/src/utils.test.ts b/packages/posthog/src/utils.test.tsindex f5dbba6e6..3535d4f1c 100644--- a/packages/posthog/src/utils.test.ts+++ b/packages/posthog/src/utils.test.ts@@ -4,6 +4,7 @@ import {getPostHogCookieName,isAbortError,isResizeObserverLoopError,+ isUnsymbolicatedMinifiedException,parsePostHogCookieDistinctId,} from "./utils";@@ -106,6 +107,84 @@ describe("isResizeObserverLoopError", () => {});});+describe("isUnsymbolicatedMinifiedException", () => {+ const event = (exceptionList: unknown) =>+ ({+ properties: { $exception_list: exceptionList },+ }) as unknown as CaptureResult;++ const documentFrames = [+ { filename: "https://app.rallly.co/", function: "?" },+ { filename: "https://app.rallly.co/", function: "?" },+ ];++ it("matches a minified identifier with no /_next/static frame", () => {+ for (const value of ["fa", "ga", "Ba", "Ca"]) {+ expect(+ isUnsymbolicatedMinifiedException(+ event([+ { type: "Error", value, stacktrace: { frames: documentFrames } },+ ]),+ ),+ ).toBe(true);+ }+ });++ it("does not match when a frame resolves to a /_next/static chunk", () => {+ expect(+ isUnsymbolicatedMinifiedException(+ event([+ {+ type: "Error",+ value: "Ca",+ stacktrace: {+ frames: [+ ...documentFrames,+ { filename: "https://app.rallly.co/_next/static/chunk.js" },+ ],+ },+ },+ ]),+ ),+ ).toBe(false);+ });++ it("does not match a readable error message", () => {+ expect(+ isUnsymbolicatedMinifiedException(+ event([+ {+ type: "TypeError",+ value: "x is not a function",+ stacktrace: { frames: documentFrames },+ },+ ]),+ ),+ ).toBe(false);+ });++ it("does not match a minified value without a stack", () => {+ expect(+ isUnsymbolicatedMinifiedException(+ event([{ type: "Error", value: "Ca", stacktrace: { frames: [] } }]),+ ),+ ).toBe(false);+ expect(+ isUnsymbolicatedMinifiedException(+ event([{ type: "Error", value: "Ca" }]),+ ),+ ).toBe(false);+ });++ it("does not match when the exception list is missing", () => {+ expect(+ isUnsymbolicatedMinifiedException({+ properties: {},+ } as unknown as CaptureResult),+ ).toBe(false);+ });+});+describe("parsePostHogCookieDistinctId", () => {it("parses a URL-encoded JSON cookie value", () => {const value = encodeURIComponent(diff --git a/packages/posthog/src/utils.ts b/packages/posthog/src/utils.tsindex 772c5ab51..d1d6ffbeb 100644--- a/packages/posthog/src/utils.ts+++ b/packages/posthog/src/utils.ts@@ -139,3 +139,47 @@ export function isResizeObserverLoopError(event: CaptureResult) {RESIZE_OBSERVER_LOOP_VALUE_PATTERN.test(exception.value),);}++/**+ * An iOS-only throw reaches error tracking with a bare minified identifier as+ * its message (`fa`, `ga`, `Ba`, `Ca`, ...) and a stack whose every frame+ * resolves to the HTML document (`filename: https://app.rallly.co/`,+ * `function: "?"`) instead of a `/_next/static` chunk. Only chunk files ship+ * source maps (`productionBrowserSourceMaps` in next.config.ts), so an inline+ * document script can never be symbolicated and the stack stays useless. The+ * minifier renames the symbol on each release, so the message is part of the+ * fingerprint and every deploy opens a fresh, uninvestigable issue.+ *+ * Match a short minified identifier value together with a stack that carries no+ * `/_next/static` frame. This drops the whole class and covers the next rename.+ */+const MINIFIED_IDENTIFIER_VALUE_PATTERN = /^[A-Za-z$_][\w$]{0,2}$/;++export function isUnsymbolicatedMinifiedException(event: CaptureResult) {+ const exceptionList = event.properties?.$exception_list as+ | Array<{+ value?: string;+ stacktrace?: { frames?: Array<{ filename?: string }> };+ }>+ | undefined;++ if (!Array.isArray(exceptionList)) {+ return false;+ }++ return exceptionList.some((exception) => {+ if (+ typeof exception?.value !== "string" ||+ !MINIFIED_IDENTIFIER_VALUE_PATTERN.test(exception.value)+ ) {+ return false;+ }++ const frames = exception.stacktrace?.frames;+ if (!Array.isArray(frames) || frames.length === 0) {+ return false;+ }++ return !frames.some((frame) => frame?.filename?.includes("/_next/static"));+ });+}