function sanitizeEvent(e, ts) {
  const r = { ...e };
  r.args = { ...r.args };

  if (ts === 0) {
    this.sessionId = r.args.data.id;
    this.cwd = r.args.cwd;
    r.name = r.name.replace(/^[^ ]*/, 'detox');
  }

  r.pid = (this.pid.has(e.pid) ? this.pid : this.pid.set(e.pid, this.pid.size)).get(e.pid);
  r.tid = (this.tid.has(e.tid) ? this.tid : this.tid.set(e.tid, this.tid.size)).get(e.tid);
  r.ts = ts;

  if (r.name) {
    r.name = r.name
      .replace(TMPDIR, '$TMPDIR')
      .replace(this.sessionId, '$SESSION_ID')
      .replace(this.cwd, '$CWD')
      .replace(this.cwd.replace(/\\/g, '/'), '$CWD')
      .replace(/\\/g, '/')
      .replace(/DETOX_[A-Z_]+=\S*\s*/g, '');
  }

  if (r.args.cwd) {
    r.args.cwd = '$CWD';
  }

  if (typeof r.args.error === 'string') {
    r.args.error = r.args.error.split('\n')[0];
  }

  if (r.args.data) {
    r.args.data = {};
  }

  if (r.args.env) {
    r.args.env = {};
  }

  return r;
}
@this {{ pid: Map; tid: Map; sessionId: string; cwd: string; }}