PII masking is the practice of removing, replacing, hashing or truncating personally identifiable information such as names, email addresses, IP addresses, phone numbers or payment data in logs, traces, metrics and session recordings. In observability it is applied as early as possible, ideally in the application or telemetry pipeline before data is stored or sent to third parties.
What is PII masking?
PII masking protects personally identifiable information (PII) by hiding it in data that is collected for other purposes. Telemetry is a common place where personal data ends up by accident: a log line that prints the full request body, a span attribute with the user's email address, a URL with a session token in the query string or an error message that contains a customer's address. Masking replaces those values with placeholders, hashes or truncated versions, so that engineers can still debug without seeing who the data belongs to.
In the EU, the relevant legal term is personal data under the GDPR, which is broader than the US notion of PII. It includes any information relating to an identifiable person, for example IP addresses, device IDs and user IDs, not only names and email addresses.
Why it matters for observability
- Data minimization: the GDPR requires that personal data is limited to what is necessary (Art. 5) and that systems implement data protection by design and by default (Art. 25).
- Wide access: observability data is read by many engineers, copied to dashboards and sometimes shared with vendors or AI assistants.
- Long retention: logs may be kept for months, which multiplies the exposure.
- Deletion requests: if personal data is scattered across log indices, honoring a deletion request becomes very hard.
- Secrets: the same mechanisms also catch API keys, passwords and tokens that should never be logged.
Masking techniques
| Technique | Example | Use when |
|---|---|---|
| Redaction | [REDACTED] | The value is never needed. |
| Partial masking | j***@example.com, ****1234 | Humans need a hint for support cases. |
| Hashing or tokenization | user=7f3a9c... | You need to group or count by user without knowing who it is. |
| Truncation and generalization | 203.0.113.0/24 | Coarse location or network data is enough. |
| Dropping the field | attribute removed | The field has no diagnostic value. |
Hashing is pseudonymization, not anonymization: under the GDPR pseudonymized data is still personal data. Plain hashes of low-entropy values such as email addresses or phone numbers can be reversed by brute force, so use a keyed hash (HMAC) with a secret that is rotated and stored outside the telemetry system.
Where to mask
- In the application: the safest place. Use structured logging with explicit fields instead of dumping objects, and keep allowlists of fields that may be logged.
- In the instrumentation: OpenTelemetry SDKs and auto-instrumentation can be configured not to capture request bodies, headers or query strings.
- In the telemetry pipeline: a central safety net. The OpenTelemetry Collector offers processors such as the attributes processor (delete or hash attributes), the transform processor (pattern replacements with OTTL) and the redaction processor (allowlists and blocked value patterns).
- In the frontend: real user monitoring and session replay should mask input fields and text by default.
Masking in storage or at query time is the weakest option, because the raw data has already been written and may already be in backups.
Also think of side channels: database error messages often contain the offending values, stack traces may print parameters, and exports to external tools sometimes bypass the central pipeline. Review samples from all signal types regularly, not only from logs.
Best practices
- Prefer allowlists over blocklists: decide which attributes may pass instead of trying to list every sensitive one.
- Combine field-based rules with pattern detection for emails, IBANs, card numbers and tokens.
- Test masking rules with real samples and monitor how often they match; a sudden spike often reveals a new logging bug.
- Document the rules as part of your record of processing activities.
- Mask before data leaves your environment or region.
Example: masking in an OpenTelemetry Collector
An illustrative Collector configuration that removes the email attribute, hashes the user ID and masks card-like numbers in log bodies could look like this:
processors:
attributes/pii:
actions:
- key: user.email
action: delete
- key: user.id
action: hash
transform/pii:
log_statements:
- context: log
statements:
- replace_pattern(body, "[0-9]{13,19}", "****")
Rules like these are a safety net, not a replacement for clean logging in the code. Keep them under version control, review them like code and add test cases for every new pattern.
How Obseria helps
The Obseria Pipeline masks PII and secrets in logs, traces and metrics before storage, with field rules, pattern detection and keyed hashing, and drops or routes data according to your policies. Data is stored in Obseria Lake with EU data residency, and session replay masks input fields by default.