Skip to content

fix: Omit non-symbol context attributes and protect against cyclic values - #423

Draft
kinyoklion wants to merge 1 commit into
mainfrom
rlamb/context-filter-prune-unaddressable
Draft

fix: Omit non-symbol context attributes and protect against cyclic values#423
kinyoklion wants to merge 1 commit into
mainfrom
rlamb/context-filter-prune-unaddressable

Conversation

@kinyoklion

Copy link
Copy Markdown
Member

Summary

Attribute references store every path component as a symbol, so a context attribute with a non-symbol name (for example "street" => ... instead of street:) can never be addressed: it is invisible to evaluation and bucketing, and a private-attribute reference can never redact it. Today the event filter still copies such attributes into analytics event payloads, with one extra defect: a top-level string-keyed attribute is emitted with a null value, because the attribute name comes from raw storage but the value is fetched through get_value, which symbolizes the name and misses the entry.

This PR makes ContextFilter:

  • Omit attributes with non-symbol names, at the top level and at any nesting depth (including the whole subtree under a non-symbol key). Omitted attributes are not reported in _meta.redactedAttributes, since no reference removed them. This also removes the top-level null emission described above.
  • Log an error the first time a non-symbol name is dropped (once per filter instance, guarded by an AtomicBoolean since the formatter runs on flush workers), so the condition is discoverable without log spam.
  • Stop recursing into cyclic values. A self-referential hash in a context attribute previously crashed event serialization with SystemStackError. The filter now tracks the chain of hashes from the attribute root down each branch and omits a value that points back into its own chain. The same object appearing in different branches (a DAG) is still copied everywhere it appears.

Behavior change note: string-keyed attribute data that was previously sent in event payloads (intact when nested, null at top level) is now omitted.

Performance: same-process A/B against main on representative context shapes shows 0.99-1.05x on flat and redact-all paths and ~0.90x on deeply nested contexts (the cycle-protection chain costs one small array per nested hash).

Regression tests cover: top-level and nested omission, subtree omission, no redactedAttributes reporting for omitted names, composition with private-attribute redaction, log-once behavior, the previous SystemStackError on cycles, and DAG preservation. All new tests fail against the previous implementation.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant