public void Enrich(EventEnrichmentContext context, Event ev) { if (!context.Data.ContainsKey("HttpActionContext")) return; HttpActionContext actionContext = context.Data.GetHttpActionContext(); if (actionContext == null) return; IPrincipal principal = GetPrincipal(actionContext.Request); if (context.Client.Configuration.IncludePrivateInformation && principal != null && principal.Identity.IsAuthenticated) ev.SetUserIdentity(principal.Identity.Name); RequestInfo requestInfo = null; try { requestInfo = actionContext.GetRequestInfo(context.Client.Configuration); } catch (Exception ex) { context.Log.Error(typeof(ExceptionlessWebApiEnrichment), ex, "Error adding request info."); } if (requestInfo == null) return; var error = ev.GetError(); if (error != null && error.Code == "404") { ev.Type = Event.KnownTypes.NotFound; ev.Source = requestInfo.GetFullPath(includeHttpMethod: true, includeHost: false, includeQueryString: false); ev.Data.Clear(); } ev.AddRequestInfo(requestInfo); }
public bool IsDuplicate(Event ev) { if (!ev.IsError()) return false; InnerError current = ev.GetError(); DateTime repeatWindow = DateTime.Now.AddSeconds(-2); while (current != null) { int hashCode = current.GetHashCode(); // make sure that we don't process the same error multiple times within 2 seconds. if (_recentlyProcessedErrors.Any(s => s.Item1 == hashCode && s.Item2 >= repeatWindow)) { _log.FormattedInfo(typeof(ExceptionlessClient), "Ignoring duplicate error event: hash={0}", hashCode); return true; } // add this exception to our list of recent errors that we have processed. _recentlyProcessedErrors.Enqueue(Tuple.Create(hashCode, DateTime.Now)); // only keep the last 10 recent errors Tuple<int, DateTime> temp; while (_recentlyProcessedErrors.Count > 10) _recentlyProcessedErrors.TryDequeue(out temp); current = current.Inner; } return false; }