Glossary · P

PII Masking

Removing, replacing or hashing personal data in logs, traces and other telemetry before it is stored or shared.

By Obseria TeamUpdated

Definition

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

TechniqueExampleUse when
Redaction[REDACTED]The value is never needed.
Partial maskingj***@example.com, ****1234Humans need a hint for support cases.
Hashing or tokenizationuser=7f3a9c...You need to group or count by user without knowing who it is.
Truncation and generalization203.0.113.0/24Coarse location or network data is enough.
Dropping the fieldattribute removedThe 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

  1. 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.
  2. In the instrumentation: OpenTelemetry SDKs and auto-instrumentation can be configured not to capture request bodies, headers or query strings.
  3. 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).
  4. 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.

Frequently asked questions

Masking hides or replaces values, but some techniques such as hashing or tokenization still allow linking records to the same person. That is pseudonymization, and the data remains personal data under the GDPR. Anonymization removes the link to a person irreversibly.

Under the GDPR, an IP address is usually considered personal data, because it can be linked to a person with additional information. In observability, IP addresses are therefore often truncated, hashed with a secret or dropped.

As early as possible: ideally in the application by not logging personal data at all, and additionally in the telemetry pipeline as a central safety net before data is stored or leaves your environment.

Rarely, if it is done well. Engineers usually need stable identifiers and error context, not real names or email addresses. Keyed hashes let you group events by user, and partial masking leaves enough of a hint for support cases.

Put these concepts into practice

Try Obseria free for 14 days, with OpenTelemetry and no proprietary agents.