Skip to content

feat: added span redaction#2295

Open
poshinchen wants to merge 7 commits into
strands-agents:mainfrom
poshinchen:feat/add-span-redaction
Open

feat: added span redaction#2295
poshinchen wants to merge 7 commits into
strands-agents:mainfrom
poshinchen:feat/add-span-redaction

Conversation

@poshinchen
Copy link
Copy Markdown
Contributor

Description

Related Issues

Documentation PR

Type of Change

Bug fix
New feature
Breaking change
Documentation update
Other (please describe):

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

poshinchen and others added 7 commits May 14, 2026 13:28
Adds a `gen_ai_unredacted_attributes=<list>` token to OTEL_SEMCONV_STABILITY_OPT_IN
that lets operators allow-list which sensitive GenAI span attributes (user messages,
model output, tool input/output, system instructions) are emitted unredacted; everything
else collapses to "<Redacted>". Supports exact names and trailing-`*` glob prefixes.
Behavior is off by default to preserve backward compatibility (issue strands-agents#1292).
…y events

In `_add_event_messages`, assistant messages were redacted under the
`gen_ai.input.messages` policy key, so an allowlist targeting
`gen_ai.output.*` could not unredact assistant content emitted via the
legacy per-message events. Route the lookup by message role and document
the canonical-name convention used in `_redact`.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Tool results are fed back into the model as input, so their redaction
should be governed by the gen_ai.input.messages policy key, matching
how tool results are policied in start_tool_call_span. The emitted
event attribute key (tool.result, gen_ai.output.messages) is unchanged.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…n cycle span

Emit tool_result_message under gen_ai.input.messages (not gen_ai.output.messages)
in end_event_loop_cycle_span so the emitted attribute name matches the redaction
policy key, making allowlist behavior predictable for OTEL consumers.

Also adds a co-located comment in _add_system_prompt_event and a regression test
that locks in the attribute-key / policy-key alignment for tool result events.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nd harden tests

Rename the misleading local variable in end_event_loop_cycle_span from
output_messages to tool_result_messages to reflect that tool results are
fed back to the model as input under gen_ai.input.messages.

Add the system-prompt sensitivity comment to the legacy else branch of
_add_system_prompt_event for symmetry with the latest-conventions branch.

Strengthen the negative assertion in test_tool_result_cycle_span_uses_input_messages_key
to use a comprehension over all attribute keys, and add
test_legacy_tool_result_redacts_under_input_messages_policy to cover the
legacy gen_ai.choice path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ed token at the call site

The parser was widened to return tuple[set[str], dict[str, str]] so that
gen_ai_unredacted_attributes could be looked up as a key/value mapping. The
only call site that uses the dict view is the redaction setup itself, and
the bare-key enrichment of the flag set was unused dead weight that also
made "gen_ai_unredacted_attributes" in opt_in_values surprisingly true even
when no bare token was present.

Restore the original set[str] return and find the unredacted token with a
single next() over the existing set. Behavior of _redact and the public
class API are unchanged; the 94-test telemetry suite still passes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant