mapLogEvent method

Map<String, dynamic>? mapLogEvent(
  1. Map<String, dynamic> logEventJson
)

Implementation

Map<String, dynamic>? mapLogEvent(Map<String, dynamic> logEventJson) {
  if (_logEventMapper case final mapper?) {
    final logEvent = LogEvent.fromJson(logEventJson);
    // Pull out any extra attributes
    for (final item in logEventJson.entries) {
      final key = item.key;
      if (!reservedAttributes.contains(key)) {
        logEvent.attributes[key] = item.value;
      }
    }

    final mappedEvent = mapper(logEvent);
    if (mappedEvent == null) return null;

    final mappedJson = mappedEvent.toJson();
    for (final item in mappedEvent.attributes.entries) {
      // Put extra attributes back
      final keyRoot = item.key.split('.').first;
      if (!reservedAttributes.contains(keyRoot)) {
        mappedJson[item.key] = item.value;
      }
    }
    return mappedJson;
  }

  return logEventJson;
}