Skip to content

Commit 7c08584

Browse files
[dotnet] scrub empty static field (#7198)
Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Dudi Keleti <dudikeleti@users.noreply.github.com>
1 parent 16b5df0 commit 7c08584

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

manifests/dotnet.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ manifest:
622622
tests/debugger/test_debugger_exception_replay.py::Test_Debugger_Exception_Replay::test_exception_replay_multiframe:
623623
- declaration: bug (DEBUG-2799)
624624
component_version: <3.10.0
625+
- declaration: missing_feature (Static field guard is not released yet)
625626
tests/debugger/test_debugger_exception_replay.py::Test_Debugger_Exception_Replay::test_exception_replay_recursion_20:
626627
- declaration: bug (DEBUG-2799)
627628
component_version: <3.10.0

tests/debugger/test_debugger_exception_replay.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Test_Debugger_Exception_Replay(debugger.BaseDebuggerTest):
6363

6464
############ setup ############
6565
def _setup(self, request_path: str, exception_message: str):
66-
self.weblog_responses = []
66+
self.weblog_responses: list[object] = []
6767

6868
retries = 0
6969
timeout = _timeout_first
@@ -230,19 +230,42 @@ def __scrub_dotnet(key: str, value: dict | list | str, parent: dict): # noqa: A
230230
elif key == "StackTrace" and isinstance(value, dict):
231231
value["value"] = "<scrubbed>"
232232
return value
233+
elif key == "staticFields" and isinstance(value, dict):
234+
235+
def is_empty_result_static_field(field_name: str, field_value: object) -> bool:
236+
return (
237+
field_name == "Empty"
238+
and isinstance(field_value, dict)
239+
and field_value.get("type") == "EmptyResult"
240+
and set(field_value).issubset({"type", "notCapturedReason"})
241+
and field_value.get("notCapturedReason") in (None, "typeInitializer")
242+
)
243+
244+
scrubbed_static_fields = {
245+
field_name: __scrub(field_value)
246+
for field_name, field_value in value.items()
247+
if not is_empty_result_static_field(field_name, field_value)
248+
}
249+
return scrubbed_static_fields or None
233250
elif key == "function":
234251
assert isinstance(value, str)
235252
if "lambda_" in value:
236253
value = re.sub(r"(lambda_method)\d+", r"\1<scrubbed>", value)
237-
if re.search(r"<[^>]+>", value):
254+
if re.search(r"<[^>]+>", value) and not value.endswith("<scrubbed>"):
238255
value = re.sub(r"(.*>)(.*)", r"\1<scrubbed>", value)
239256
return value
240257
elif key in ["stacktrace", "stack"]:
241258
scrubbed = []
242259
assert isinstance(value, list)
243260
for entry in value:
261+
function = entry.get("function")
262+
if function is None:
263+
if entry != {"<runtime>": "<scrubbed>"}:
264+
scrubbed.append(__scrub(entry))
265+
continue
266+
244267
# skip inner runtime methods from stack traces since they are not relevant to debugger
245-
if entry["function"].startswith(("Microsoft", "System", "Unknown")):
268+
if function.startswith(("Microsoft", "System", "Unknown")):
246269
continue
247270

248271
scrubbed.append(__scrub(entry))
@@ -318,6 +341,8 @@ def __approve(snapshots: list):
318341
self._write_approval(snapshots, test_name, "snapshots_expected")
319342

320343
expected_snapshots = self._read_approval(test_name, "snapshots_expected")
344+
if self.get_tracer()["language"] == "dotnet" and not _SKIP_SCRUB:
345+
expected_snapshots = [__scrub_dict(snapshot) for snapshot in expected_snapshots] # type: ignore[assignment]
321346
if self.get_tracer()["language"] == "php":
322347
expected_snapshots = __normalize_php_fields(expected_snapshots) # type: ignore[assignment]
323348
assert expected_snapshots == snapshots
@@ -604,7 +629,7 @@ def test_exception_replay_inner(self):
604629

605630
############ Rock Paper Scissors ############
606631
def setup_exception_replay_rockpaperscissors(self):
607-
self.weblog_responses = []
632+
self.weblog_responses: list[object] = []
608633

609634
retries = 0
610635
timeout = _timeout_first

0 commit comments

Comments
 (0)