Skip to content

feat(aiguard): set manual.keep on root span after AI Guard evaluation#7758

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit intomasterfrom
smola/ai-guard-manual-keep
Mar 13, 2026
Merged

feat(aiguard): set manual.keep on root span after AI Guard evaluation#7758
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit intomasterfrom
smola/ai-guard-manual-keep

Conversation

@smola
Copy link
Copy Markdown
Member

@smola smola commented Mar 12, 2026

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

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.44%. Comparing base (63a867a) to head (82fb6d1).
⚠️ Report is 8 commits behind head on master.

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           
Flag Coverage Δ
aiguard-macos 39.09% <100.00%> (+0.15%) ⬆️
aiguard-ubuntu 39.21% <100.00%> (+0.15%) ⬆️
aiguard-windows 38.94% <100.00%> (+0.15%) ⬆️
apm-capabilities-tracing-macos 48.89% <50.00%> (-0.01%) ⬇️
apm-capabilities-tracing-ubuntu 48.93% <50.00%> (-0.01%) ⬇️
apm-capabilities-tracing-windows 48.62% <50.00%> (-0.05%) ⬇️
apm-integrations-child-process 38.39% <100.00%> (-0.10%) ⬇️
apm-integrations-couchbase-18 37.31% <100.00%> (-0.10%) ⬇️
apm-integrations-couchbase-eol 37.78% <100.00%> (-0.10%) ⬇️
apm-integrations-oracledb 37.62% <100.00%> (-0.10%) ⬇️
appsec-express 55.20% <100.00%> (-0.07%) ⬇️
appsec-fastify 51.54% <100.00%> (-0.07%) ⬇️
appsec-graphql 51.74% <100.00%> (-0.06%) ⬇️
appsec-kafka 44.27% <100.00%> (-0.08%) ⬇️
appsec-ldapjs 43.93% <100.00%> (-0.08%) ⬇️
appsec-lodash 43.59% <100.00%> (-0.08%) ⬇️
appsec-macos 58.21% <100.00%> (-0.07%) ⬇️
appsec-mongodb-core 48.70% <100.00%> (+0.03%) ⬆️
appsec-mongoose 49.37% <100.00%> (-0.07%) ⬇️
appsec-mysql 50.90% <100.00%> (+0.03%) ⬆️
appsec-node-serialize 43.11% <100.00%> (-0.08%) ⬇️
appsec-passport 47.55% <100.00%> (-0.09%) ⬇️
appsec-postgres 50.52% <100.00%> (-0.09%) ⬇️
appsec-sourcing 42.51% <100.00%> (-0.08%) ⬇️
appsec-template 43.27% <100.00%> (-0.08%) ⬇️
appsec-ubuntu 58.29% <100.00%> (-0.07%) ⬇️
appsec-windows 58.07% <100.00%> (-0.07%) ⬇️
instrumentations-instrumentation-bluebird 32.26% <100.00%> (-0.10%) ⬇️
instrumentations-instrumentation-body-parser 40.41% <100.00%> (-0.09%) ⬇️
instrumentations-instrumentation-child_process 37.71% <100.00%> (-0.10%) ⬇️
instrumentations-instrumentation-cookie-parser 34.24% <100.00%> (-0.09%) ⬇️
instrumentations-instrumentation-express 34.56% <100.00%> (-0.09%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.37% <100.00%> (-0.09%) ⬇️
instrumentations-instrumentation-express-session 40.05% <100.00%> (-0.09%) ⬇️
instrumentations-instrumentation-fs 31.88% <100.00%> (-0.10%) ⬇️
instrumentations-instrumentation-generic-pool 29.69% <ø> (ø)
instrumentations-instrumentation-http 39.69% <100.00%> (-0.10%) ⬇️
instrumentations-instrumentation-knex 32.27% <100.00%> (-0.10%) ⬇️
instrumentations-instrumentation-mongoose 33.39% <100.00%> (-0.10%) ⬇️
instrumentations-instrumentation-multer 40.16% <100.00%> (-0.09%) ⬇️
instrumentations-instrumentation-mysql2 38.17% <100.00%> (-0.10%) ⬇️
instrumentations-instrumentation-passport 43.97% <100.00%> (-0.09%) ⬇️
instrumentations-instrumentation-passport-http 43.64% <100.00%> (-0.09%) ⬇️
instrumentations-instrumentation-passport-local 44.17% <100.00%> (-0.09%) ⬇️
instrumentations-instrumentation-pg 37.60% <100.00%> (-0.10%) ⬇️
instrumentations-instrumentation-promise 32.19% <100.00%> (-0.10%) ⬇️
instrumentations-instrumentation-promise-js 32.20% <100.00%> (-0.10%) ⬇️
instrumentations-instrumentation-q 32.24% <100.00%> (-0.10%) ⬇️
instrumentations-instrumentation-url 32.17% <100.00%> (-0.10%) ⬇️
instrumentations-instrumentation-when 32.21% <100.00%> (-0.10%) ⬇️
llmobs-ai 42.15% <100.00%> (-0.09%) ⬇️
llmobs-anthropic 40.14% <100.00%> (-0.09%) ⬇️
llmobs-bedrock 39.13% <100.00%> (-0.08%) ⬇️
llmobs-google-genai 39.69% <100.00%> (-0.09%) ⬇️
llmobs-langchain 39.93% <100.00%> (-0.08%) ⬇️
llmobs-openai 43.87% <100.00%> (-0.09%) ⬇️
llmobs-vertex-ai 39.94% <100.00%> (-0.09%) ⬇️
platform-core 31.53% <ø> (ø)
platform-esbuild 34.48% <ø> (ø)
platform-instrumentations-misc 48.40% <ø> (ø)
platform-shimmer 37.63% <ø> (ø)
platform-unit-guardrails 32.95% <ø> (ø)
plugins-azure-event-hubs 25.83% <ø> (ø)
plugins-azure-service-bus 25.19% <ø> (ø)
plugins-bullmq 44.20% <100.00%> (-0.01%) ⬇️
plugins-cassandra 37.66% <100.00%> (-0.10%) ⬇️
plugins-cookie 26.89% <ø> (ø)
plugins-cookie-parser 26.67% <ø> (ø)
plugins-crypto 26.79% <ø> (ø)
plugins-dd-trace-api 38.22% <100.00%> (-0.10%) ⬇️
plugins-express-mongo-sanitize 26.82% <ø> (ø)
plugins-express-session 26.63% <ø> (ø)
plugins-fastify 42.13% <100.00%> (-0.09%) ⬇️
plugins-fetch 38.22% <100.00%> (-0.09%) ⬇️
plugins-fs 38.49% <100.00%> (-0.10%) ⬇️
plugins-generic-pool 25.87% <ø> (ø)
plugins-google-cloud-pubsub 45.34% <100.00%> (-0.09%) ⬇️
plugins-grpc 40.81% <100.00%> (-0.09%) ⬇️
plugins-handlebars 26.86% <ø> (ø)
plugins-hapi 40.04% <100.00%> (-0.10%) ⬇️
plugins-hono 40.30% <100.00%> (-0.10%) ⬇️
plugins-ioredis 38.30% <100.00%> (-0.10%) ⬇️
plugins-knex 26.50% <ø> (ø)
plugins-ldapjs 24.36% <ø> (ø)
plugins-light-my-request 26.23% <ø> (ø)
plugins-limitd-client 32.54% <100.00%> (-0.10%) ⬇️
plugins-lodash 25.96% <ø> (ø)
plugins-mariadb 39.40% <100.00%> (-0.05%) ⬇️
plugins-memcached 38.03% <100.00%> (-0.10%) ⬇️
plugins-microgateway-core 39.11% <100.00%> (-0.10%) ⬇️
plugins-moleculer 40.40% <100.00%> (-0.09%) ⬇️
plugins-mongodb 39.05% <100.00%> (-0.10%) ⬇️
plugins-mongodb-core 38.88% <100.00%> (-0.10%) ⬇️
plugins-mongoose 38.74% <100.00%> (-0.10%) ⬇️
plugins-multer 26.63% <ø> (ø)
plugins-mysql 39.04% <100.00%> (-0.10%) ⬇️
plugins-mysql2 39.14% <100.00%> (-0.10%) ⬇️
plugins-node-serialize 26.93% <ø> (ø)
plugins-opensearch 37.49% <100.00%> (-0.10%) ⬇️
plugins-passport-http 26.68% <ø> (ø)
plugins-postgres 35.53% <100.00%> (-0.09%) ⬇️
plugins-process 26.79% <ø> (ø)
plugins-pug 26.89% <ø> (ø)
plugins-redis 38.77% <100.00%> (-0.10%) ⬇️
plugins-router 42.99% <100.00%> (+0.04%) ⬆️
plugins-sequelize 25.47% <ø> (ø)
plugins-test-and-upstream-amqp10 38.38% <100.00%> (-0.10%) ⬇️
plugins-test-and-upstream-amqplib 43.76% <100.00%> (-0.10%) ⬇️
plugins-test-and-upstream-apollo 39.01% <100.00%> (-0.09%) ⬇️
plugins-test-and-upstream-avsc 38.55% <100.00%> (-0.10%) ⬇️
plugins-test-and-upstream-bunyan 33.80% <100.00%> (-0.10%) ⬇️
plugins-test-and-upstream-connect 40.70% <100.00%> (-0.10%) ⬇️
plugins-test-and-upstream-graphql 40.00% <100.00%> (-0.10%) ⬇️
plugins-test-and-upstream-koa 40.29% <100.00%> (-0.10%) ⬇️
plugins-test-and-upstream-protobufjs 38.78% <100.00%> (-0.10%) ⬇️
plugins-test-and-upstream-rhea 43.94% <100.00%> (-0.10%) ⬇️
plugins-undici 38.99% <100.00%> (-0.09%) ⬇️
plugins-url 26.79% <ø> (ø)
plugins-valkey 37.97% <100.00%> (-0.10%) ⬇️
plugins-vm 26.79% <ø> (ø)
plugins-winston 33.99% <100.00%> (-0.10%) ⬇️
plugins-ws 41.76% <100.00%> (-0.10%) ⬇️
profiling-macos 39.80% <100.00%> (-0.10%) ⬇️
profiling-ubuntu 39.92% <100.00%> (-0.10%) ⬇️
profiling-windows 41.51% <100.00%> (+0.30%) ⬆️
serverless-azure-functions-client 25.54% <ø> (ø)
serverless-azure-functions-eventhubs 25.54% <ø> (ø)
serverless-azure-functions-servicebus 25.54% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 12, 2026

Overall package size

Self size: 4.96 MB
Deduped: 5.81 MB
No deduping: 5.81 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

@smola smola added semver-minor ai-generated PR created with AI assistance labels Mar 12, 2026
@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Mar 12, 2026

Benchmarks

Benchmark execution time: 2026-03-13 12:51:44

Comparing candidate commit 82fb6d1 in PR branch smola/ai-guard-manual-keep with baseline commit 63a867a in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 232 metrics, 28 unstable metrics.

@smola smola force-pushed the smola/ai-guard-manual-keep branch from 64e6fe4 to 78662ae Compare March 12, 2026 11:23
@datadog-datadog-prod-us1

This comment has been minimized.

@smola smola marked this pull request as ready for review March 13, 2026 10:07
@smola smola requested a review from a team as a code owner March 13, 2026 10:07
const rootSpan = span.context()._trace.started[0]
if (rootSpan) {
keepTrace(rootSpan, AI_GUARD)
span.context()._trace.tags[DECISION_MAKER_KEY] = `-${SAMPLING_MECHANISM_AI_GUARD}`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also are you sure you need htis anyway ? i don't see it being used anywhere else in the code ?

Copy link
Copy Markdown
Member Author

@smola smola Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@smola smola force-pushed the smola/ai-guard-manual-keep branch from 5366d6e to 2780b68 Compare March 13, 2026 11:48
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]>
@smola smola force-pushed the smola/ai-guard-manual-keep branch from 2780b68 to 82fb6d1 Compare March 13, 2026 12:35
@smola smola requested a review from simon-id March 13, 2026 13:08
@smola
Copy link
Copy Markdown
Member Author

smola commented Mar 13, 2026

/merge

@gh-worker-devflow-routing-ef8351
Copy link
Copy Markdown

gh-worker-devflow-routing-ef8351 bot commented Mar 13, 2026

View all feedbacks in Devflow UI.

2026-03-13 14:14:15 UTC ℹ️ Start processing command /merge


2026-03-13 14:14:20 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 23m (p90).


2026-03-13 14:35:58 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d bot merged commit c9ba145 into master Mar 13, 2026
790 checks passed
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d bot deleted the smola/ai-guard-manual-keep branch March 13, 2026 14:35
dd-octo-sts bot pushed a commit that referenced this pull request Mar 14, 2026
…#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]>
@dd-octo-sts dd-octo-sts bot mentioned this pull request Mar 14, 2026
CarlesDD pushed a commit that referenced this pull request Mar 16, 2026
…#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated PR created with AI assistance semver-minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants