Skip to content

Commit 2f66cd4

Browse files
committed
cleanup
1 parent e29c09d commit 2f66cd4

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

sentry_sdk/integrations/dedupe.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
get_error_message,
99
iter_stacks,
1010
)
11+
from sentry_sdk.tracing_utils import _should_be_included
1112
from sentry_sdk.integrations import Integration
1213
from sentry_sdk.scope import add_global_event_processor
1314

@@ -19,58 +20,65 @@
1920
from sentry_sdk._types import Event, Hint
2021

2122

23+
def _is_frame_in_app(tb_frame):
24+
# type: (Any) -> bool
25+
client = sentry_sdk.get_client()
26+
if not client.is_active():
27+
return True
28+
29+
in_app_include = client.options.get("in_app_include")
30+
in_app_exclude = client.options.get("in_app_exclude")
31+
project_root = client.options.get("project_root")
32+
33+
abs_path = tb_frame.tb_frame.f_code.co_filename
34+
namespace = tb_frame.tb_frame.f_globals.get("__name__")
35+
36+
return _should_be_included(
37+
is_sentry_sdk_frame=False,
38+
namespace=namespace,
39+
in_app_include=in_app_include,
40+
in_app_exclude=in_app_exclude,
41+
abs_path=abs_path,
42+
project_root=project_root,
43+
)
44+
45+
2246
def _create_exception_fingerprint(exc_info):
2347
# type: (Any) -> str
2448
"""
25-
Creates a unique fingerprint for an exception based on type, message, and traceback.
26-
27-
This replaces object identity comparison to prevent memory leaks while maintaining
28-
accurate deduplication for the same exception (same type+message+traceback).
29-
30-
Memory usage: 64 bytes (SHA256 hex string) for the last seen exception fingerprint.
49+
Creates a unique fingerprint for an exception based on type, message, and in-app traceback.
3150
"""
3251
exc_type, exc_value, tb = exc_info
3352

3453
if exc_type is None or exc_value is None:
3554
return ""
3655

37-
# Get exception type information
3856
type_module = get_type_module(exc_type) or ""
3957
type_name = get_type_name(exc_type) or ""
40-
41-
# Get exception message
4258
message = get_error_message(exc_value)
4359

44-
# Create traceback fingerprint from top frames (limit to avoid excessive memory usage)
4560
tb_parts = []
4661
frame_count = 0
47-
max_frames = 10 # Limit frames to keep memory usage low
4862

4963
for tb_frame in iter_stacks(tb):
50-
if frame_count >= max_frames:
51-
break
64+
if not _is_frame_in_app(tb_frame):
65+
continue
5266

53-
# Extract key frame information for fingerprint
54-
filename = tb_frame.tb_frame.f_code.co_filename or ""
67+
file_path = tb_frame.tb_frame.f_code.co_filename or ""
68+
file_name = file_path.split("/")[-1] if "/" in file_path else file_path
5569
function_name = tb_frame.tb_frame.f_code.co_name or ""
5670
line_number = str(tb_frame.tb_lineno)
57-
58-
# Create a compact frame fingerprint
5971
frame_fingerprint = "{}:{}:{}".format(
60-
(
61-
filename.split("/")[-1] if "/" in filename else filename
62-
), # Just filename, not full path
72+
file_name,
6373
function_name,
6474
line_number,
6575
)
6676
tb_parts.append(frame_fingerprint)
6777
frame_count += 1
6878

69-
# Combine all parts for the complete fingerprint
7079
fingerprint_parts = [type_module, type_name, message, "|".join(tb_parts)]
71-
72-
# Create SHA256 hash of the combined fingerprint
7380
fingerprint_data = "||".join(fingerprint_parts).encode("utf-8", errors="replace")
81+
7482
return hashlib.sha256(fingerprint_data).hexdigest()
7583

7684

0 commit comments

Comments
 (0)