diff --git a/ingest-api/src/integration.twoProjects.test.ts b/ingest-api/src/integration.twoProjects.test.ts index b182380..9bad604 100644 --- a/ingest-api/src/integration.twoProjects.test.ts +++ b/ingest-api/src/integration.twoProjects.test.ts @@ -258,6 +258,43 @@ describe.skipIf(!_testUrl)("two-project passive ingest (BIT-179)", () => { expect(Number((after[0] as { c: number }).c)).toBe(_nBefore); }); + it("skips BIT-SMOKE- in stack_trace when message omits marker (CRM-style payload)", async () => { + const [before] = await _pool.execute( + `SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`, + [_projectIdA], + ); + const _nBefore = Number((before[0] as { c: number }).c); + const _res = await _app.inject({ + method: "POST", + url: "/v1/ingest/events", + headers: { authorization: `Bearer ${_tokenA}` }, + payload: { + events: [ + { + schema_version: 1, + occurred_at: "2026-04-05T10:05:00.000Z", + level: "error", + message: "Exception", + stack_trace: "Error: BIT-SMOKE-CRM-MAIN-DIRECT\n#0 smoke", + }, + ], + }, + }); + expect(_res.statusCode).toBe(200); + const _body = JSON.parse(_res.body) as { + noise_filtered_count: number; + results: Array<{ skipped?: boolean; rule_id?: string }>; + }; + expect(_body.noise_filtered_count).toBe(1); + expect(_body.results[0]?.skipped).toBe(true); + expect(_body.results[0]?.rule_id).toBe("bitreport_smoke_marker"); + const [after] = await _pool.execute( + `SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`, + [_projectIdA], + ); + expect(Number((after[0] as { c: number }).c)).toBe(_nBefore); + }); + it("replays identical idempotent requests", async () => { const _payload = { events: [ diff --git a/ingest-api/src/lib/noisePolicy.test.ts b/ingest-api/src/lib/noisePolicy.test.ts index eb82f85..baf89a5 100644 --- a/ingest-api/src/lib/noisePolicy.test.ts +++ b/ingest-api/src/lib/noisePolicy.test.ts @@ -101,4 +101,18 @@ describe("evaluateNoise", () => { reason: "filtered_intentional_smoke_event", }); }); + + it("matches BIT-SMOKE- in stack_trace when message omits the marker (CRM PHP smoke)", () => { + const _r = evaluateNoise({ + level: "error", + message: "PHP exception", + stackText: "Error: BIT-SMOKE-CRM-MAIN-DIRECT\n#0 smoke", + filePathHint: "/smoke/crm-main.php", + }); + expect(_r).toEqual({ + matched: true, + ruleId: "bitreport_smoke_marker", + reason: "filtered_intentional_smoke_event", + }); + }); }); diff --git a/ingest-api/src/lib/noisePolicy.ts b/ingest-api/src/lib/noisePolicy.ts index 863df66..f599602 100644 --- a/ingest-api/src/lib/noisePolicy.ts +++ b/ingest-api/src/lib/noisePolicy.ts @@ -4,7 +4,7 @@ import { normalizeLevelToSeverity } from "./normalize.js"; * Versioned ruleset id (document in release notes when rules change). * Rule inventory and validation steps: `docs/operations/ingest-hardening-runbook.md`. */ -export const NOISE_RULESET_VERSION = "1.0.2"; +export const NOISE_RULESET_VERSION = "1.0.3"; export type NoiseEvaluation = | { matched: false } @@ -127,17 +127,21 @@ const _RULES: NoiseRule[] = [ /** * Conservative: never classify fatal/critical ingest levels as noise (avoid hiding real outages). - * Exception: reserved `BIT-SMOKE-` messages are intentional end-to-end probes (e.g. wdmi-store - * `/smoke/wdmi.js`) and are filtered at every ingest level so they do not open incidents. + * Exception: reserved `BIT-SMOKE-` markers are intentional end-to-end probes (e.g. wdmi-store + * `/smoke/wdmi.js`, CRM `/smoke/crm-main.php`) and are filtered at every ingest level so they do + * not open incidents. Some PHP reporters put the marker only in `stack_trace`, not in `message`. */ export function evaluateNoise(input: { level: string; message: string; + /** Client `stacktrace` / `stack_trace` when present — used only for BIT-SMOKE- detection. */ + stackText?: string; context?: Record; filePathHint: string; }): NoiseEvaluation { const _msg = input.message.trim(); - if (_msg.includes("BIT-SMOKE-")) { + const _stack = (input.stackText ?? "").trim(); + if (_msg.includes("BIT-SMOKE-") || _stack.includes("BIT-SMOKE-")) { return { matched: true, ruleId: "bitreport_smoke_marker", diff --git a/ingest-api/src/services/processIngestBatch.ts b/ingest-api/src/services/processIngestBatch.ts index 324454f..13d3322 100644 --- a/ingest-api/src/services/processIngestBatch.ts +++ b/ingest-api/src/services/processIngestBatch.ts @@ -169,9 +169,11 @@ async function _ingestOneEvent( const _severity = normalizeLevelToSeverity(_ev.level); const _message = _ev.message.trim(); const _context = _ev.context && typeof _ev.context === "object" ? _ev.context : null; + const _clientStackEarly = clientProvidedStack(_ev); const _noise = evaluateNoise({ level: _ev.level, message: _message, + ...(_clientStackEarly !== null ? { stackText: _clientStackEarly } : {}), context: _context ?? undefined, filePathHint: extractLocationFromContext(_context).filePath, }); @@ -184,7 +186,7 @@ async function _ingestOneEvent( fingerprint_policy_version: FINGERPRINT_POLICY_VERSION, }; } - const _clientStack = clientProvidedStack(_ev); + const _clientStack = _clientStackEarly; const _fingerprint = computeFingerprint({ clientFingerprint: _ev.fingerprint, message: _message,