Skip to content

Commit cd30b23

Browse files
committed
implements #7362
1 parent 152c51c commit cd30b23

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/common-library/src/common_library/error_codes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ def _create_timestamp() -> int:
5151
ts = datetime.now(UTC).timestamp() * _SECS_TO_MILISECS
5252
return int(ts)
5353

54+
_LEN = 12 # chars (~48 bits)
55+
56+
57+
def _generate_error_fingerprint(exc: BaseException) -> str:
58+
"""
59+
Unique error fingerprint for deduplication purposes
60+
"""
61+
tb = traceback.extract_tb(exc.__traceback__)
62+
frame_sigs = [f"{frame.name}:{frame.lineno}" for frame in tb]
63+
fingerprint = f"{type(exc).__name__}|" + "|".join(frame_sigs)
64+
# E.g. ZeroDivisionError|foo:23|main:10
65+
return hashlib.sha256(fingerprint.encode()).hexdigest()[:_LEN]
66+
5467

5568
def create_error_code(exception: BaseException) -> ErrorCodeStr:
5669
"""

0 commit comments

Comments
 (0)