Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(er): max frame setting #11851

Merged
merged 5 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 7 additions & 0 deletions ddtrace/settings/exception_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class ExceptionReplayConfig(En):
help="Enable automatic capturing of exception debugging information",
deprecations=[("debugging.enabled", None, "3.0")],
)
max_frames = En.v(
int,
"replay.capture_max_frames",
default=8,
help_type="int",
help="The maximum number of frames to capture for each exception",
)


config = ExceptionReplayConfig()
Expand Down
1 change: 1 addition & 0 deletions tests/telemetry/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ def test_app_started_event_configuration_override(test_agent_session, run_python
{"name": "DD_DYNAMIC_INSTRUMENTATION_UPLOAD_FLUSH_INTERVAL", "origin": "default", "value": 1.0},
{"name": "DD_DYNAMIC_INSTRUMENTATION_UPLOAD_TIMEOUT", "origin": "default", "value": 30},
{"name": "DD_ENV", "origin": "default", "value": None},
{"name": "DD_EXCEPTION_REPLAY_CAPTURE_MAX_FRAMES", "origin": "default", "value": 8},
{"name": "DD_EXCEPTION_REPLAY_ENABLED", "origin": "env_var", "value": True},
{"name": "DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED", "origin": "default", "value": False},
{"name": "DD_HTTP_CLIENT_TAG_QUERY_STRING", "origin": "default", "value": None},
Expand Down
Loading