Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(observability): stop sending opaque non-Error captures to Sentry (LANGFUSE-5EX cluster) (#15175)

Nikita Kabardind4bc213a9b98
diff --git a/web/src/components/table/data-table-ai-filters.tsx b/web/src/components/table/data-table-ai-filters.tsx
index cbdd5092e3..e63d4d5749 100644
--- a/web/src/components/table/data-table-ai-filters.tsx
+++ b/web/src/components/table/data-table-ai-filters.tsx
@@ -48,7 +48,10 @@ export function DataTableAIFilters({
onFiltersGenerated(result.filters as FilterState);
setAiPrompt("");
} else {
- console.error(result);
+ console.error(
+ "dataTable.aiFilters: invalid response format",
+ JSON.stringify(result),
+ );
setAiError("Invalid response format from API");
}
} catch (error) {
diff --git a/web/src/components/ui/resizable-image.tsx b/web/src/components/ui/resizable-image.tsx
index 6f8d04938d..3a0b5fb67a 100644
--- a/web/src/components/ui/resizable-image.tsx
+++ b/web/src/components/ui/resizable-image.tsx
@@ -6,7 +6,6 @@ import { Button } from "@/src/components/ui/button";
import { ImageOff, Maximize2, Minimize2 } from "lucide-react";
import { api } from "@/src/utils/api";
import { Skeleton } from "@/src/components/ui/skeleton";
-import { captureException } from "@sentry/nextjs";
import { useSession } from "next-auth/react";
import { buildResizableImageSrc } from "./resizable-image.utils";
import { getSafeImageUrl } from "@/src/components/ui/safe-url";
@@ -143,9 +142,13 @@ export const ResizableImage = ({
"rounded border",
fitContent ? "h-auto w-full" : "h-full w-full object-contain",
)}
- onError={(error) => {
+ onError={() => {
+ // An image failing to load is an <img> error Event (a
+ // SyntheticEvent), not an Error, and is expected: rendered
+ // markdown routinely points at dead user-content URLs. Show
+ // the fallback UI; do not report it to Sentry (a non-Error
+ // capture is opaque and not actionable for us).
setHasFetchError(true);
- captureException(error);
}}
/>
<Button
diff --git a/web/src/features/datasets/components/NewDatasetItemForm.tsx b/web/src/features/datasets/components/NewDatasetItemForm.tsx
index 2bb1590c82..25bdf037ab 100644
--- a/web/src/features/datasets/components/NewDatasetItemForm.tsx
+++ b/web/src/features/datasets/components/NewDatasetItemForm.tsx
@@ -326,10 +326,12 @@ export const NewDatasetItemForm = (props: {
return;
}
+ // The user already sees the validation errors via setFormError above;
+ // a bare console.error(object) would only add an opaque, non-actionable
+ // Sentry capture (captureConsoleIntegration), so we omit it here.
setFormError(
`Item does not match dataset schema. Errors: ${JSON.stringify(result.validationErrors, null, 2)}`,
);
- console.error(result.validationErrors);
})
.catch((error) => {
console.error(error);
diff --git a/web/src/features/filters/components/filter-builder.tsx b/web/src/features/filters/components/filter-builder.tsx
index c7069c156e..352e982134 100644
--- a/web/src/features/filters/components/filter-builder.tsx
+++ b/web/src/features/filters/components/filter-builder.tsx
@@ -548,7 +548,10 @@ function FilterBuilderForm({
setAiPrompt("");
setShowAiFilter(false);
} else {
- console.error(result);
+ console.error(
+ "filterBuilder.aiGenerate: invalid response format",
+ JSON.stringify(result),
+ );
setAiError("Invalid response format from API");
}
} catch (error) {
diff --git a/web/src/features/playground/page/components/Messages.tsx b/web/src/features/playground/page/components/Messages.tsx
index db61f13cf6..09b62d3980 100644
--- a/web/src/features/playground/page/components/Messages.tsx
+++ b/web/src/features/playground/page/components/Messages.tsx
@@ -11,6 +11,7 @@ import { Settings } from "lucide-react";
import useLocalStorage from "@/src/components/useLocalStorage";
import { env } from "@/src/env.mjs";
import { STREAMING_PREF_KEY } from "@/src/features/playground/page/storage/keys";
+import { captureUnknownError } from "@/src/utils/captureUnknownError";
import { GenerationOutput } from "./GenerationOutput";
import { ChatMessages } from "@/src/components/ChatMessages";
@@ -56,7 +57,9 @@ const SubmitButton = () => {
<Button
className="flex-1"
onClick={() => {
- handleSubmit(streamingEnabled).catch((err) => console.error(err));
+ handleSubmit(streamingEnabled).catch((err) =>
+ captureUnknownError("playground.run", err),
+ );
}}
loading={isStreaming}
>
diff --git a/web/src/features/playground/page/context/index.tsx b/web/src/features/playground/page/context/index.tsx
index cbc3960138..792a8b2df8 100644
--- a/web/src/features/playground/page/context/index.tsx
+++ b/web/src/features/playground/page/context/index.tsx
@@ -50,6 +50,7 @@ import {
import { useSyncMessageSearchMessages } from "@/src/components/ChatMessages/MessageSearch";
import { getFinalModelParams } from "@/src/utils/getFinalModelParams";
import { STREAMING_PREF_KEY } from "@/src/features/playground/page/storage/keys";
+import { captureUnknownError } from "@/src/utils/captureUnknownError";
type PlaygroundContextType = {
windowId: string;
@@ -633,7 +634,9 @@ export const PlaygroundProvider: React.FC<PlaygroundProviderProps> = ({
// malformed localStorage value — fall back to default
}
- handleSubmit(streaming).catch((err) => console.error(err));
+ handleSubmit(streaming).catch((err) =>
+ captureUnknownError("playground.run", err),
+ );
}
// If no content, skip silently
}
diff --git a/web/src/features/playground/page/hooks/useCommandEnter.ts b/web/src/features/playground/page/hooks/useCommandEnter.ts
index 85206c9040..43223923e3 100644
--- a/web/src/features/playground/page/hooks/useCommandEnter.ts
+++ b/web/src/features/playground/page/hooks/useCommandEnter.ts
@@ -1,4 +1,5 @@
import { useEffect } from "react";
+import { captureUnknownError } from "@/src/utils/captureUnknownError";
export default function useCommandEnter(
isEnabled: boolean,
@@ -13,7 +14,7 @@ export default function useCommandEnter(
if (isEnabled && hasRunAllModifier && event.key === "Enter") {
event.preventDefault();
event.stopPropagation();
- callback().catch((err) => console.error(err));
+ callback().catch((err) => captureUnknownError("playground.run", err));
}
}
diff --git a/web/src/pages/auth/enterprise-sso-required.tsx b/web/src/pages/auth/enterprise-sso-required.tsx
index b13cb072fe..ab920010df 100644
--- a/web/src/pages/auth/enterprise-sso-required.tsx
+++ b/web/src/pages/auth/enterprise-sso-required.tsx
@@ -18,7 +18,7 @@ import {
} from "@/src/components/ui/form";
import { Input } from "@/src/components/ui/input";
import { env } from "@/src/env.mjs";
-import { captureException } from "@sentry/nextjs";
+import { captureUnknownError } from "@/src/utils/captureUnknownError";
const enterpriseSsoFormSchema = z.object({
email: z.email(),
@@ -123,7 +123,7 @@ export default function EnterpriseSsoRequiredPage() {
"Unable to start the Enterprise SSO sign-in flow. Please try again.",
);
} catch (err) {
- captureException(err);
+ captureUnknownError("auth.enterpriseSso", err);
setError(
"Something went wrong while checking your Enterprise SSO configuration. Please try again.",
);
diff --git a/web/src/pages/auth/sign-in.tsx b/web/src/pages/auth/sign-in.tsx
index 1b7ed1cd2a..d5f7d8a4b3 100644
--- a/web/src/pages/auth/sign-in.tsx
+++ b/web/src/pages/auth/sign-in.tsx
@@ -39,6 +39,7 @@ import { isEmailVerificationRequired } from "@/src/features/auth-credentials/lib
import { Code, Key } from "lucide-react";
import { useRouter } from "next/router";
import { captureException } from "@sentry/nextjs";
+import { captureUnknownError } from "@/src/utils/captureUnknownError";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import useLocalStorage from "@/src/components/useLocalStorage";
import { AuthProviderButton } from "@/src/features/auth/components/AuthProviderButton";
@@ -220,7 +221,7 @@ export function SSOButtons({
// do not reset loadingProvider here, as the page will reload
})
.catch((error) => {
- console.error(error);
+ captureUnknownError("auth.signIn.provider", error, { provider });
setProviderSigningIn(null);
});
};
@@ -640,8 +641,7 @@ export default function SignIn({
);
}
} catch (error) {
- captureException(error);
- console.error(error);
+ captureUnknownError("auth.signIn.credentials", error);
setCredentialsFormError("An unexpected error occurred.");
}
}
@@ -710,7 +710,7 @@ export default function SignIn({
}
}, 100);
} catch (error) {
- console.error(error);
+ captureUnknownError("auth.signIn.checkSso", error);
setCredentialsFormError(
"Unable to check SSO configuration. Please try again.",
);
diff --git a/web/src/pages/auth/sign-up.tsx b/web/src/pages/auth/sign-up.tsx
index 054754bfaf..cc971aa7fe 100644
--- a/web/src/pages/auth/sign-up.tsx
+++ b/web/src/pages/auth/sign-up.tsx
@@ -29,6 +29,7 @@ import { PasswordInput } from "@/src/components/ui/password-input";
import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";
import { useRouter } from "next/router";
import { getSafeRedirectPath } from "@/src/utils/redirect";
+import { captureUnknownError } from "@/src/utils/captureUnknownError";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import useLocalStorage from "@/src/components/useLocalStorage";
import { noUrlCheck, StringNoHTMLNonEmpty } from "@langfuse/shared";
@@ -182,7 +183,7 @@ function StandardSignupFlow({
}
}, 100);
} catch (error) {
- console.error(error);
+ captureUnknownError("auth.signUp.checkSso", error);
setFormError("Unable to check SSO configuration. Please try again.");
} finally {
setContinueLoading(false);
diff --git a/web/src/utils/captureUnknownError.clienttest.ts b/web/src/utils/captureUnknownError.clienttest.ts
new file mode 100644
index 0000000000..46f3798014
--- /dev/null
+++ b/web/src/utils/captureUnknownError.clienttest.ts
@@ -0,0 +1,121 @@
+import { captureUnknownError } from "@/src/utils/captureUnknownError";
+
+const { captureExceptionMock } = vi.hoisted(() => ({
+ captureExceptionMock: vi.fn(),
+}));
+
+vi.mock("@sentry/nextjs", () => ({
+ captureException: captureExceptionMock,
+}));
+
+describe("captureUnknownError", () => {
+ let warnSpy: ReturnType<typeof vi.spyOn>;
+ let errorSpy: ReturnType<typeof vi.spyOn>;
+
+ beforeEach(() => {
+ captureExceptionMock.mockClear();
+ warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
+ errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
+ });
+
+ afterEach(() => {
+ warnSpy.mockRestore();
+ errorSpy.mockRestore();
+ });
+
+ it("passes a real Error through untouched (preserves the instance/stack)", () => {
+ const original = new Error("boom");
+ captureUnknownError("test.ctx", original);
+
+ expect(captureExceptionMock).toHaveBeenCalledTimes(1);
+ const call = captureExceptionMock.mock.calls[0];
+ expect(call).toBeDefined();
+ const [err, options] = call!;
+ expect(err).toBe(original); // same instance → original stack preserved
+ expect(options.extra.context).toBe("test.ctx");
+ expect(options.tags.area).toBe("test.ctx");
+ });
+
+ it("wraps a string as `[context] string`", () => {
+ captureUnknownError("test.ctx", "something failed");
+
+ const [err] = captureExceptionMock.mock.calls[0]!;
+ expect(err).toBeInstanceOf(Error);
+ expect(err.message).toBe("[test.ctx] something failed");
+ });
+
+ it("renders a plain object legibly (not [object Object])", () => {
+ captureUnknownError("test.ctx", { code: 42, reason: "bad" });
+
+ const [err] = captureExceptionMock.mock.calls[0]!;
+ expect(err).toBeInstanceOf(Error);
+ expect(err.message).not.toContain("[object Object]");
+ expect(err.message).toContain("code");
+ expect(err.message).toContain("42");
+ });
+
+ it("renders a key-less object (Event/SyntheticEvent) via its constructor name, not [object …]", () => {
+ // An <img> onError / a DOM Event exposes its fields as prototype getters,
+ // so it has no own enumerable keys → JSON.stringify yields "{}". This class
+ // instance reproduces that shape deterministically (jsdom, unlike real
+ // browsers, adds an own `isTrusted` key to DOM Events).
+ class SyntheticErrorEvent {
+ get type() {
+ return "error";
+ }
+ }
+ captureUnknownError("test.ctx", new SyntheticErrorEvent());
+
+ const [err] = captureExceptionMock.mock.calls[0]!;
+ expect(err.message).not.toContain("[object");
+ expect(err.message).toContain("SyntheticErrorEvent");
+ });
+
+ it("renders a real DOM Event legibly (never [object Event])", () => {
+ captureUnknownError("test.ctx", new Event("error"));
+
+ const [err] = captureExceptionMock.mock.calls[0]!;
+ expect(err.message).not.toContain("[object");
+ });
+
+ it("handles circular references without throwing", () => {
+ const circular: Record<string, unknown> = { a: 1 };
+ circular.self = circular;
+
+ expect(() => captureUnknownError("test.ctx", circular)).not.toThrow();
+ const [err] = captureExceptionMock.mock.calls[0]!;
+ expect(err.message).not.toContain("[object Object]");
+ expect(err.message).toContain("a"); // constructor-name fallback lists keys
+ });
+
+ it("logs via console.warn, never console.error (avoids captureConsole double-capture)", () => {
+ captureUnknownError("test.ctx", "x");
+
+ expect(warnSpy).toHaveBeenCalledTimes(1);
+ expect(errorSpy).not.toHaveBeenCalled();
+ });
+
+ it("prints the context tag exactly once for a non-Error value (no double-tag)", () => {
+ captureUnknownError("auth.signIn.credentials", { reason: "bad" });
+
+ expect(warnSpy).toHaveBeenCalledTimes(1);
+ const message = String(warnSpy.mock.calls[0]![0]);
+ const occurrences = message.split("[auth.signIn.credentials]").length - 1;
+ expect(occurrences).toBe(1);
+ });
+
+ it("prints the context once plus the original message for a real Error", () => {
+ captureUnknownError("auth.signIn.credentials", new Error("kaboom"));
+
+ expect(warnSpy).toHaveBeenCalledTimes(1);
+ const message = String(warnSpy.mock.calls[0]![0]);
+ const occurrences = message.split("[auth.signIn.credentials]").length - 1;
+ expect(occurrences).toBe(1);
+ expect(message).toContain("kaboom");
+ });
+
+ it("captures exactly once per call", () => {
+ captureUnknownError("test.ctx", new Error("once"));
+ expect(captureExceptionMock).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/web/src/utils/captureUnknownError.ts b/web/src/utils/captureUnknownError.ts
new file mode 100644
index 0000000000..33ea767bae
--- /dev/null
+++ b/web/src/utils/captureUnknownError.ts
@@ -0,0 +1,72 @@
+import { captureException } from "@sentry/nextjs";
+
+/**
+ * Turn an unknown thrown/logged value into a legible string.
+ *
+ * `String(value)` and template interpolation collapse most objects to the
+ * useless `[object Object]` / `[object ErrorEvent]`. We try `JSON.stringify`
+ * first, and when that yields nothing useful — `"{}"` for objects whose fields
+ * live on the prototype (DOM `Event`s, `DOMException`), or a throw on circular
+ * references — we fall back to a descriptor built from the value's constructor
+ * name and own enumerable keys.
+ */
+function safeStringify(value: unknown): string {
+ try {
+ const json = JSON.stringify(value);
+ if (json !== undefined && json !== "{}") {
+ return json;
+ }
+ } catch {
+ // circular reference or a throwing getter — fall through to describe()
+ }
+ return describeUnknown(value);
+}
+
+function describeUnknown(value: unknown): string {
+ if (value === null) return "null";
+ if (typeof value !== "object") return String(value);
+ const ctorName =
+ (value as { constructor?: { name?: string } }).constructor?.name ??
+ "Object";
+ const keys = Object.keys(value as Record<string, unknown>);
+ return keys.length > 0 ? `${ctorName} { ${keys.join(", ")} }` : ctorName;
+}
+
+/**
+ * Report an unknown (possibly non-Error) value to Sentry as a legible Error.
+ *
+ * `instrumentation-client.ts` enables
+ * `captureConsoleIntegration({ levels: ["error"] })`, so every
+ * `console.error(nonError)` also becomes an opaque Sentry event
+ * (`[object Object]` / "Object captured as exception with keys …"). Route
+ * caught-unknown values through here instead: real `Error`s pass through
+ * untouched (stack preserved); anything else is synthesized into an `Error`
+ * with a readable message. We log with `console.warn` (not `console.error`) so
+ * the integration does not double-capture the same failure.
+ */
+export function captureUnknownError(
+ context: string,
+ value: unknown,
+ extra?: Record<string, unknown>,
+): void {
+ const err =
+ value instanceof Error
+ ? value
+ : new Error(
+ `[${context}] ${
+ typeof value === "string" ? value : safeStringify(value)
+ }`,
+ );
+ captureException(err, {
+ extra: { context, ...extra },
+ tags: { area: context },
+ });
+ // warn, not error → captureConsoleIntegration only captures console.error,
+ // so this line does not create a second, opaque Sentry event. The
+ // synthesized (non-Error) message already carries the `[context]` prefix; a
+ // pass-through Error does not, so add it here only in that branch to keep the
+ // context present exactly once in both cases.
+ console.warn(
+ value instanceof Error ? `[${context}] ${err.message}` : err.message,
+ );
+}