Design Privacy-Preserving Observability
Core idea
Observability uses events, metrics and traces to investigate system behavior. Define a small event schema with an operation identifier, outcome and duration or count. Use an allowlist of safe fields and bound their size. Keep raw payloads and secrets outside diagnostics; avoid high-cardinality metric labels such as individual request IDs.
import jsondef event(data): return {'operation': data['operation'], 'outcome': data['outcome']}record = event({'operation': 'job-4', 'outcome': 'ok', 'token': 'demo-secret'})print(json.dumps(record, sort_keys=True))Only permitted fields leave this boundary; values must also be validated in a real system.
Expected output:
{"operation": "job-4", "outcome": "ok"}Aggregate low-cardinality outcomes
from collections import Counterresults = ['ok', 'error', 'ok']counts = Counter(results)print(counts['ok'], counts['error'])A bounded outcome vocabulary can be aggregated independently of individual IDs.
Expected output:
2 1Common mistake
Redacting one known key is insufficient: secrets can appear in messages, exceptions and nested values. Define retention and access policies and test the actual emitted fields.
Practice
Design an event for a failed inventory update with a bounded reason code. Assert that a synthetic secret in the source input never appears in the serialized event.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Observability and privacy
Check your understanding of observability and privacy.
What is printed?
record={"outcome":"ok","secret":"demo"}print(sorted(k for k in record if k in {"outcome"}))What is printed?
from collections import Counterprint(Counter(["ok","ok","error"])["ok"])Which metric label is usually bounded?
What is an allowlist for diagnostics?