Skip to content

Commit 895fe41

Browse files
committed
chore: exception replay max frame setting
We add the setting option to specifiy the maximum number of frames to capture while collecting exception replay data. By default this is infinite.
1 parent 6bfe77e commit 895fe41

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

ddtrace/debugging/_exception/replay.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from ddtrace.internal.rate_limiter import BudgetRateLimiterWithJitter as RateLimiter
2222
from ddtrace.internal.rate_limiter import RateLimitExceeded
2323
from ddtrace.internal.utils.time import HourGlass
24+
from ddtrace.settings.exception_replay import config
2425

2526

2627
log = get_logger(__name__)
@@ -225,15 +226,17 @@ def on_span_exception(
225226

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

228-
while chain:
229+
frames_captured = 0
230+
231+
while chain and frames_captured <= config.max_frames:
229232
exc, _tb = chain.pop() # LIFO: reverse the chain
230233

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

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

269+
# Count
270+
frames_captured += 1
271+
266272
# Add correlation tags on the span
267273
span.set_tag_str(FRAME_SNAPSHOT_ID_TAG % seq_nr, snapshot_id)
268274
span.set_tag_str(FRAME_FUNCTION_TAG % seq_nr, code.co_name)

ddtrace/settings/exception_replay.py

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ class ExceptionReplayConfig(En):
1414
help="Enable automatic capturing of exception debugging information",
1515
deprecations=[("debugging.enabled", None, "3.0")],
1616
)
17+
max_frames = En.v(
18+
int,
19+
"replay.capture_max_frames",
20+
default=float("inf"),
21+
help_type="int",
22+
help="The maximum number of frames to capture for each exception",
23+
)
1724

1825

1926
config = ExceptionReplayConfig()

0 commit comments

Comments
 (0)