autotel
Version:
Write Once, Observe Anywhere
51 lines • 2.47 kB
TypeScript
import { SpanProcessor } from "@opentelemetry/sdk-trace-base";
//#region src/exception-fingerprint.d.ts
/** Attribute the fingerprint is written to. */
declare const EXCEPTION_FINGERPRINT_ATTRIBUTE = "exception.fingerprint";
interface ExceptionInput {
/** Error class name, e.g. `TypeError`. Defaults to `Error`. */
type?: string;
/** Error message. Only used for grouping when there is no usable stack. */
message?: string;
/** Raw stack string, as `Error.stack` produces it. */
stack?: string;
}
/**
* Collapse a path to the part that identifies the code rather than the machine
* it ran on: a dependency becomes its package name, and an absolute path
* becomes the project-relative one. Without this, the same error fingerprints
* differently in CI, in Docker, and on a laptop.
*/
declare function normalizeFilePath(filePath: string): string;
/**
* Strip the parts of a message that change on every occurrence, so
* `timeout after 341ms` and `timeout after 78ms` are one issue rather than two.
*/
declare function normalizeMessage(message: string): string;
/**
* `function@normalized-path` for the top N frames. Line and column are
* deliberately dropped: an edit one line above the throw is the same bug.
*/
declare function normalizeStackFrames(stack: string, count: number): string[];
/** 32-bit djb2-style hash, rendered as 8 hex characters. */
declare function hashFingerprintParts(parts: string[]): string;
/**
* Group key for an exception. Returns `undefined` when there is nothing to
* group on, so callers never write an attribute that means "no information".
*/
declare function fingerprintException(input: ExceptionInput, frames?: number): string | undefined;
interface ExceptionFingerprintOptions {
/** Stack frames to fingerprint on. @default 5 */
frames?: number;
}
/**
* Span enricher that stamps {@link EXCEPTION_FINGERPRINT_ATTRIBUTE} on every
* span that recorded an exception.
*
* Pass it to `init({ spanEnrichers: [...] })` rather than `spanProcessors`:
* enrichers add to the pipeline instead of replacing it, and sit outside the
* redaction wrapper so the attribute reaches every exporter.
*/
declare function exceptionFingerprint(options?: ExceptionFingerprintOptions): SpanProcessor;
//#endregion
export { EXCEPTION_FINGERPRINT_ATTRIBUTE, ExceptionFingerprintOptions, ExceptionInput, exceptionFingerprint, fingerprintException, hashFingerprintParts, normalizeFilePath, normalizeMessage, normalizeStackFrames };