Repository navigation
fix(telemetry): strip nested PII keys inside mapping and sequence attributes - #8772
yaosongding wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🔍 Devin Review: 1 flag
Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
1AbdullahButt
left a comment
There was a problem hiding this comment.
The fix is right. _serialize_session_options renames keyterms to lk.pii.keyterms inside session.options. On main, _contains_pii only looks at top-level keys, so the log processor skips the record and the terms are exported even with redaction on. I reproduced that on the base commit. Both new tests fail there and pass here, and test_telemetry_redaction.py, test_session_options_report.py and test_recording.py pass (245). I also checked non-str keys (kept), tuple vs list (type preserved), bytes (untouched), and dicts inside lists inside tuples (filtered).
One optional note on cost: _PIIFilteringSpanProcessor.on_end now walks every sequence attribute item by item. With 50 attributes of 100 ints each, _contains_pii went from about 32 µs to about 3 ms per call. Span attributes can only be primitives or flat sequences of primitives, so for spans that walk can never find anything. Recursing in _value_contains_pii (pii.py:95-96) only into items that are a Mapping or a non-str Sequence brought it down to about 0.7 ms with the same results. Skipping the value walk for spans entirely would remove the cost.
This is Gold, thanks for your test and great instruction, I'll update this PR! |
Summary
_serialize_session_options()aliasesstt_context_options["keyterms"]tolk.pii.keytermsinside the nestedsession.optionsdict so client-side PII filtering can strip customer keyterms when redaction is enabled, and_upload_session_report()emits the"session report"OTel log record withattributes={"session.options": _serialize_session_options(report.options), ...}.pii._contains_pii()andpii.filter_attributes()only inspected top-level attribute keys:_PIIFilteringLogProcessor.on_emit()skipped records whose top-level keys did not matchis_pii_attribute(), andfilter_attributes()shallow-copied nestedMappingandSequencevalues verbatim, leavinglk.pii.keytermsin exported OTLP log payloads even when redaction was enabled.is_pii_attribute,ATTR_EXCEPTION_TRACE,ATTR_EXCEPTION_MESSAGE) across nestedMappingand non-string/bytesSequenceattribute values while preservingtuplevslistcontainer types used by OpenTelemetryBoundedAttributes.Test plan
uv run pytest tests/test_telemetry_redaction.py tests/test_session_options_report.py tests/test_recording.py --unit(covers nestedMapping/Sequencefiltering and end-to-end_upload_session_report->LoggerProvider->_PIIFilteringLogProcessor-> OTLP protobufencode_logsredaction)uv run ruff checkanduv run ruff format --checkon touched filesuv run mypy -p livekit.agents