bugdna (Python)¶
Deterministic exception fingerprinting, similarity comparison, regression detection, and thread-safe failure tracking for Python.
Installation¶
Quick Start¶
from bugdna import (
BugDnaAssertions,
FailureCategory,
FailureTracker,
compare_fingerprints,
dependency_graph,
diff_exceptions,
generate,
lookup,
normalize,
)
try:
# application logic
raise ValueError("Invalid account id 12345")
except Exception as exc:
fp = generate(exc)
print(fp.id) # BUGDNA-...
print(fp.signature) # module#func or ClassName#method
print(fp.category) # FailureCategory.VALIDATION
print(fp.family) # FailureFamily.VALIDATION
print(fp.stability_score) # 70..98
print(fp.explain()) # multi-line summary
Features¶
- Zero runtime dependencies — pure Python standard library (
hashlib,traceback,dataclasses,threading) withPEP 561type annotations. - Deterministic IDs — excludes exception messages and line numbers from hashes so nearby source edits do not split failure groups.
- Causal Chain & Dependency Graphs — walks
__cause__and unsuppressed__context__chains with cycle protection (generateanddependency_graph). - PII-Safe Normalization —
normalize(text)replaces numeric tokens with{NUMBER}and emails with{EMAIL}. - Knowledge Base Lookup —
lookup(id)andload_knowledge_base(source)mapBUGDNA-*IDs to owners, titles, and runbooks viabugdna.ymlorBUGDNA_KNOWLEDGE_PATH. - Fluent Test Assertions —
BugDnaAssertions.assert_that(fp)forpytestandunittest. - Similarity & Diffs —
compare_fingerprints(a, b)anddiff_exceptions(old_exc, new_exc). - Failure Tracking — thread-safe
FailureTrackerwith root-cause family clustering (families(),family_report()), bounded timelines, and per-minute burst detection (bursts()). - Batch & Consumer Tracking —
SkipReasonAnalyzerand topic/partition/offset-awareConsumerFailureTracker. - Deployment Regression & Drift Detection —
RegressionDetector.compare(old_snapshot, new_snapshot)anddetect_drift(old_fp, new_fp).