Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-latest-mako-version
Browse files Browse the repository at this point in the history
  • Loading branch information
emmettbutler authored Dec 19, 2024
2 parents 1183446 + 315a48f commit 4e45735
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/system-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ jobs:
if: always() && steps.docker_load.outcome == 'success' && matrix.scenario == 'appsec-1'
run: ./run.sh IAST_STANDALONE

- name: Run SCA_STANDALONE
if: always() && steps.docker_load.outcome == 'success' && matrix.scenario == 'appsec-1'
run: ./run.sh SCA_STANDALONE

- name: Run APPSEC_RUNTIME_ACTIVATION
if: always() && steps.docker_load.outcome == 'success' && matrix.scenario == 'appsec-1'
run: ./run.sh APPSEC_RUNTIME_ACTIVATION
Expand Down
3 changes: 1 addition & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ check_new_flaky_tests:
stage: quality-gate
extends: .testrunner
script:
- curl -L --fail "https://github.com/DataDog/datadog-ci/releases/latest/download/datadog-ci_linux-x64" --output "/usr/local/bin/datadog-ci" && chmod +x /usr/local/bin/datadog-ci
- export DD_SITE=datadoghq.com
- export DD_API_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.${CI_PROJECT_NAME}.dd-api-key-qualitygate --with-decryption --query "Parameter.Value" --out text)
- export DD_APP_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.${CI_PROJECT_NAME}.dd-app-key-qualitygate --with-decryption --query "Parameter.Value" --out text)
- datadog-ci gate evaluate
except:
- main
- '[0-9].[0-9]*'
- 'mq-working-branch**'
- 'mq-working-branch**'
12 changes: 7 additions & 5 deletions ddtrace/debugging/_exception/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
CAPTURE_TRACE_TAG = "_dd.debug.error.trace_captured"

# unique exception id
EXCEPTION_ID_TAG = "_dd.debug.error.exception_id"
EXCEPTION_HASH_TAG = "_dd.debug.error.exception_hash"
EXCEPTION_ID_TAG = "_dd.debug.error.exception_capture_id"

# link to matching snapshot for every frame in the traceback
FRAME_SNAPSHOT_ID_TAG = "_dd.debug.error.%d.snapshot_id"
Expand Down Expand Up @@ -80,9 +81,8 @@ def exception_chain_ident(chain: ExceptionChain) -> int:
return h


def limit_exception(chain: ExceptionChain) -> bool:
def limit_exception(exc_ident: int) -> bool:
try:
exc_ident = exception_chain_ident(chain)
hg = EXCEPTION_IDENT_LIMITER.get(exc_ident)
if hg is None:
# We haven't seen this exception yet, or it's been evicted
Expand Down Expand Up @@ -170,7 +170,7 @@ class SpanExceptionSnapshot(Snapshot):
@property
def data(self) -> t.Dict[str, t.Any]:
data = super().data
data.update({"exception-id": str(self.exc_id)})
data.update({"exceptionId": str(self.exc_id)})
return data


Expand Down Expand Up @@ -218,7 +218,8 @@ def on_span_exception(
# No exceptions to capture
return

if limit_exception(chain):
exc_ident = exception_chain_ident(chain)
if limit_exception(exc_ident):
# We have seen this exception recently
return

Expand Down Expand Up @@ -272,6 +273,7 @@ def on_span_exception(
_tb = _tb.tb_next

span.set_tag_str(DEBUG_INFO_TAG, "true")
span.set_tag_str(EXCEPTION_HASH_TAG, str(exc_ident))
span.set_tag_str(EXCEPTION_ID_TAG, str(exc_id))

@classmethod
Expand Down
9 changes: 9 additions & 0 deletions ddtrace/debugging/_signal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@ def capture_value(
}

fields = get_fields(value)

# Capture exception chain for exceptions
if _isinstance(value, BaseException):
for attr in ("args", "__cause__", "__context__", "__suppress_context__"):
try:
fields[attr] = object.__getattribute__(value, attr)
except AttributeError:
pass

captured_fields = {
n: (
capture_value(v, level=level - 1, maxlen=maxlen, maxsize=maxsize, maxfields=maxfields, stopping_cond=cond)
Expand Down
4 changes: 2 additions & 2 deletions tests/debugging/exception/test_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def b_chain(bar):
m = 4
try:
a(bar % m)
except ValueError:
raise KeyError("chain it")
except ValueError as exc:
raise KeyError("chain it") from exc

def c(foo=42):
with self.trace("c"):
Expand Down
20 changes: 19 additions & 1 deletion tests/debugging/test_debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,25 @@ def test_debugger_function_probe_on_function_with_exception():

return_capture = snapshot_data["captures"]["return"]
assert return_capture["arguments"] == {}
assert return_capture["locals"] == {"@exception": {"fields": {}, "type": "Exception"}}
assert return_capture["locals"] == {
"@exception": {
"type": "Exception",
"fields": {
"args": {
"type": "tuple",
"elements": [
{"type": "str", "value": "'Hello'"},
{"type": "str", "value": "'world!'"},
{"type": "int", "value": "42"},
],
"size": 3,
},
"__cause__": {"type": "NoneType", "isNull": True},
"__context__": {"type": "NoneType", "isNull": True},
"__suppress_context__": {"type": "bool", "value": "False"},
},
}
}
assert return_capture["throwable"]["message"] == "'Hello', 'world!', 42"
assert return_capture["throwable"]["type"] == "Exception"

Expand Down
16 changes: 15 additions & 1 deletion tests/debugging/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,21 @@ def _():

exc = context.pop("throwable")
assert context["arguments"] == {}
assert context["locals"] == {"@exception": {"type": "Exception", "fields": {}}}
assert context["locals"] == {
"@exception": {
"type": "Exception",
"fields": {
"args": {
"type": "tuple",
"elements": [{"type": "str", "value": "'test'"}, {"type": "str", "value": "'me'"}],
"size": 2,
},
"__cause__": {"type": "NoneType", "isNull": True},
"__context__": {"type": "NoneType", "isNull": True},
"__suppress_context__": {"type": "bool", "value": "False"},
},
}
}
assert exc["message"] == "'test', 'me'"
assert exc["type"] == "Exception"

Expand Down

0 comments on commit 4e45735

Please sign in to comment.