|
| 1 | +--- |
| 2 | +title: PII Selectors |
| 3 | +--- |
| 4 | + |
| 5 | +Selectors allow you to restrict rules to certain parts of the event. This is |
| 6 | +useful to unconditionally remove certain data by variable/field name from the |
| 7 | +event, but can also be used to conservatively test rules on real data. |
| 8 | + |
| 9 | +Data scrubbing always works on the raw event payload. Keep in mind that some |
| 10 | +fields in the UI may be called differently in the JSON schema. When looking at |
| 11 | +an event there should always be a link called "JSON" present that allows you to |
| 12 | +see what the data scrubber sees. |
| 13 | + |
| 14 | +For example, what is called "Additional Data" in the UI is called `extra` in the |
| 15 | +event payload. To remove a specific key called `foo`, you would write: |
| 16 | + |
| 17 | +``` |
| 18 | +[Remove] [Anything] from [extra.foo] |
| 19 | +``` |
| 20 | + |
| 21 | +Another example. Sentry knows about two kinds of error messages: The exception |
| 22 | +message, and the top-level log message. Here is an example of how such an event |
| 23 | +payload as sent by the SDK (and downloadable from the UI) would look like: |
| 24 | + |
| 25 | +```json |
| 26 | +{ |
| 27 | + "logentry": { |
| 28 | + "formatted": "Failed to roll out the dinglebop" |
| 29 | + }, |
| 30 | + "exceptions": { |
| 31 | + "values": [ |
| 32 | + { |
| 33 | + "type": "ZeroDivisionError", |
| 34 | + "value": "integer division or modulo by zero" |
| 35 | + } |
| 36 | + ] |
| 37 | + } |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +Since the "error message" is taken from the `exception`'s `value`, and the |
| 42 | +"message" is taken from `logentry`, we would have to write the following to |
| 43 | +remove both from the event: |
| 44 | + |
| 45 | +``` |
| 46 | +[Remove] [Anything] from [exception.value] |
| 47 | +[Remove] [Anything] from [logentry.formatted] |
| 48 | +``` |
| 49 | + |
| 50 | +### Boolean Logic |
| 51 | + |
| 52 | +You can combine selectors using boolean logic. |
| 53 | + |
| 54 | +- Prefix with `!` to invert the selector. `foo` matches the JSON key `foo`, |
| 55 | + while `!foo` matches everything but `foo`. |
| 56 | +- Build the conjunction (AND) using `&&`, such as: `foo && !extra.foo` to match |
| 57 | + the key `foo` except when inside of `extra`. |
| 58 | +- Build the disjunction (OR) using `||`, such as: `foo || bar` to match `foo` or |
| 59 | + `bar`. |
| 60 | + |
| 61 | +### Wildcards |
| 62 | + |
| 63 | +- `**` matches all subpaths, so that `foo.**` matches all JSON keys within |
| 64 | + `foo`. |
| 65 | +- `*` matches a single path item, so that `foo.*` matches all JSON keys one |
| 66 | + level below `foo`. |
| 67 | + |
| 68 | +### Value Types |
| 69 | + |
| 70 | +Select subsections by JSON-type using the following: |
| 71 | + |
| 72 | +- `$string` matches any string value |
| 73 | +- `$number` matches any integer or float value |
| 74 | +- `$datetime` matches any field in the event that represents a timestamp |
| 75 | +- `$array` matches any JSON array value |
| 76 | +- `$object` matches any JSON object |
| 77 | + |
| 78 | +Select known parts of the schema using the following: |
| 79 | + |
| 80 | +- `$exception` matches a single exception instance in `{"exception": {"values": [...]}}` |
| 81 | +- `$stacktrace` matches a stack trace instance |
| 82 | +- `$frame` matches a frame |
| 83 | +- `$request` matches the HTTP request context of an event |
| 84 | +- `$user` matches the user context of an event |
| 85 | +- `$logentry` (also applies to the `message` attribute) |
| 86 | +- `$thread` matches a single thread instance in `{"threads": {"values": [...]}}` |
| 87 | +- `$breadcrumb` matches a single breadcrumb in `{"breadcrumbs": [...]}` |
| 88 | +- `$span` matches a [trace span] |
| 89 | +- `$sdk` matches the SDK context in `{"sdk": ...}` |
| 90 | + |
| 91 | +#### Examples |
| 92 | + |
| 93 | +- Delete `event.user`: |
| 94 | + |
| 95 | + ``` |
| 96 | + [Remove] [Anything] from [$user] |
| 97 | + ``` |
| 98 | + |
| 99 | +- Delete all frame-local variables: |
| 100 | + |
| 101 | + ``` |
| 102 | + [Remove] [Anything] from [$frame.vars] |
| 103 | + ``` |
| 104 | + |
| 105 | +### Escaping Specal Characters |
| 106 | + |
| 107 | +If the object key you want to match contains whitespace or special characters, |
| 108 | +you can use quotes to escape it: |
| 109 | + |
| 110 | +``` |
| 111 | +[Remove] [Anything] from [extra.'my special value'] |
| 112 | +``` |
| 113 | + |
| 114 | +This matches the key `my special value` in _Additional Data_. |
| 115 | + |
| 116 | +To escape `'` (single quote) within the quotes, replace it with `''` (two |
| 117 | +quotes): |
| 118 | + |
| 119 | +``` |
| 120 | +[Remove] [Anything] from [extra.'my special '' value'] |
| 121 | +``` |
| 122 | + |
| 123 | +This matches the key `my special ' value` in _Additional Data_. |
| 124 | + |
| 125 | +[trace span]: https://docs.sentry.io/product/performance/distributed-tracing/#spans |
0 commit comments