Skip to content

Commit

Permalink
chore: exception replay max frame setting
Browse files Browse the repository at this point in the history
We add the setting option to specifiy the maximum number of frames to
capture while collecting exception replay data. By default this is
infinite.
  • Loading branch information
P403n1x87 committed Jan 3, 2025
1 parent 6bfe77e commit e5e0419
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ddtrace/debugging/_exception/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ddtrace.internal.rate_limiter import BudgetRateLimiterWithJitter as RateLimiter
from ddtrace.internal.rate_limiter import RateLimitExceeded
from ddtrace.internal.utils.time import HourGlass
from ddtrace.settings.exception_replay import config


log = get_logger(__name__)
Expand Down Expand Up @@ -225,15 +226,17 @@ def on_span_exception(

seq = count(1) # 1-based sequence number

while chain:
frames_captured = 0

while chain and frames_captured <= config.max_frames:
exc, _tb = chain.pop() # LIFO: reverse the chain

if _tb is None or _tb.tb_frame is None:
# If we don't have a traceback there isn't much we can do
continue

# DEV: We go from the handler up to the root exception
while _tb:
while _tb and frames_captured <= config.max_frames:
frame = _tb.tb_frame
code = frame.f_code
seq_nr = next(seq)
Expand Down Expand Up @@ -263,6 +266,9 @@ def on_span_exception(
# Memoize
frame.f_locals[SNAPSHOT_KEY] = snapshot_id = snapshot.uuid

# Count
frames_captured += 1

# Add correlation tags on the span
span.set_tag_str(FRAME_SNAPSHOT_ID_TAG % seq_nr, snapshot_id)
span.set_tag_str(FRAME_FUNCTION_TAG % seq_nr, code.co_name)
Expand Down
6 changes: 6 additions & 0 deletions ddtrace/settings/exception_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class ExceptionReplayConfig(En):
help="Enable automatic capturing of exception debugging information",
deprecations=[("debugging.enabled", None, "3.0")],
)
max_frames = En.v(
"replay.capture_max_frames",
default=float("inf"),
help_type="int",
help="The maximum number of frames to capture for each exception",
)


config = ExceptionReplayConfig()
Expand Down

0 comments on commit e5e0419

Please sign in to comment.