-
Notifications
You must be signed in to change notification settings - Fork 15
Add Test_AnomalyDetectionTags for AI Guard span enrichment #6784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -493,6 +493,82 @@ def test_sds_in_response(self): | |
| assert _assert_key(location, "path") | ||
|
|
||
|
|
||
| @rfc("https://datadoghq.atlassian.net/wiki/x/KIApiQE") | ||
| @features.ai_guard | ||
| @scenarios.ai_guard | ||
| class Test_AnomalyDetectionTags: | ||
| """Test that anomaly detection attributes are propagated from the root span into every AI Guard span.""" | ||
|
|
||
| PUBLIC_IP = "5.6.7.9" | ||
| USER_ID = "u12345" | ||
| SESSION_ID = "s12345" | ||
|
|
||
| def _assert_span(self, root_span: DataDogLibrarySpan): | ||
| def validate(span: DataDogLibrarySpan): | ||
| if span["resource"] != "ai_guard": | ||
| return False | ||
|
|
||
| meta = span["meta"] | ||
|
|
||
| # Tags copied from the root span must be present on every AI Guard span | ||
| _assert_key(meta, "ai_guard.http.client_ip") | ||
| _assert_key(meta, "ai_guard.network.client.ip") | ||
| _assert_key(meta, "ai_guard.http.useragent") | ||
| _assert_key(meta, "ai_guard.usr.id", self.USER_ID) | ||
| _assert_key(meta, "ai_guard.session.id", self.SESSION_ID) | ||
|
|
||
| # Values must match what is on the root span | ||
| root_meta = root_span["meta"] | ||
| assert meta["ai_guard.http.client_ip"] == root_meta.get("http.client_ip"), ( | ||
| f"ai_guard.http.client_ip mismatch: {meta['ai_guard.http.client_ip']} != {root_meta.get('http.client_ip')}" | ||
| ) | ||
| assert meta["ai_guard.network.client.ip"] == root_meta.get("network.client.ip"), ( | ||
| f"ai_guard.network.client.ip mismatch: {meta['ai_guard.network.client.ip']} != {root_meta.get('network.client.ip')}" | ||
| ) | ||
| assert meta["ai_guard.http.useragent"] == root_meta.get("http.useragent"), ( | ||
| f"ai_guard.http.useragent mismatch: {meta['ai_guard.http.useragent']} != {root_meta.get('http.useragent')}" | ||
| ) | ||
| assert meta["ai_guard.usr.id"] == root_meta.get("usr.id"), ( | ||
| f"ai_guard.usr.id mismatch: {meta['ai_guard.usr.id']} != {root_meta.get('usr.id')}" | ||
| ) | ||
| assert meta["ai_guard.session.id"] == root_meta.get("session.id"), ( | ||
| f"ai_guard.session.id mismatch: {meta['ai_guard.session.id']} != {root_meta.get('session.id')}" | ||
| ) | ||
|
|
||
| return True | ||
|
|
||
| return validate | ||
|
|
||
| def setup_anomaly_detection_tags(self): | ||
| self.r = weblog.post( | ||
| "/ai_guard/evaluate", | ||
| headers={ | ||
| "X-Forwarded-For": self.PUBLIC_IP, | ||
| "X-User-Id": self.USER_ID, | ||
| "X-Session-Id": self.SESSION_ID, | ||
| }, | ||
| json=MESSAGES["ALLOW"], | ||
| ) | ||
|
|
||
| def test_anomaly_detection_tags(self): | ||
| """Test that AI Guard spans carry anomaly detection attributes copied from the root span. | ||
|
|
||
| Verifies that http.client_ip, network.client.ip, http.useragent, usr.id and session.id | ||
| are all present on the AI Guard span with the ai_guard. prefix, and that their values | ||
| match the corresponding tags on the local root span. | ||
| """ | ||
| assert self.r.status_code == 200 | ||
|
|
||
| root_span = interfaces.library.get_root_span(self.r) | ||
| assert root_span, "No root span found" | ||
|
|
||
| interfaces.library.validate_one_span( | ||
| self.r, | ||
| validator=self._assert_span(root_span=root_span), | ||
| full_trace=True, | ||
| ) | ||
|
Comment on lines
+565
to
+569
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new test claims to verify propagation to every Useful? React with 👍 / 👎. |
||
|
|
||
|
|
||
| @features.ai_guard | ||
| @scenarios.ai_guard | ||
| class Test_AIGuardEvent_Tag: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.