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

refactor(debugging): make safety module internal #6810

Merged
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
2 changes: 1 addition & 1 deletion ddtrace/debugging/_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from bytecode import Compare
from bytecode import Instr

from ddtrace.debugging.safety import safe_getitem
from ddtrace.debugging._safety import safe_getitem
from ddtrace.internal.compat import PYTHON_VERSION_INFO as PY


Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions ddtrace/debugging/_signal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import six

from ddtrace.context import Context
from ddtrace.debugging import safety
from ddtrace.debugging import _safety
from ddtrace.debugging._expressions import DDExpressionEvaluationError
from ddtrace.debugging._probe.model import FunctionLocationMixin
from ddtrace.debugging._probe.model import LineLocationMixin
Expand Down Expand Up @@ -83,7 +83,7 @@ def _eval_condition(self, _locals=None):
return False

def _enrich_args(self, retval, exc_info, duration):
_locals = list(self.args or safety.get_args(self.frame))
_locals = list(self.args or _safety.get_args(self.frame))
_locals.append(("@duration", duration / 1e6)) # milliseconds
if exc_info[1] is None:
_locals.append(("@return", retval))
Expand Down
10 changes: 5 additions & 5 deletions ddtrace/debugging/_signal/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import attr

from ddtrace.debugging import safety
from ddtrace.debugging import _safety
from ddtrace.debugging._expressions import DDExpressionEvaluationError
from ddtrace.debugging._probe.model import CaptureLimits
from ddtrace.debugging._probe.model import DEFAULT_CAPTURE_LIMITS
Expand Down Expand Up @@ -144,7 +144,7 @@ def enter(self):

probe = self.probe
frame = self.frame
_args = list(self.args or safety.get_args(frame))
_args = list(self.args or _safety.get_args(frame))

if probe.evaluate_at == ProbeEvaluateTimingForMethod.EXIT:
return
Expand Down Expand Up @@ -190,7 +190,7 @@ def exit(self, retval, exc_info, duration):

if probe.take_snapshot:
self.return_capture = _capture_context(
self.args or safety.get_args(self.frame), _locals, exc_info, limits=probe.limits
self.args or _safety.get_args(self.frame), _locals, exc_info, limits=probe.limits
)
self.duration = duration
self.state = SignalState.DONE
Expand All @@ -213,8 +213,8 @@ def line(self):
return

self.line_capture = _capture_context(
self.args or safety.get_args(frame),
safety.get_locals(frame),
self.args or _safety.get_args(frame),
_safety.get_locals(frame),
sys.exc_info(),
limits=probe.limits,
)
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/debugging/_signal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ddtrace.debugging._probe.model import MAXLEN
from ddtrace.debugging._probe.model import MAXLEVEL
from ddtrace.debugging._probe.model import MAXSIZE
from ddtrace.debugging.safety import get_fields
from ddtrace.debugging._safety import get_fields
from ddtrace.internal.compat import BUILTIN_CONTAINER_TYPES
from ddtrace.internal.compat import BUILTIN_SIMPLE_TYPES
from ddtrace.internal.compat import CALLABLE_TYPES
Expand Down
14 changes: 7 additions & 7 deletions tests/debugging/test_safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

import pytest

from ddtrace.debugging import safety
from ddtrace.debugging import _safety


def test_get_args():
def assert_args(args):
assert set(dict(safety.get_args(inspect.currentframe().f_back)).keys()) == args
assert set(dict(_safety.get_args(inspect.currentframe().f_back)).keys()) == args

def assert_locals(_locals):
assert set(dict(safety.get_locals(inspect.currentframe().f_back)).keys()) == _locals
assert set(dict(_safety.get_locals(inspect.currentframe().f_back)).keys()) == _locals

def arg_and_kwargs(a, **kwargs):
assert_args({"a", "kwargs"})
Expand Down Expand Up @@ -55,7 +55,7 @@ def property_with_side_effect(self):


def test_get_fields_side_effects():
assert safety.get_fields(SideEffects()) == {}
assert _safety.get_fields(SideEffects()) == {}


# ---- Slots ----
Expand All @@ -75,8 +75,8 @@ def __init__(self):
super(B, self).__init__()
self.b = "b"

assert safety.get_fields(A()) == {"a": "a"}
assert safety.get_fields(B()) == {"a": "a", "b": "b"}
assert _safety.get_fields(A()) == {"a": "a"}
assert _safety.get_fields(B()) == {"a": "a", "b": "b"}


def test_safe_dict():
Expand All @@ -87,4 +87,4 @@ def __dict__(self):
raise NotImplementedError()

with pytest.raises(AttributeError):
safety._safe_dict(Foo())
_safety._safe_dict(Foo())