import type { NormalizedSpan } from './types.js'; export interface DefectsOptions { nowMs: number; windowMs: number; /** Number of time buckets in each defect's series. */ buckets: number; service?: string; /** Versions per service in deploy order (ServiceInfo.versions). */ deployOrder: Map; /** * False when the storage has dropped old spans. Then "not seen before the latest version" may only mean "its older * occurrences are gone", and a defect is called new only with evidence: `ranIn` for the previous version. */ historyComplete: boolean; /** Did this operation run (failed or not) in this version, among the spans still stored? */ ranIn?: (service: string, operation: string, version: string) => boolean; } export interface Defect { /** Stable for the same service + operation + message shape. */ id: string; service: string; /** * Where the error originated, as a person reads it: the span's name — for a browser request the method and the path * (`GET /api/inventory/:id`), since the span itself is named just "GET". */ operation: string; /** The span's exact name: what the operation page and the trace search look up. */ spanName: string; /** Where it happened: in the visitor's browser or on the server. */ source: 'browser' | 'server'; /** * `browser-error`: something the APM agent caught in the page (an uncaught error, a console.error, a failed resource…) * — `operation` is then the kind of error, not a piece of code. `request`: an outgoing HTTP call. `code`: the rest. */ category: 'browser-error' | 'request' | 'code'; /** Pages it happened on (browser errors), most frequent first. */ pages: { path: string; count: number; }[]; /** The most recent message, as thrown. */ message: string; /** exception.type of the most recent occurrence, when recorded. */ type: string | null; /** Occurrences in the window. */ count: number; /** Occurrences per time bucket of the window. */ series: number[]; /** Over everything stored, not just the window. */ firstSeenMs: number; lastSeenMs: number; firstSeenVersion: string | null; /** In deploy order. */ versions: string[]; /** * The last deploy brought it: first seen in the service's latest version, which is not the only one — and the older * history is trustworthy (nothing dropped, or the operation is still on record running in the previous version). */ isNew: boolean; /** Requests that failed because of it (the topmost failed span), most frequent first. Empty when it is the origin itself. */ affected: { service: string; operation: string; spanName: string; count: number; }[]; /** Most recent first. */ exampleTraceIds: string[]; } export declare function errorMessage(span: NormalizedSpan): string; /** * The shape of a message: ids and numbers replaced, so "Order 4127 not found" and "Order 9 not found" are one defect. * UUIDs first (their short groups would otherwise keep letters: "e29b" → "eb"), then long hex runs (trace ids, * hashes), then any remaining digits. */ export declare function messageShape(message: string): string; export declare function computeDefects(spans: NormalizedSpan[], options: DefectsOptions): Defect[];