discontinuedPackage fluttersdk_telescope has been discontinued and replaced by crumbs.

redactEventRecord static method

EventRecord? redactEventRecord(
  1. EventRecord record
)

Return record with a JSON-safe payload, and with every text field run through the redactor and redacted set when one is registered.

The payload is walked at any depth of Maps and Lists, and the redactor runs over every map key as well as every String value. A value jsonEncode cannot write (a DateTime, a Duration, any object) is stored as its toString() and a non-String map key as its toString(), so one bad payload cannot fail a whole events response. A subtree nested past 64 levels is masked whole. Returns record itself when there is nothing to change, and null, the record dropped, when the redactor throws.

Implementation

static EventRecord? redactEventRecord(EventRecord record) {
  final String Function(String)? redact = _guardedRedactor();

  return _dropOnRedactorFailure(() {
    final Map<String, dynamic> payload =
        _scrub(record.payload, redact) as Map<String, dynamic>;
    if (redact == null && identical(payload, record.payload)) return record;

    final EventRecord scrubbed = EventRecord(
      eventType: _text(record.eventType, redact)!,
      payload: payload,
      time: record.time,
      listenerCount: record.listenerCount,
      atUs: record.atUs,
      interactionId: _text(record.interactionId, redact),
      linkedBy: _text(record.linkedBy, redact),
    );
    // Without a redactor only the JSON-safe pass ran; a copy of a record a
    // redactor already produced stays as redacted as its source.
    return redact != null || record.redacted
        ? _markRedacted(scrubbed)
        : scrubbed;
  });
}