Skip to content

Commit 71a389c

Browse files
committed
Verify errors intake crash messages
1 parent 888cd6d commit 71a389c

File tree

5 files changed

+103
-35
lines changed

5 files changed

+103
-35
lines changed

src/native/Cargo.lock

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/native/Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ profiling = ["dep:datadog-profiling-ffi"]
1616

1717
[dependencies]
1818
anyhow = { version = "1.0", optional = true }
19-
datadog-crashtracker = { git = "https://github.com/DataDog/libdatadog", rev = "f4c0bdfbd620cf4a627d852e8c31eda2b0057cd7", optional = true }
20-
datadog-ddsketch = { git = "https://github.com/DataDog/libdatadog", rev = "f4c0bdfbd620cf4a627d852e8c31eda2b0057cd7" }
21-
datadog-library-config = { git = "https://github.com/DataDog/libdatadog", rev = "f4c0bdfbd620cf4a627d852e8c31eda2b0057cd7" }
22-
datadog-log = { git = "https://github.com/DataDog/libdatadog", rev = "f4c0bdfbd620cf4a627d852e8c31eda2b0057cd7" }
23-
data-pipeline = { git = "https://github.com/DataDog/libdatadog", rev = "f4c0bdfbd620cf4a627d852e8c31eda2b0057cd7" }
24-
datadog-profiling-ffi = { git = "https://github.com/DataDog/libdatadog", rev = "f4c0bdfbd620cf4a627d852e8c31eda2b0057cd7", optional = true, features = [
19+
datadog-crashtracker = { git = "https://github.com/DataDog/libdatadog", rev = "309daec4ef976e3c74c684732aac0e6f18e5e1a4", optional = true }
20+
datadog-ddsketch = { git = "https://github.com/DataDog/libdatadog", rev = "309daec4ef976e3c74c684732aac0e6f18e5e1a4" }
21+
datadog-library-config = { git = "https://github.com/DataDog/libdatadog", rev = "309daec4ef976e3c74c684732aac0e6f18e5e1a4" }
22+
datadog-log = { git = "https://github.com/DataDog/libdatadog", rev = "309daec4ef976e3c74c684732aac0e6f18e5e1a4" }
23+
data-pipeline = { git = "https://github.com/DataDog/libdatadog", rev = "309daec4ef976e3c74c684732aac0e6f18e5e1a4" }
24+
datadog-profiling-ffi = { git = "https://github.com/DataDog/libdatadog", rev = "309daec4ef976e3c74c684732aac0e6f18e5e1a4", optional = true, features = [
2525
"cbindgen",
2626
] }
27-
ddcommon = { git = "https://github.com/DataDog/libdatadog", rev = "f4c0bdfbd620cf4a627d852e8c31eda2b0057cd7" }
27+
ddcommon = { git = "https://github.com/DataDog/libdatadog", rev = "309daec4ef976e3c74c684732aac0e6f18e5e1a4" }
2828
pyo3 = { version = "0.25", features = ["extension-module", "anyhow"] }
2929
tracing = { version = "0.1", default-features = false }
3030

3131
[build-dependencies]
3232
pyo3-build-config = "0.25"
33-
build_common = { git = "https://github.com/DataDog/libdatadog", rev = "f4c0bdfbd620cf4a627d852e8c31eda2b0057cd7", features = [
33+
build_common = { git = "https://github.com/DataDog/libdatadog", rev = "309daec4ef976e3c74c684732aac0e6f18e5e1a4", features = [
3434
"cbindgen",
3535
] }
3636

tests/internal/crashtracker/test_crashtracker.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ def test_crashtracker_upload_errors_intake():
743743
with utils.with_test_agent() as client:
744744
pid = os.fork()
745745
if pid == 0:
746-
ct = utils.CrashtrackerWrapper(base_name="tags_required")
746+
ct = utils.CrashtrackerWrapper(base_name="errors_intake_test")
747747
assert ct.start()
748748
stdout_msg, stderr_msg = ct.logs()
749749
assert not stdout_msg
@@ -752,11 +752,26 @@ def test_crashtracker_upload_errors_intake():
752752
ctypes.string_at(0)
753753
sys.exit(-1)
754754

755-
# Check for crash ping and report
756-
_crash_ping = utils.get_crash_ping(client)
757-
_crash_report = utils.get_crash_report(client)
758-
assert _crash_ping is not None, "Should have a crash ping"
759-
assert _crash_report is not None, "Should have a crash report"
760-
755+
# Check for telemetry crash ping and report
756+
_telemetry_crash_ping = utils.get_crash_ping(client)
757+
_telemetry_crash_report = utils.get_crash_report(client)
758+
assert _telemetry_crash_ping is not None, "Should have a telemetry crash ping"
759+
assert _telemetry_crash_report is not None, "Should have a telemetry crash report"
760+
# Verify that we have both telemetry and errors intake messages
761761
all_requests = client.requests()
762-
assert len(all_requests) == 4, f"Should have 4 total requests (2 telemetry, 2 errors intake) {all_requests}"
762+
763+
# Check for errors intake crash ping and report
764+
_errors_intake_crash_ping = utils.get_errors_intake_crash_ping(client)
765+
_errors_intake_crash_report = utils.get_errors_intake_crash_report(client)
766+
assert _errors_intake_crash_ping is not None, "Should have an errors intake crash ping"
767+
assert _errors_intake_crash_report is not None, "Should have an errors intake crash report"
768+
769+
telemetry_requests = client.crash_messages()
770+
errors_intake_requests = client.error_intake_messages()
771+
772+
assert len(
773+
telemetry_requests) == 2, f"Should have 2 telemetry crash messages (ping + report), got {len(telemetry_requests)}"
774+
assert len(
775+
errors_intake_requests) == 2, f"Should have 2 errors intake messages (ping + report), got {len(errors_intake_requests)}"
776+
assert len(
777+
all_requests) == 4, f"Should have 4 total requests (2 telemetry, 2 errors intake), got {len(all_requests)}"

tests/internal/crashtracker/utils.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,50 @@ def get_crash_ping(test_agent_client: TestAgentClient) -> TestAgentRequest:
174174
return crash_ping
175175

176176

177+
def get_errors_intake_crash_report(test_agent_client: TestAgentClient) -> TestAgentRequest:
178+
"""Wait for and retrieve a crash report from the errors intake endpoint."""
179+
for _ in range(5):
180+
errors_messages = test_agent_client.error_intake_messages()
181+
for message in errors_messages:
182+
body = message.get("body", b"")
183+
if isinstance(body, str):
184+
body = body.encode("utf-8")
185+
try:
186+
if isinstance(message.get("body"), bytes):
187+
data = json.loads(message["body"].decode("utf-8"))
188+
else:
189+
data = json.loads(message["body"])
190+
if "is_crash:true" in data.get("ddtags", ""):
191+
return message
192+
except (json.JSONDecodeError, KeyError, TypeError):
193+
continue
194+
time.sleep(0.2)
195+
196+
raise AssertionError("Could not find errors intake crash report with 'is_crash: true'")
197+
198+
199+
def get_errors_intake_crash_ping(test_agent_client: TestAgentClient) -> TestAgentRequest:
200+
"""Wait for and retrieve a crash ping from the errors intake endpoint."""
201+
for _ in range(5):
202+
errors_messages = test_agent_client.error_intake_messages()
203+
for message in errors_messages:
204+
body = message.get("body", b"")
205+
if isinstance(body, str):
206+
body = body.encode("utf-8")
207+
try:
208+
if isinstance(message.get("body"), bytes):
209+
data = json.loads(message["body"].decode("utf-8"))
210+
else:
211+
data = json.loads(message["body"])
212+
if "is_crash_ping:true" in data.get("ddtags", ""):
213+
return message
214+
except (json.JSONDecodeError, KeyError, TypeError):
215+
continue
216+
time.sleep(0.2)
217+
218+
raise AssertionError("Could not find errors intake crash ping with 'is_crash: false' and 'is_crash_ping:true' tag")
219+
220+
177221
@contextmanager
178222
def with_test_agent() -> Generator[TestAgentClient, None, None]:
179223
base_url = ddtrace.tracer.agent_trace_url or "http://localhost:9126" # default to local test agent

tests/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,15 @@ def crash_messages(self) -> List[TestAgentRequest]:
11801180
reqs.append(req)
11811181
return reqs
11821182

1183+
def error_intake_messages(self) -> List[TestAgentRequest]:
1184+
reqs = []
1185+
for req in self.requests():
1186+
# Filter requests to the errors intake endpoint
1187+
if req["url"].endswith("/evp_proxy/v4/api/v2/errorsintake"):
1188+
req["body"] = base64.b64decode(req["body"])
1189+
reqs.append(req)
1190+
return reqs
1191+
11831192
def clear(self) -> None:
11841193
status, body = self._request("GET", self._url("/test/session/clear"))
11851194
assert status == 200, (

0 commit comments

Comments
 (0)