feat(aiguard): set manual.keep on root span after AI Guard evaluation#7758
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7758 +/- ##
=======================================
Coverage 80.43% 80.44%
=======================================
Files 741 741
Lines 32173 32178 +5
=======================================
+ Hits 25879 25884 +5
Misses 6294 6294
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Overall package sizeSelf size: 4.96 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.0 | 81.15 kB | 815.98 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
BenchmarksBenchmark execution time: 2026-03-13 12:51:44 Comparing candidate commit 82fb6d1 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 232 metrics, 28 unstable metrics. |
64e6fe4 to
78662ae
Compare
This comment has been minimized.
This comment has been minimized.
packages/dd-trace/src/aiguard/sdk.js
Outdated
| const rootSpan = span.context()._trace.started[0] | ||
| if (rootSpan) { | ||
| keepTrace(rootSpan, AI_GUARD) | ||
| span.context()._trace.tags[DECISION_MAKER_KEY] = `-${SAMPLING_MECHANISM_AI_GUARD}` |
There was a problem hiding this comment.
also are you sure you need htis anyway ? i don't see it being used anywhere else in the code ?
There was a problem hiding this comment.
Let me double check, during tests, an auto-keep was being set, and keepTrace was not overriding the decision maker because it was already set (to default, -0, apparentl). Going back to check this.
There was a problem hiding this comment.
Fixed. The problem here was that sampling was kicking in and setting AUTO_KEEP with decision maker -0. Then when calling keepTrace it would update the sampling decision to USER_KEEP but would not override the decision maker.
It turns out the reason sampling was being triggered so early is because just above I make an HTTP client call, which forces the sampling decision. Solved for the most part by just moving the keepTrace call above.
I think the keepTrace behavior is generally incorrect when this early sampling happens, but I'll bring that up with the guild as a follow up. For the purpose of this PR, and with the changed order, I was able to remove this hack.
5366d6e to
2780b68
Compare
Ensure AI Guard traces are always retained by setting USER_KEEP sampling priority with AI_GUARD mechanism (13) on the root span after successful evaluations, bypassing sampling rules. Co-Authored-By: Claude Opus 4.6 <[email protected]>
2780b68 to
82fb6d1
Compare
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
…#7758) feat(aiguard): set manual.keep on root span after AI Guard evaluation Ensure AI Guard traces are always retained by setting USER_KEEP sampling priority with AI_GUARD mechanism (13) on the root span after successful evaluations, bypassing sampling rules. Co-Authored-By: Claude Opus 4.6 <[email protected]> Co-authored-by: santiago.mola <[email protected]>
…#7758) feat(aiguard): set manual.keep on root span after AI Guard evaluation Ensure AI Guard traces are always retained by setting USER_KEEP sampling priority with AI_GUARD mechanism (13) on the root span after successful evaluations, bypassing sampling rules. Co-Authored-By: Claude Opus 4.6 <[email protected]> Co-authored-by: santiago.mola <[email protected]>
What does this PR do?
Ensure AI Guard traces are always retained by setting USER_KEEP sampling priority with AI_GUARD mechanism (13) on the root span after successful evaluations, bypassing sampling rules.
Motivation
Ensuring all AI Guard evaluations appear in the AI Guard UI (no sampling).
Additional Notes
Test_RootSpanUserKeep