private void ProcessEvent(object e, EventBuffer buffer) { if (_disabled) { return; } // Decide whether to add the event to the payload. Feature events may be added twice, once for // the event (if tracked) and once for debugging. bool willAddFullEvent = true; DebugEvent? debugEvent = null; UnixMillisecondTime timestamp; User user = null; switch (e) { case EvaluationEvent ee: buffer.AddToSummary(ee); // only evaluation events go into the summarizer timestamp = ee.Timestamp; user = ee.User; willAddFullEvent = ee.TrackEvents; if (ShouldDebugEvent(ee)) { debugEvent = new DebugEvent { FromEvent = ee }; } break; case IdentifyEvent ie: timestamp = ie.Timestamp; user = ie.User; break; case CustomEvent ce: timestamp = ce.Timestamp; user = ce.User; break; default: timestamp = new UnixMillisecondTime(); break; } // Tell the user deduplicator, if any, about this user; this may produce an index event. // We only need to do this if there is *not* already going to be a full-fidelity event // containing an inline user. if (!(willAddFullEvent && _config.InlineUsersInEvents) && user != null && _userDeduplicator != null) { bool needUserEvent = _userDeduplicator.ProcessUser(user); if (needUserEvent && !(e is IdentifyEvent)) { IndexEvent ie = new IndexEvent { Timestamp = timestamp, User = user }; buffer.AddEvent(ie); } else if (!(e is IdentifyEvent)) { _diagnosticStore?.IncrementDeduplicatedUsers(); } } if (willAddFullEvent) { buffer.AddEvent(e); } if (debugEvent != null) { buffer.AddEvent(debugEvent); } }