Skip to content

Conversation

@loewenheim
Copy link
Contributor

@loewenheim loewenheim commented Sep 1, 2025

This adds the ability to "dynamically" define PII to metastructure. It works like this: if compute_pii is a function fn(&ProcessingState) -> Pii, you can annotate a container or field with #[metastructure(pii = "compute_pii")] (in addition to the existing values of "true", "false", and "maybe") which will cause the PII value of the field/container to depend on the current ProcessingState. See the new test_dynamic_pii test for a simple example of this feature in action.

The intended use of this is to allow the PII status of AttributeValue::value to be fetched from relay-conventions based on the attribute's name.

ref: #5096. ref: RELAY-152.

This adds the ability to "dynamically" define PII to `metastructure`. It
works like this: if `compute_pii` is a function
`fn(&ProcessingState) -> Pii`, you can annotate a container or field
with `#[metastructure(pii = "compute_pii")]` (in addition to the
existing values of `"true"`, `"false"`, and `"maybe"`) which will cause
the PII value of the field/container to depend on the current
`ProcessingState`. See the new `test_dynamic_pii` test for a simple
example of this feature in action.

The intended use of this is to allow the PII status  of
`AttributeValue::value` to be fetched from `relay-conventions` based on
the attribute's name.
@loewenheim loewenheim requested a review from a team as a code owner September 1, 2025 14:55
@linear
Copy link

linear bot commented Sep 1, 2025

PiiExtended::Static(Pii::True) => Some(Cow::Borrowed(&PII_TRUE_FIELD_ATTRS)),
PiiExtended::Static(Pii::False) => None,
PiiExtended::Static(Pii::Maybe) => Some(Cow::Borrowed(&PII_MAYBE_FIELD_ATTRS)),
PiiExtended::Dynamic(_) => None,
Copy link
Member

Choose a reason for hiding this comment

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

Is this safe? I would have expected FieldAttrs::pii to also be of type PiiExtended and to be derived for dynamic fields as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would have expected FieldAttrs::pii to also be of type PiiExtended

Sorry, I don't follow. It is of that type. This function controls how field attributes are passed from a field to its children (currently, Pii::True and Pii::Maybe are inherited, but Pii::False isn't; I'm not actually sure how much sense that makes). I decided to make it so the function to dynamically compute the PII value should not be inherited by child fields because the child field would get passed a different state, so the same function wouldn't necessarily make sense.

But since this is a function on ProcessingState, we can actually realize the dynamic PII value and pass that to the child fields, which I think is a lot more natural.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I don't follow. It is of that type.

My bad.

I decided to make it so the function to dynamically compute the PII value should not be inherited by child fields because the child field would get passed a different state, so the same function wouldn't necessarily make sense.

Makes sense!

Copy link
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

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

Nice! It will be interesting to see if this works on deeply nested real-world types, but IMO we can just merge this and see about that in the next PR.

@loewenheim loewenheim added this pull request to the merge queue Sep 2, 2025
Merged via the queue into master with commit c87fa86 Sep 2, 2025
28 checks passed
@loewenheim loewenheim deleted the sebastian/derive-pii-conventions branch September 2, 2025 09:02
loewenheim added a commit that referenced this pull request Sep 3, 2025
This implements fetching PII information from `relay-conventions` for
attributes, using the dynamic machinery introduced in #5107.
Unfortunately, in the `AttributeMode::ValueOnly` case (i.e.
default/legacy rules), we have to do some state manipulation and can't
rely on the derived machinery.

ref: #5096. ref: RELAY-152.
loewenheim added a commit that referenced this pull request Sep 3, 2025
This implements fetching PII information from `relay-conventions` for
attributes, using the dynamic machinery introduced in #5107.
Unfortunately, in the `AttributeMode::ValueOnly` case (i.e.
default/legacy rules), we have to do some state manipulation and can't
rely on the derived machinery.

ref: #5096. ref: RELAY-152.
github-merge-queue bot pushed a commit that referenced this pull request Sep 9, 2025
This implements fetching PII information from `relay-conventions` for
attributes, using the dynamic machinery introduced in #5107.
Unfortunately, in the `AttributeMode::ValueOnly` case (i.e.
default/legacy rules), we have to do some state manipulation and can't
rely on the derived machinery.

Also, this PR reverts the dependency between `relay-conventions` and
`relay-event-schema` (now `event-schema` depends on `conventions`),
which means that `conventions` now has its own `Pii` type since it can't
use the one from `event-schema` anymore.

ref: #5096. ref: RELAY-152.
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.

3 participants