Skip to content

feat(aiguard): apply backend extra_tags and extra_metastruct to AI Guard spans - #10865

Merged
avara1986 merged 6 commits into
masterfrom
avara/aiguard-extra-tags
Oct 29, 2026
Merged

avara1986 merged 6 commits into
masterfrom
avara/aiguard-extra-tags

Conversation

@avara1986

@avara1986 avara1986 commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Jira: APPSEC-70769 (epic APPSEC-70724)

The AI Guard evaluate response can now carry backend-provided span data in two optional attributes, each a list of { key, value } entries. This applies them to the ai_guard span:

What the backend sends today (the evaluation ID, as a span tag only):

"extra_tags": [{ "key": "ai_guard.evaluate_id", "value": "<same UUID as data.id>" }]

extra_metastruct is empty for now, but implemented so future structured values need no tracer release. Illustrative shape (examples only, not sent today):

"extra_metastruct": [
  { "key": "policy_match", "value": { "rule": "credit_card", "categories": ["pii", "financial"] } },
  { "key": "matched_rules", "value": [{ "id": "r1", "action": "DENY" }, { "id": "r2", "action": "ALLOW" }] },
  { "key": "policy_version", "value": "v3" }
]
  • extra_tags: each entry with a string value is set as a tag on the ai_guard span, under the key exactly as returned. Non-string values are skipped and never reach the meta_struct.
  • extra_metastruct: each entry with a non-null value (object, array or scalar) is added to the ai_guard meta_struct, under the key exactly as returned.
  • The tracer adds no ai_guard. prefix and does not filter by namespace: the backend owns it.
  • A repeated key keeps its last value.
  • Reserved keys are never overridden:
    • extra_tags (single isReservedExtraTag predicate): every tracer-internal _dd* key (_dd.*, _dd1.*, e.g. _dd.top_level, _dd.*_psr, _dd.p.*, which the span formatter writes before copying span tags), the tags the tracer computes itself (ai_guard.action, reason, target, tool_name, blocked, redacted, event, the HTTP/user entry tags), and keys with span-level side effects (manual.keep, manual.drop, sampling.priority, _sampling_priority_v1, service.name, resource.name, span.type, span.kind, error*, analytics.event, service.version, version, env, process_id, language, runtime-id). Reserving _dd* protects the tracer namespace; it is not an AI Guard namespace filter.
    • extra_metastruct: messages, attack_categories, sds, tag_probs.
  • Applied before the block decision, so the data lands on both allow and blocking paths.
  • Fail-safe: a field that is not a list, an entry that is not an object, or a missing, empty, non-string or __proto__ key is skipped with a debug log. The evaluation result and telemetry never change, and a missing or malformed field never becomes a bad response.

No public API change.

Motivation

Lets AI Guard policies attach their own context to traces without a tracer release per tag (APPSEC-69622); the first entry is the evaluation ID (ai_guard.evaluate_id, a span tag only), so the ai_guard span can be correlated with the backend evaluation.

The two fields are lists rather than maps because dotted keys such as ai_guard.evaluate_id are not valid JSON:API member names, and the default DataDog/jsonapi decoder would reject the response (see APPSEC-70724).

Additional Notes

  • Differences from Python #21252: Node.js also reserves every _dd* key and the span-control keys that span_format/span.setTag treat specially in dd-trace-js (sampling, top-level span fields, error flag, root/chunk metrics), and rejects __proto__ keys. Worth aligning the cross-tracer list in the RFC.
  • Known limitation: the msgpack meta_struct encoder (encode/0.4.js) drops booleans directly inside arrays and null values. The backend defines extra_metastruct, so it avoids those shapes, as it already avoids dotted keys inside structured values.
  • manifests/nodejs.yml in system-tests needs flipping from missing_feature once this ships.
  • Testing: mocha 'packages/dd-trace/test/aiguard/**/*.spec.js' 412 passing; npm run lint clean; no new tsc errors in src/aiguard.

🤖 Generated with Claude Code

The AI Guard evaluate response can carry an optional extra_tags object
(data.attributes.extra_tags), so policies can add context to AI Guard
spans without a tracer release per tag.

- Scalar values (string, finite number, boolean) are set as tags on the
  ai_guard span under the key exactly as returned; booleans as
  'true'/'false'.
- Objects and arrays are added to the ai_guard meta_struct.
- No prefix is added and keys are not filtered by namespace.
- Tracer-computed tags and meta_struct keys, and span-control keys
  (sampling, service, resource, type, error, version, env, ...), are
  never overridden.
- Applied before the block decision, so tags land on both allow and
  blocking paths.
- Malformed payloads are skipped with a debug log and never change the
  evaluation result or telemetry.

Jira: APPSEC-70769

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dd-octo-sts

dd-octo-sts Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 9.73 MB
Deduped: 10.48 MB
No deduping: 10.48 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.5.3 | 131.25 kB | 531.86 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🔄 Datadog retried 4 tests - 3 passed on retry View in Datadog

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 98.33% (+5.29%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 73fcee0 | Docs | View more details | Give us feedback!

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.97%. Comparing base (3ed563d) to head (73fcee0).
⚠️ Report is 23 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10865      +/-   ##
==========================================
+ Coverage   93.64%   98.97%   +5.33%     
==========================================
  Files        1068     1072       +4     
  Lines      175397   176070     +673     
  Branches       72       72              
==========================================
+ Hits       164252   174270   +10018     
+ Misses      11144     1799    -9345     
  Partials        1        1              
Flag Coverage Δ
ai-guard 63.75% <100.00%> (+0.08%) ⬆️
apm-capabilities 54.82% <62.93%> (+0.01%) ⬆️
apm-integrations 80.85% <ø> (?)
appsec 57.26% <ø> (-0.04%) ⬇️
debugger 70.83% <ø> (-0.08%) ⬇️
instrumentation 55.44% <ø> (-0.01%) ⬇️
llmobs 81.30% <ø> (-0.09%) ⬇️
master-coverage 98.97% <100.00%> (?)
openfeature 67.33% <ø> (-0.07%) ⬇️
platform 68.37% <ø> (-0.06%) ⬇️
profiling 65.86% <ø> (-0.07%) ⬇️
serverless 64.95% <ø> (+0.04%) ⬆️
test-optimization 82.05% <ø> (+0.04%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

@pr-commenter

pr-commenter Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-10-29 10:55:19

Comparing candidate commit 73fcee0 in PR branch avara/aiguard-extra-tags with baseline commit 3ed563d in branch master.

📊 Benchmarking dashboard

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

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-appsec-enabled-20

  • unstable max_rss_usage [-49.933MB; +52.110MB] or [-18.788%; +19.607%]

scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-20

  • unstable max_rss_usage [-26.572MB; +41.248MB] or [-7.641%; +11.861%]

scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-26

  • unstable max_rss_usage [-24.127MB; +21.454MB] or [-7.959%; +7.077%]

scenario:debugger-enabled-but-breakpoint-not-hit-20

  • unstable cpu_user_time [-758.814ms; +1145.816ms] or [-8.195%; +12.374%]
  • unstable execution_time [-758.943ms; +1146.240ms] or [-8.192%; +12.372%]
  • unstable throughput [-2840026.581op/s; +1906278.647op/s] or [-10.454%; +7.017%]

scenario:encoders-0.4-immediate-flush-20

  • unstable max_rss_usage [-12.800MB; +8.001MB] or [-15.045%; +9.404%]

scenario:openfeature-initialization-configuration-20

  • unstable max_rss_usage [-4020.451KB; +5533.178KB] or [-5.406%; +7.440%]

scenario:openfeature-scale-full-24

  • unstable max_rss_usage [-46.393MB; +18.707MB] or [-15.481%; +6.242%]

scenario:openfeature-scale-full-26

  • unstable max_rss_usage [-3.414MB; +32.789MB] or [-1.388%; +13.332%]

scenario:plugin-graphql-long-with-depth-and-collapse-off-24

  • unstable cpu_user_time [-520.653ms; +671.765ms] or [-5.225%; +6.741%]
  • unstable execution_time [-523.284ms; +679.093ms] or [-5.177%; +6.719%]
  • unstable throughput [-2.632op/s; +2.065op/s] or [-6.621%; +5.194%]

scenario:plugin-graphql-long-with-depth-off-26

  • unstable cpu_user_time [-388.609ms; +329.394ms] or [-5.485%; +4.649%]
  • unstable execution_time [-406.293ms; +337.653ms] or [-5.615%; +4.667%]
  • unstable max_rss_usage [-31.543MB; +20.359MB] or [-12.280%; +7.926%]
  • unstable throughput [-15.195op/s; +19.028op/s] or [-4.860%; +6.086%]

@avara1986

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@avara1986

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-29T10:39:28.604962Z 73fcee0 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: d9e068a195

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

avara1986 and others added 2 commits October 21, 2026 16:28
The span formatter writes root and chunk keys (_dd.top_level,
_dd.*_psr, _dd.p.*, _dd.tags.process) before copying span tags, so a
backend extra tag with the same key could overwrite them, and
_dd1.sr.eausr was writable directly.

Reserve the whole tracer-internal _dd namespace through a single
isReservedExtraTag predicate, plus the internal keys outside it
(_sampling_priority_v1, process_id, language, runtime-id). This is not
an AI Guard namespace filter: the backend still owns ai_guard.*.

Jira: APPSEC-70769

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@avara1986 avara1986 changed the title feat(aiguard): add backend-provided extra_tags to AI Guard spans feat(aiguard): apply backend extra_tags and extra_metastruct to AI Guard spans Oct 26, 2026
avara1986 and others added 2 commits October 27, 2026 12:22
The AI Guard evaluate response now carries backend-provided span data
in two attributes, each a list of { key, value } objects, because
dotted keys such as ai_guard.evaluate_id are not valid JSON:API member
names and the default decoder would reject the response.

- extra_tags: each entry with a string value is set as a tag on the
  ai_guard span under the key exactly as returned. Non-string values
  are skipped and never reach the meta_struct.
- extra_metastruct: each entry with a non-null value (object, array or
  scalar) is added to the ai_guard meta_struct under the key exactly
  as returned.
- A repeated key keeps its last value. A field that is not a list, or
  an entry that is not an object or has a missing, empty, non-string
  or __proto__ key, is skipped with a debug log.
- Reserved keys and the fail-safe guarantees are unchanged.

The backend sends the evaluation ID as ai_guard.evaluate_id in
extra_tags only; extra_metastruct is empty for now.

Jira: APPSEC-70769

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@avara1986
avara1986 marked this pull request as ready for review October 27, 2026 14:16
@avara1986
avara1986 requested a review from a team as a code owner October 27, 2026 14:16

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Reserved-key handling protects tracer-owned span controls, and malformed optional fields do not change evaluation validity. Runtime confidence is limited to isolated checks because the checkout lacks the dependencies needed for the full Mocha suite.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 28e0d15

@avara1986
avara1986 requested a review from CarlesDD October 28, 2026 10:27

@CarlesDD CarlesDD left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. one optional suggestion, not blocking

…sing the response

Parsing now owns the shape of both fields, like tags, sds_findings and
tag_probs: normalizeExtraEntries turns each into a list of { key, value }
entries, maps a non-list to an empty list and drops malformed entries,
so a malformed value never becomes a bad_response. Absent fields share
one frozen empty list.

applyExtraSpanData only applies the span policy: string tag values,
non-null meta_struct values and the reserved keys.

Jira: APPSEC-70769

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@avara1986

Copy link
Copy Markdown
Member Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-10-29 12:06:59 UTC ℹ️ Start processing command /merge


2026-10-29 12:07:03 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 0s (p90).


2026-10-29 12:26:36 UTC ❌ MergeQueue: The checks failed on this merge request

Tests failed on this commit ad90c0b:

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.

@avara1986

Copy link
Copy Markdown
Member Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-10-29 12:36:54 UTC ℹ️ Start processing command /merge


2026-10-29 12:36:58 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 0s (p90).


2026-10-29 12:52:29 UTC ❌ MergeQueue: The checks failed on this merge request

Tests failed on this commit 40a10a3:

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.

@avara1986

Copy link
Copy Markdown
Member Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-10-29 13:07:58 UTC ℹ️ Start processing command /merge


2026-10-29 13:08:02 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 0s (p90).


2026-10-29 13:21:25 UTC ❌ MergeQueue: The checks failed on this merge request

Tests failed on this commit c0f117e:

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.

@avara1986

Copy link
Copy Markdown
Member Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-10-29 13:33:19 UTC ℹ️ Start processing command /merge


2026-10-29 13:33:23 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 0s (p90).


2026-10-29 13:33:57 UTC ℹ️ MergeQueue: This merge request was already merged

This pull request was merged directly.

@avara1986
avara1986 merged commit 62d1094 into master Oct 29, 2026
967 of 972 checks passed
@avara1986
avara1986 deleted the avara/aiguard-extra-tags branch October 29, 2026 13:33
dd-octo-sts Bot pushed a commit that referenced this pull request Oct 29, 2026
…ard spans (#10865)

* feat(aiguard): add backend-provided extra_tags to AI Guard spans

The AI Guard evaluate response can carry an optional extra_tags object
(data.attributes.extra_tags), so policies can add context to AI Guard
spans without a tracer release per tag.

- Scalar values (string, finite number, boolean) are set as tags on the
  ai_guard span under the key exactly as returned; booleans as
  'true'/'false'.
- Objects and arrays are added to the ai_guard meta_struct.
- No prefix is added and keys are not filtered by namespace.
- Tracer-computed tags and meta_struct keys, and span-control keys
  (sampling, service, resource, type, error, version, env, ...), are
  never overridden.
- Applied before the block decision, so tags land on both allow and
  blocking paths.
- Malformed payloads are skipped with a debug log and never change the
  evaluation result or telemetry.

Jira: APPSEC-70769

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(aiguard): reserve tracer-internal keys from backend extra_tags

The span formatter writes root and chunk keys (_dd.top_level,
_dd.*_psr, _dd.p.*, _dd.tags.process) before copying span tags, so a
backend extra tag with the same key could overwrite them, and
_dd1.sr.eausr was writable directly.

Reserve the whole tracer-internal _dd namespace through a single
isReservedExtraTag predicate, plus the internal keys outside it
(_sampling_priority_v1, process_id, language, runtime-id). This is not
an AI Guard namespace filter: the backend still owns ai_guard.*.

Jira: APPSEC-70769

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(aiguard): read extra_tags and extra_metastruct as key/value lists

The AI Guard evaluate response now carries backend-provided span data
in two attributes, each a list of { key, value } objects, because
dotted keys such as ai_guard.evaluate_id are not valid JSON:API member
names and the default decoder would reject the response.

- extra_tags: each entry with a string value is set as a tag on the
  ai_guard span under the key exactly as returned. Non-string values
  are skipped and never reach the meta_struct.
- extra_metastruct: each entry with a non-null value (object, array or
  scalar) is added to the ai_guard meta_struct under the key exactly
  as returned.
- A repeated key keeps its last value. A field that is not a list, or
  an entry that is not an object or has a missing, empty, non-string
  or __proto__ key, is skipped with a debug log.
- Reserved keys and the fail-safe guarantees are unchanged.

The backend sends the evaluation ID as ai_guard.evaluate_id in
extra_tags only; extra_metastruct is empty for now.

Jira: APPSEC-70769

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(aiguard): normalize extra_tags and extra_metastruct when parsing the response

Parsing now owns the shape of both fields, like tags, sds_findings and
tag_probs: normalizeExtraEntries turns each into a list of { key, value }
entries, maps a non-list to an empty list and drops malformed entries,
so a malformed value never becomes a bad_response. Absent fields share
one frozen empty list.

applyExtraSpanData only applies the span policy: string tag values,
non-null meta_struct values and the reserved keys.

Jira: APPSEC-70769

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Oct 29, 2026
dd-octo-sts Bot pushed a commit that referenced this pull request Oct 29, 2026
…ard spans (#10865)

* feat(aiguard): add backend-provided extra_tags to AI Guard spans

The AI Guard evaluate response can carry an optional extra_tags object
(data.attributes.extra_tags), so policies can add context to AI Guard
spans without a tracer release per tag.

- Scalar values (string, finite number, boolean) are set as tags on the
  ai_guard span under the key exactly as returned; booleans as
  'true'/'false'.
- Objects and arrays are added to the ai_guard meta_struct.
- No prefix is added and keys are not filtered by namespace.
- Tracer-computed tags and meta_struct keys, and span-control keys
  (sampling, service, resource, type, error, version, env, ...), are
  never overridden.
- Applied before the block decision, so tags land on both allow and
  blocking paths.
- Malformed payloads are skipped with a debug log and never change the
  evaluation result or telemetry.

Jira: APPSEC-70769

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(aiguard): reserve tracer-internal keys from backend extra_tags

The span formatter writes root and chunk keys (_dd.top_level,
_dd.*_psr, _dd.p.*, _dd.tags.process) before copying span tags, so a
backend extra tag with the same key could overwrite them, and
_dd1.sr.eausr was writable directly.

Reserve the whole tracer-internal _dd namespace through a single
isReservedExtraTag predicate, plus the internal keys outside it
(_sampling_priority_v1, process_id, language, runtime-id). This is not
an AI Guard namespace filter: the backend still owns ai_guard.*.

Jira: APPSEC-70769

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(aiguard): read extra_tags and extra_metastruct as key/value lists

The AI Guard evaluate response now carries backend-provided span data
in two attributes, each a list of { key, value } objects, because
dotted keys such as ai_guard.evaluate_id are not valid JSON:API member
names and the default decoder would reject the response.

- extra_tags: each entry with a string value is set as a tag on the
  ai_guard span under the key exactly as returned. Non-string values
  are skipped and never reach the meta_struct.
- extra_metastruct: each entry with a non-null value (object, array or
  scalar) is added to the ai_guard meta_struct under the key exactly
  as returned.
- A repeated key keeps its last value. A field that is not a list, or
  an entry that is not an object or has a missing, empty, non-string
  or __proto__ key, is skipped with a debug log.
- Reserved keys and the fail-safe guarantees are unchanged.

The backend sends the evaluation ID as ai_guard.evaluate_id in
extra_tags only; extra_metastruct is empty for now.

Jira: APPSEC-70769

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(aiguard): normalize extra_tags and extra_metastruct when parsing the response

Parsing now owns the shape of both fields, like tags, sds_findings and
tag_probs: normalizeExtraEntries turns each into a list of { key, value }
entries, maps a non-list to an empty list and drops malformed entries,
so a malformed value never becomes a bad_response. Absent fields share
one frozen empty list.

applyExtraSpanData only applies the span policy: string tag values,
non-null meta_struct values and the reserved keys.

Jira: APPSEC-70769

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants