Skip to content

Commit 0ab3ebe

Browse files
committed
feat(er): Ensure APM_MULTICONFIG compat works
1 parent b9dd55c commit 0ab3ebe

File tree

3 files changed

+78
-22
lines changed

3 files changed

+78
-22
lines changed

tests/debugger/test_debugger_inproduct_enablement.py

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import tests.debugger.utils as debugger
66
from utils import features, scenarios, missing_feature, context, logger
77
import json
8+
import time
89

910
TIMEOUT = 5
1011

@@ -67,43 +68,46 @@ class Test_Debugger_InProduct_Enablement_Exception_Replay(debugger.BaseDebuggerT
6768
############ exception replay ############
6869
_max_retries = 2
6970

70-
def setup_inproduct_enablement_exception_replay(self):
71-
def _send_config(enabled=None):
72-
self.send_rc_apm_tracing(exception_replay_enabled=enabled)
71+
def _send_config(self, enabled=None, service_name="weblog", env="system-tests"):
72+
self.send_rc_apm_tracing(exception_replay_enabled=enabled, service_name=service_name, env=env)
7373

74-
def _wait_for_exception_snapshot_received(request_path, exception_message):
75-
self.weblog_responses = []
74+
def _wait_for_exception_snapshot_received(self, request_path, exception_message):
75+
self.weblog_responses = []
7676

77-
retries = 0
78-
snapshot_found = False
77+
retries = 0
78+
snapshot_found = False
7979

80-
while not snapshot_found and retries < self._max_retries:
81-
logger.debug(f"Waiting for snapshot, retry #{retries}")
80+
while not snapshot_found and retries < self._max_retries:
81+
logger.debug(f"Waiting for snapshot, retry #{retries}")
8282

83-
self.send_weblog_request(request_path, reset=False)
84-
snapshot_found = self.wait_for_exception_snapshot_received(exception_message, TIMEOUT)
83+
self.send_weblog_request(request_path, reset=False)
84+
snapshot_found = self.wait_for_exception_snapshot_received(exception_message, TIMEOUT)
8585

86-
retries += 1
86+
retries += 1
8787

88-
return snapshot_found
88+
return snapshot_found
8989

90+
def setup_inproduct_enablement_exception_replay(self):
91+
self.start_time = int(time.time() * 1000)
9092
self.initialize_weblog_remote_config()
9193
self.weblog_responses = []
9294

93-
self.er_initial_enabled = not _wait_for_exception_snapshot_received(
95+
self.er_initial_enabled = not self._wait_for_exception_snapshot_received(
9496
"/exceptionreplay/simple", "simple exception"
9597
)
9698

97-
_send_config(enabled=True)
98-
self.er_explicit_enabled = _wait_for_exception_snapshot_received("/exceptionreplay/simple", "simple exception")
99+
self._send_config(enabled=True)
100+
self.er_explicit_enabled = self._wait_for_exception_snapshot_received(
101+
"/exceptionreplay/simple", "simple exception"
102+
)
99103

100-
_send_config()
101-
self.er_empty_config = _wait_for_exception_snapshot_received(
104+
self._send_config()
105+
self.er_empty_config = self._wait_for_exception_snapshot_received(
102106
"/exceptionreplay/recursion?depth=1", "recursion exception depth 1"
103107
)
104108

105-
_send_config(enabled=False)
106-
self.er_explicit_disabled = not _wait_for_exception_snapshot_received(
109+
self._send_config(enabled=False)
110+
self.er_explicit_disabled = not self._wait_for_exception_snapshot_received(
107111
"/exceptionreplay/multiframe", "multiple stack frames exception"
108112
)
109113

@@ -116,6 +120,42 @@ def test_inproduct_enablement_exception_replay(self):
116120
assert self.er_empty_config, "Expected snapshots to continue emitting with empty config"
117121
assert self.er_explicit_disabled, "Expected snapshots to stop emitting after explicit disable"
118122

123+
def setup_inproduct_enablement_exception_replay_apm_multiconfig(self):
124+
self.start_time = int(time.time() * 1000)
125+
self.initialize_weblog_remote_config()
126+
self.weblog_responses = []
127+
128+
self._send_config(enabled=False, service_name="*", env="*")
129+
self.er_initial_enabled = not self._wait_for_exception_snapshot_received(
130+
"/exceptionreplay/simple", "simple exception"
131+
)
132+
133+
self._send_config(enabled=True, service_name="*", env="*")
134+
self.er_apm_multiconfig_enabled = self._wait_for_exception_snapshot_received(
135+
"/exceptionreplay/simple", "simple exception"
136+
)
137+
138+
self._send_config(enabled=False, service_name="weblog", env="system-tests")
139+
self.er_disabled_by_service_name = not self._wait_for_exception_snapshot_received(
140+
"/exceptionreplay/recursion?depth=1", "recursion exception depth 1"
141+
)
142+
143+
self._send_config(enabled=True, service_name="*", env="*")
144+
self.er_apm_multiconfig_enabled_2 = not self._wait_for_exception_snapshot_received(
145+
"/exceptionreplay/multiframe", "multiple stack frames exception"
146+
)
147+
148+
@missing_feature(context.library == "python", force_skip=True)
149+
@missing_feature(context.library == "java", force_skip=True)
150+
def test_inproduct_enablement_exception_replay_apm_multiconfig(self):
151+
self.assert_rc_state_not_error()
152+
self.assert_all_weblog_responses_ok(expected_code=500)
153+
154+
assert self.er_initial_enabled, "Expected snapshots to not be emitting when exception replay was disabled"
155+
assert self.er_apm_multiconfig_enabled, "Expected snapshots to be emitting after enabling exception replay"
156+
assert self.er_disabled_by_service_name, "Expected snapshots to stop emitting after service name override"
157+
assert self.er_apm_multiconfig_enabled_2, "Expected snapshots to not be emitting after service name override"
158+
119159

120160
@features.debugger_inproduct_enablement
121161
@scenarios.debugger_inproduct_enablement

tests/debugger/utils.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class BaseDebuggerTest:
8080
all_spans: list = []
8181
symbols: list = []
8282

83+
start_time: int | None = None
84+
8385
rc_states: list[remote_config.RemoteConfigStateResults] = []
8486
weblog_responses: list = []
8587

@@ -212,6 +214,8 @@ def send_rc_apm_tracing(
212214
live_debugging_enabled: bool | None = None,
213215
code_origin_enabled: bool | None = None,
214216
dynamic_sampling_enabled: bool | None = None,
217+
service_name: str | None = "weblog",
218+
env: str | None = "system-tests",
215219
*,
216220
reset: bool = True,
217221
) -> None:
@@ -228,6 +232,8 @@ def send_rc_apm_tracing(
228232
code_origin_enabled=code_origin_enabled,
229233
dynamic_sampling_enabled=dynamic_sampling_enabled,
230234
version=BaseDebuggerTest._rc_version,
235+
service_name=service_name,
236+
env=env,
231237
)
232238
)
233239

@@ -315,14 +321,17 @@ def _wait_for_snapshot_received(self, data: dict):
315321
contents = data["request"].get("content", []) or []
316322

317323
for content in contents:
324+
# Filter out snapshots from before the test start time for multiple tests using the same file.
325+
if "timestamp" in content and self.start_time is not None:
326+
if content["timestamp"] < self.start_time:
327+
continue
328+
318329
snapshot = content.get("debugger", {}).get("snapshot") or content.get("debugger.snapshot")
319330

320331
if not snapshot or "probe" not in snapshot:
321-
logger.debug("Snapshot doesn't have pobe")
322332
continue
323333

324334
if "exceptionId" not in snapshot:
325-
logger.debug("Snapshot doesnt't have exception")
326335
continue
327336

328337
exception_message = self.get_exception_message(snapshot)

utils/_remote_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ def build_apm_tracing_command(
265265
live_debugging_enabled: bool | None = None,
266266
code_origin_enabled: bool | None = None,
267267
dynamic_sampling_enabled: bool | None = None,
268+
service_name: str | None = "weblog",
269+
env: str | None = "system-tests",
268270
):
269271
lib_config: dict[str, str | bool] = {
270272
"library_language": "all",
@@ -287,6 +289,7 @@ def build_apm_tracing_command(
287289
"schema_version": "v1.0.0",
288290
"action": "enable",
289291
"lib_config": lib_config,
292+
"service_target": {"service": service_name, "env": env},
290293
}
291294

292295
path_payloads = {"datadog/2/APM_TRACING/config_overrides/config": config}
@@ -299,6 +302,8 @@ def send_apm_tracing_command(
299302
live_debugging_enabled: bool | None = None,
300303
code_origin_enabled: bool | None = None,
301304
dynamic_sampling_enabled: bool | None = None,
305+
service_name: str | None = "weblog",
306+
env: str | None = "system-tests",
302307
version: int = 1,
303308
) -> RemoteConfigStateResults:
304309
raw_payload = build_apm_tracing_command(
@@ -308,6 +313,8 @@ def send_apm_tracing_command(
308313
live_debugging_enabled=live_debugging_enabled,
309314
code_origin_enabled=code_origin_enabled,
310315
dynamic_sampling_enabled=dynamic_sampling_enabled,
316+
service_name=service_name,
317+
env=env,
311318
)
312319

313320
return send_state(raw_payload)

0 commit comments

Comments
 (0)