Skip to content

Commit

Permalink
Merge branch 'main' into avara1986/revert_modulo
Browse files Browse the repository at this point in the history
  • Loading branch information
avara1986 authored Dec 19, 2024
2 parents 5150ff9 + e9dbe4f commit bff2c0b
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 85 deletions.
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**'
13 changes: 9 additions & 4 deletions .gitlab/tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
stages:
- precheck
- hatch
- riot
- hatch

variables:
RIOT_RUN_CMD: riot -P -v run --exitfirst --pass-env -s
Expand Down Expand Up @@ -30,6 +30,9 @@ variables:
parallel: 4
# DEV: This is the max retries that GitLab currently allows for
retry: 2
before_script:
- !reference [.testrunner, before_script]
- pip install riot==0.20.1
script:
- export PYTEST_ADDOPTS="${PYTEST_ADDOPTS} --ddtrace"
- export _DD_CIVISIBILITY_USE_CI_CONTEXT_PROVIDER=true
Expand All @@ -51,7 +54,7 @@ variables:
services:
- !reference [.services, testagent]
before_script:
- !reference [.testrunner, before_script]
- !reference [.test_base_hatch, before_script]
# DEV: All job variables get shared with services, setting `DD_TRACE_AGENT_URL` on the testagent will tell it to forward all requests to the
# agent at that host. Therefore setting this as a variable will cause recursive requests to the testagent
- export DD_TRACE_AGENT_URL="http://testagent:9126"
Expand Down Expand Up @@ -88,12 +91,14 @@ build_base_venvs:
- !reference [.services, ddagent]
# DEV: This is the max retries that GitLab currently allows for
retry: 2
script:
before_script:
- !reference [.testrunner, before_script]
- pip install riot==0.20.1
- unset DD_SERVICE
- unset DD_ENV
- unset DD_TAGS
- unset DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED
script:
- |
hashes=( $(riot list --hash-only "${SUITE_NAME}" | sort | ./.gitlab/ci-split-input.sh) )
if [[ ${#hashes[@]} -eq 0 ]]; then
Expand All @@ -116,7 +121,7 @@ build_base_venvs:
- !reference [.test_base_riot, services]
- !reference [.services, testagent]
before_script:
- !reference [.testrunner, before_script]
- !reference [.test_base_riot, before_script]
# DEV: All job variables get shared with services, setting `DD_TRACE_AGENT_URL` on the testagent will tell it to forward all requests to the
# agent at that host. Therefore setting this as a variable will cause recursive requests to the testagent
- export DD_TRACE_AGENT_URL="http://testagent:9126"
Expand Down
41 changes: 41 additions & 0 deletions .riot/requirements/151d7b0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/151d7b0.in
#
amqp==2.6.1
attrs==24.3.0
cassandra-driver==3.29.2
certifi==2024.12.14
charset-normalizer==3.4.0
click==8.1.7
coverage[toml]==7.6.9
exceptiongroup==1.2.2
future==1.0.0
geomet==0.2.1.post1
hypothesis==6.45.0
idna==3.10
importlib-metadata==8.5.0
iniconfig==2.0.0
kombu==4.2.2.post1
mock==5.1.0
mysql-connector-python==9.1.0
opentracing==2.4.0
packaging==24.2
pluggy==1.5.0
psycopg2-binary==2.9.10
pytest==8.3.4
pytest-cov==6.0.0
pytest-mock==3.14.0
pytest-randomly==3.16.0
python-dateutil==2.9.0.post0
pytz==2024.2
requests==2.32.3
six==1.17.0
sortedcontainers==2.4.0
tomli==2.2.1
urllib3==2.2.3
vertica-python==0.6.14
vine==1.3.0
zipp==3.21.0
37 changes: 0 additions & 37 deletions .riot/requirements/1805689.txt

This file was deleted.

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
2 changes: 1 addition & 1 deletion hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ extra-dependencies = [
]

[envs.slotscheck.scripts]
_ = [
test = [
"python -m slotscheck -v ddtrace/",
]

Expand Down
1 change: 1 addition & 0 deletions riotfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
"vertica-python": ">=0.6.0,<0.7.0",
"kombu": ">=4.2.0,<4.3.0",
"pytest-randomly": latest,
"requests": latest,
},
),
Venv(
Expand Down
21 changes: 12 additions & 9 deletions scripts/gen_gitlab_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class JobSpec:
runner: str
pattern: t.Optional[str] = None
snapshot: bool = False
services: t.Optional[t.Set[str]] = None
services: t.Optional[t.List[str]] = None
env: t.Optional[t.Dict[str, str]] = None
parallelism: t.Optional[int] = None
retry: t.Optional[int] = None
Expand All @@ -32,16 +32,25 @@ def __str__(self) -> str:
lines.append(f"{self.name}:")
lines.append(f" extends: {base}")

if self.services:
services = set(self.services or [])
if services:
lines.append(" services:")

_services = [f"!reference [.services, {_}]" for _ in self.services]
_services = [f"!reference [.services, {_}]" for _ in services]
if self.snapshot:
_services.insert(0, f"!reference [{base}, services]")

for service in _services:
lines.append(f" - {service}")

wait_for: t.Set[str] = services.copy()
if self.snapshot:
wait_for.add("testagent")
if wait_for:
lines.append(" before_script:")
lines.append(f" - !reference [{base}, before_script]")
lines.append(f" - riot -v run -s --pass-env wait -- {' '.join(wait_for)}")

env = self.env
if not env or "SUITE_NAME" not in env:
env = env or {}
Expand Down Expand Up @@ -89,7 +98,6 @@ def gen_required_suites() -> None:
TESTS_GEN.write_text(
(GITLAB / "tests.yml").read_text().replace(r"{{services.yml}}", (GITLAB / "services.yml").read_text())
)

# Generate the list of suites to run
with TESTS_GEN.open("a") as f:
for suite in required_suites:
Expand Down Expand Up @@ -159,11 +167,6 @@ def check(name: str, command: str, paths: t.Set[str]) -> None:
command="hatch run meta-testing:meta-testing",
paths={"**conftest.py"},
)
check(
name="slotscheck",
command="hatch run slotscheck:_",
paths={"**.py"},
)


# -----------------------------------------------------------------------------
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
6 changes: 6 additions & 0 deletions tests/suitespec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ suites:
- tests/cache/*
runner: riot
snapshot: true
slotscheck:
parallelism: 1
paths:
- 'ddtrace/**/*.py'
runner: hatch
snapshot: false
profile:
env:
DD_TRACE_AGENT_URL: ''
Expand Down
Loading

0 comments on commit bff2c0b

Please sign in to comment.