mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix(telemetry): sharpen Sentry signal for v2.1.0 residual defects (#498)
Follow-ups to the v2.1.0 Sentry telemetry overhaul, found by reviewing live release:2.1.0 events: - error_code tag was empty because reportError read only the top-level err.code; add extractErrorCode() to walk the cause chain (pg SQLSTATE, node E-code, else first short code). - InputValidationError from a tool's processV2 in the worker was logged as error_class=bug; classify it as expected for any source. Worker-side ZodError stays a bug (schema drift). - AI dispatcher timeouts rejected with a bare Error, which the sanitizer scrubbed to a message-less "Error: Error"; reject with an operational SafeError (code "timeout") at both timeout sites. Each fix written failing-test-first; affected and adjacent unit suites green plus full CI (integration + e2e).
This commit is contained in:
@@ -46,6 +46,21 @@ describe("capture path", () => {
|
||||
expect(h.scope.setTag).toHaveBeenCalledWith("pool", "image");
|
||||
});
|
||||
|
||||
it("tags error_code from a code nested in the cause chain, not just the top level", async () => {
|
||||
// pg/undici bury the real code under a drizzle/wrapper Error whose own
|
||||
// .code is undefined; reading only the top level left error_code empty.
|
||||
const pg = Object.assign(new Error("password authentication failed"), {
|
||||
code: "28P01",
|
||||
severity: "FATAL",
|
||||
});
|
||||
const wrapped = Object.assign(new Error("Failed query: select 1"), { cause: pg });
|
||||
|
||||
await reportError(wrapped, { source: "worker", pool: "docs" });
|
||||
|
||||
expect(h.captureException).toHaveBeenCalledTimes(1);
|
||||
expect(h.scope.setTag).toHaveBeenCalledWith("error_code", "28P01");
|
||||
});
|
||||
|
||||
it("captures once per distinct signature; operational repeats are throttled", async () => {
|
||||
const full = Object.assign(new Error("disk full"), { code: "ENOSPC" });
|
||||
await reportError(full, { source: "worker", pool: "image" });
|
||||
|
||||
@@ -50,6 +50,17 @@ describe("classifyError", () => {
|
||||
expect(classifyError(reset, "worker")).toBe("operational");
|
||||
expect(classifyError(reset, "http")).toBe("expected");
|
||||
});
|
||||
it("InputValidationError is a user 400 wherever it surfaces, not only on http", () => {
|
||||
// Tools throw InputValidationError from processV2 in the worker (e.g.
|
||||
// sprite-sheet "Provide at least two images"); it must not be logged as a bug.
|
||||
const e = Object.assign(new Error("Provide at least two images"), {
|
||||
name: "InputValidationError",
|
||||
});
|
||||
expect(classifyError(e, "worker")).toBe("expected");
|
||||
expect(classifyError(e, "cron")).toBe("expected");
|
||||
expect(classifyError(e, "http")).toBe("expected");
|
||||
expect(classifyError(e)).toBe("expected");
|
||||
});
|
||||
});
|
||||
|
||||
describe("throttle", () => {
|
||||
|
||||
Reference in New Issue
Block a user