Redact Before You Record

In Map Where a Hiker’s Message Goes, one question from Marta left her phone number in two lines of your trace file. A kept trace stays on disk for thirty days after its day ends, then until the next daily sweep, and longer while the app is stopped. Anyone who opens traces/ can read it.

In this lesson, you’ll decide what a trace records about a hiker’s question, replay from that record, and delete one hiker’s traces on request. Start with the redaction most developers write first.

Redact in the Trace Writer

A pair of regular expressions looks like enough to keep contact details out of a trace. Save this as try-redact.js:

Language: JavaScript Filename: try-redact.js
const redact = (text) =>
  text
    .replace(/[\w.+-]+@[\w-]+\.[\w.]+/g, "[email]")
    .replace(/\+?\d[\d\s-]{7,}\d/g, "[phone]");

const question =
  "Hi, I'm Anna Berg, booking RH-48213 at hut 5 on " +
  "14 July with my son Leo (8). He has asthma. Is the " +
  "Forcella path OK for him? [email protected], " +
  "+39 333 123 4567";
console.log(redact(question));

Before you run it, list the personal details you expect to be left.

The terminal shows one line, wrapped here:

Language: Text
$ node try-redact.js
Hi, I'm Anna Berg, booking RH-48213 at hut 5 on 14 July with my son
Leo (8). He has asthma. Is the Forcella path OK for him? [email], [phone]

Only the email address and the phone number are gone. Anna’s name, her booking reference, her son’s name and age, and his asthma are all still there, and together they identify a family. Patterns find fixed formats, but details written in a sentence don’t follow one.

So the model span’s question shouldn’t keep the hiker’s prose at all, only the fields the answer was built from.

Record Fields Instead of the Hiker’s Words

Here’s the question line of Anna’s model span before and after replacing her question with fields, with the long line wrapped:

Language: Text
Before: Question: Hi, I'm Anna Berg, booking [booking:ac02…] … He has
        asthma. Is the Forcella path OK for him? …
After:  Question: Places: Forcella path, hut 5. Day: 14 July. Topic: conditions.

The report lines stay, since they’re the wardens’ words, and the retrieve span’s chunks keep their IDs and dates. A new hiker list holds placeholders for any booking reference, email address, or phone number, so you can find the trace on request.

The answer stays too, since it’s what a hiker reports as wrong, but patterns alone redact it. Anna’s question was answered twice while this lesson was written, on December 2, 2026, and one of those answers mentioned her son’s asthma.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.