Data Masking in Telemetry: The Art of Safe Transformation
This guide dives straight into the how-to of transforming your data. If you’re wondering which fields are trouble or what compliance wants from you, check out Your Traces Are Leaking User Data. This is about how to actually make your data safe.
The Data Transformation Pipeline
Masking is a relay. Each stage hands off to the next, trusting the last step did its job. Miss a handoff and you leak fields you thought were safe.
Raw Telemetry: The raw, sensitive data as it’s initially collected. It contains PII, and if you export it unchanged, it lands in your trace backend indexed and searchable: a GDPR audit waiting to happen.
Masking Decision: This is where you sort the fields. Some need redaction. Others, like system metrics or anonymous usage stats, carry no personal identifiers and go through untouched.
Transformation: This is where the actual masking happens, matched to each field’s type and sensitivity:
- Hashing: Run sensitive data, like user IDs or email addresses, through a one-way function, and you get a fixed-length string. You can’t get the original back, but you can still analyse and correlate.
- Tokenisation: Swap the sensitive data for a random, unique token instead, and keep a secure lookup table that maps tokens back to original values. Only authorised systems that need re-identification get access to that table.
Which of the two you reach for is decided by the field, not by preference, and getting it wrong is the most common failure in this whole area:
Hashing works when the input space is large enough that an attacker can’t enumerate it. An opaque order ID with a secret salt qualifies. An email address doesn’t: there are only so many email addresses in the world, and a single GPU walks the entire list in under a second. Personal identifiers get deleted or tokenised. Business identifiers get hashed.
Transformation Examples
User Activity Telemetry
Before transformation:
{
"event": "user_login",
"timestamp": "2024-02-15T10:30:00Z",
"attributes": {
"user.email": "sarah.jones@company.com",
"user.ip": "192.168.1.100",
"device.id": "d789-xyz-456",
"location": "San Francisco, CA",
"browser": "Chrome 120.0.0",
"login_success": true
}
}
After transformation:
{
"event": "user_login",
"timestamp": "2024-02-15T10:30:00Z",
"attributes": {
"user.id": "<hash_value>",
"user.ip_prefix": "192.168.0.0/16",
"device.type": "web_browser",
"location.region": "US-WEST",
"browser.family": "Chrome",
"login_success": true
}
}
Transformation Patterns
Quality Control Gates
Each gate checks a structural property of the transformed data before it reaches the exporter:
"US-WEST" breaks every downstream aggregationTransformation Matrix
| Data Type | Example | Transformation | Rationale | Result Example |
|---|---|---|---|---|
| user@company.com | Remove | PII — no safe hash | (deleted) | |
| IP Address | 192.168.1.100 | Subnet Mask | Network analysis | 192.168.0.0/16 |
| Location | San Francisco, CA | Region Code | Geographic trends | US-WEST |
| Timestamp | 2024-02-15T10:30:00Z | Time Bucket | Pattern analysis | 2024-02-15T10:00:00Z |
Data Utility Preservation
The transformation must preserve the relationships between fields: statistical distributions, cross-span correlations, and time-series patterns. Lose those, and the data loses its diagnostic value:
Common Pitfalls and Solutions
These are the two failures that break pipelines in practice, over and over:
Inconsistent Masking
// Bad: Same value masked differently { "user_id": "hash1", "referenced_user": "hash2" // Same user, different hash! } // Good: Consistent masking { "user_id": "hash1", "referenced_user": "hash1" // Same user, same hash }Over-Masking
// Bad: Losing analytical value { "region": "****", "response_time_ms": "****" // Don't mask metrics! } // Good: Preserve useful data { "region": "US-WEST", "response_time_ms": 123 }
I have anointed your logs with the holy redaction. The secrets are sealed, the PII is at rest. Go forth and ship.
See Also
- Your Traces Are Leaking User Data — which fields carry risk and why, before you decide how to transform them
- Observability Under Compliance — where hashing vs deletion sits in the GDPR, HIPAA, SOC 2, and PCI DSS picture
- Implementing Audit Trails with OpenTelemetry — tokenising identifiers inside a record you can’t delete
- Scrub PII from Application Logs in .NET — the application-level layer that applies these same techniques before the Collector ever sees the data