コード例 #1
0
 public void Enrich(EventEnrichmentContext context, Event ev) {
     try {
         _enrichmentAction(context, ev);
     } catch (Exception ex) {
         context.Resolver.GetLog().FormattedError(typeof(ActionEnrichment), ex, "An error occurred while running an custom enrichment: {0}", ex.Message);
     }
 }
コード例 #2
0
        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;
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public void Enrich(EventEnrichmentContext context, Event ev) {
            //error.ExceptionlessClientInfo.Platform = "Nancy";

            var nancyContext = context.Data.GetNancyContext();
            if (nancyContext == null)
                return;

            if (nancyContext.CurrentUser != null && context.Client.Configuration.IncludePrivateInformation)
                ev.SetUserIdentity(nancyContext.CurrentUser.UserName);

            RequestInfo requestInfo = null;
            try {
                requestInfo = nancyContext.GetRequestInfo(context.Client.Configuration);
            } catch (Exception ex) {
                context.Log.Error(typeof(ExceptionlessNancyEnrichment), ex, "Error adding request info.");
            }

            if (requestInfo == null)
                return;

            if (ev.Type == Event.KnownTypes.NotFound) {
                ev.Source = String.Format("{0} {1}", requestInfo.HttpMethod, requestInfo.GetFullPath(includeQueryString: true));
                ev.Data.Clear();
            }

            ev.AddRequestInfo(requestInfo);
        }
コード例 #5
0
        public void Enrich(EventEnrichmentContext context, Event ev) {
            foreach (string tag in context.Client.Configuration.DefaultTags)
                ev.Tags.Add(tag);

            foreach (var data in context.Client.Configuration.DefaultData)
                ev.Data[data.Key] = data.Value;
        }
コード例 #6
0
         public void ValidateTag(string tag, bool isValid) {
            var ev = new Event { Type = Event.KnownTypes.Error, Date = DateTimeOffset.Now };
            ev.Tags.Add(tag);

            var result = _validator.Validate(ev);
            Assert.Equal(isValid, result.IsValid);
        }
コード例 #7
0
        public void Enrich(EventEnrichmentContext context, Event ev) {
            if (!context.Client.Configuration.IncludePrivateInformation)
                return;

            var user = ev.GetUserIdentity();
            if (user == null || String.IsNullOrEmpty(user.Identity))
                ev.SetUserIdentity(Environment.UserName);
        }
コード例 #8
0
        public void CanSerializeEvent() {
            var ev = new Event { Date = DateTime.Now, Message = "Testing"};
            ev.Data["FirstName"] = "Blake";

            IJsonSerializer serializer = GetSerializer();
            string json = serializer.Serialize(ev, new[] { "Date" });
            Assert.Equal(@"{""message"":""Testing"",""data"":{""FirstName"":""Blake""}}", json);
        }
コード例 #9
0
        public void Enqueue(Event ev) {
            if (AreQueuedItemsDiscarded) {
                _log.Info(typeof(ExceptionlessClient), "Queue items are currently being discarded. The event will not be queued.");
                return;
            }

            _storage.Enqueue(_config.GetQueueName(), ev);
        }
コード例 #10
0
        public void Enrich(EventEnrichmentContext context, Event ev) {
            var exception = context.Data.GetException();
            if (exception == null)
                return;

            ev.Type = Event.KnownTypes.Error;
            ev.Data[Event.KnownDataKeys.SimpleError] = exception.ToSimpleErrorModel();
        }
コード例 #11
0
 /// <summary>
 /// Called when the event object is created and can be used to add information to the event.
 /// </summary>
 /// <param name="context">Context information.</param>
 /// <param name="ev">Event that was created.</param>
 public static void Enrich(EventEnrichmentContext context, Event ev) {
     foreach (IEventEnrichment enrichment in context.Client.Configuration.Enrichments.ToList()) {
         try {
             enrichment.Enrich(context, ev);
         } catch (Exception ex) {
             context.Resolver.GetLog().FormattedError(typeof(EventEnrichmentManager), ex, "An error occurred while running {0}.Enrich(): {1}", enrichment.GetType().FullName, ex.Message);
         }
     }
 }
コード例 #12
0
        public void EnvironmentInfo_IncorrectEventType(string eventType) {
            var client = new ExceptionlessClient();
            var context = new EventEnrichmentContext(client);
            var ev = new Event { Type = eventType };

            var enrichment = new EnvironmentInfoEnrichment();
            enrichment.Enrich(context, ev);
            Assert.Equal(0, ev.Data.Count);
        }
コード例 #13
0
 /// <summary>
 /// Enrich the event with additional information.
 /// </summary>
 /// <param name="context">Context information.</param>
 /// <param name="ev">Event to enrich.</param>
 public void Enrich(EventEnrichmentContext context, Event ev) {
     try {
         int maxEntriesToInclude = context.Client.Configuration.Settings.GetInt32(MaxEntriesToIncludeKey, DefaultMaxEntriesToInclude);
         if (maxEntriesToInclude > 0)
             AddRecentTraceLogEntries(ev, maxEntriesToInclude);
     } catch (Exception ex) {
         context.Log.FormattedError(typeof(TraceLogEnrichment), ex, "Error adding trace information: {0}", ex.Message);
     }
 }
コード例 #14
0
        public void EnvironmentInfo_ShouldAddSessionStart() {
            var client = new ExceptionlessClient();
            var context = new EventEnrichmentContext(client);
            var ev = new Event { Type = Event.KnownTypes.SessionStart };

            var enrichment = new EnvironmentInfoEnrichment();
            enrichment.Enrich(context, ev);
            Assert.Equal(1, ev.Data.Count);
            Assert.NotNull(ev.Data[Event.KnownDataKeys.EnvironmentInfo]);
        }
コード例 #15
0
        private void InitializeReport(Event report) {
            if (report.Data == null)
                report.Data = new DataDictionary();
            if (report.Tags == null)
                report.Tags = new TagSet();

            // reset values
            report.ReferenceId = String.Empty;
            report.Date = DateTimeOffset.Now;
        }
コード例 #16
0
        public void Enrich(EventEnrichmentContext context, Event ev) {
            if (ev.Type != Event.KnownTypes.SessionStart)
                return;

            try {
                var collector = context.Resolver.GetEnvironmentInfoCollector();
                ev.Data.Add(Event.KnownDataKeys.EnvironmentInfo, collector.GetEnvironmentInfo());
            } catch (Exception ex) {
                context.Resolver.GetLog().FormattedError(typeof(EnvironmentInfoEnrichment), ex, "Error adding machine information: {0}", ex.Message);
            }
        }
コード例 #17
0
        public void EnvironmentInfo_CanRunInParallel() {
            var client = new ExceptionlessClient();
            var ev = new Event { Type = Event.KnownTypes.SessionStart };
            var plugin = new EnvironmentInfoPlugin();

            Parallel.For(0, 10000, i => {
                var context = new EventPluginContext(client, ev);
                plugin.Run(context);
                Assert.Equal(1, context.Event.Data.Count);
                Assert.NotNull(context.Event.Data[Event.KnownDataKeys.EnvironmentInfo]);
            });
        }
コード例 #18
0
        /// <summary>
        /// Adds the trace info as extended data to the event.
        /// </summary>
        /// <param name="ev">The event model.</param>
        /// <param name="listener">The listener.</param>
        /// <param name="maxEntriesToInclude"></param>
        public static void AddRecentTraceLogEntries(Event ev, ExceptionlessTraceListener listener = null, int maxEntriesToInclude = DefaultMaxEntriesToInclude) {
            if (ev.Data.ContainsKey(Event.KnownDataKeys.TraceLog))
                return;

            listener = listener ?? Trace.Listeners.OfType<ExceptionlessTraceListener>().FirstOrDefault();
            if (listener == null)
                return;

            List<string> logEntries = listener.GetLogEntries(maxEntriesToInclude);
            if (logEntries.Count > 0)
                ev.Data.Add(Event.KnownDataKeys.TraceLog, logEntries);
        }
コード例 #19
0
        public void CanFireOnSubmittingEvent() {
            var client = CreateClient();
            var ev = new Event { Message = "Unit Test" };
            var submittingEventArgs = new List<EventSubmittingEventArgs>();

            client.SubmittingEvent += (sender, e) => {
                submittingEventArgs.Add(e);
            }; 

            new EventBuilder(ev, client).Submit();
            Assert.Equal(1, submittingEventArgs.Count);

            new EventBuilder(ev, client, new ContextData()).Submit();
            Assert.Equal(2, submittingEventArgs.Count);  
        }
コード例 #20
0
        public CrashReportForm(Event ev) {
            InitializeComponent();

            Event = ev;
            Text = String.Format("{0} Error", AssemblyHelper.GetAssemblyTitle());
            InformationHeaderLabel.Text = String.Format("{0} has encountered a problem and needs to close.  We are sorry for the inconvenience.", AssemblyHelper.GetAssemblyTitle());

            // TODO: Implement this once the client has persisted storage.
            var userInfo = ev.GetUserIdentity();
            if (userInfo != null && !String.IsNullOrEmpty(userInfo.Identity))
                EmailAddressTextBox.Text = userInfo.Identity;
            //else
            //    EmailAddressTextBox.Text = ExceptionlessClient.Default.LocalConfiguration.EmailAddress;

            DescriptionTextBox.Text = Event.GetUserDescription();
        }
コード例 #21
0
        public void Enrich(EventEnrichmentContext context, Event ev) {
            HttpContextBase httpContext = context.Data.GetHttpContext();

            // if the context is not passed in, try and grab it
            if (httpContext == null && HttpContext.Current != null)
                httpContext = HttpContext.Current.ToWrapped();

            if (httpContext == null)
                return;

            // ev.ExceptionlessClientInfo.Platform = ".NET Web";
            if (context.Client.Configuration.IncludePrivateInformation
                && httpContext.User != null
                && httpContext.User.Identity.IsAuthenticated)
                ev.SetUserIdentity(httpContext.User.Identity.Name);

            var tags = httpContext.Items[TAGS_HTTP_CONTEXT_NAME] as TagSet;
            if (tags != null)
                ev.Tags.UnionWith(tags);

            RequestInfo requestInfo = null;
            try {
                requestInfo = httpContext.GetRequestInfo(context.Client.Configuration);
            } catch (Exception ex) {
                context.Log.Error(typeof(ExceptionlessWebEnrichment), ex, "Error adding request info.");
            }

            if (requestInfo == null)
                return;

            var httpException = context.Data.GetException() as HttpException;
            if (httpException != null) {
                int httpCode = httpException.GetHttpCode();
                if (httpCode == 404) {
                    ev.Type = Event.KnownTypes.NotFound;
                    ev.Source = requestInfo.GetFullPath(includeHttpMethod: true, includeHost: false, includeQueryString: false);
                    ev.Data.Clear();
                }
            }

            ev.AddRequestInfo(requestInfo);
        }
コード例 #22
0
        public void IgnoreUserAgentPlugin_DiscardBot() {
            var client = new ExceptionlessClient();
            client.Configuration.AddUserAgentBotPatterns("*Bot*");
            var plugin = new IgnoreUserAgentPlugin();

            var ev = new Event();
            var context = new EventPluginContext(client, ev);
            plugin.Run(context);
            Assert.False(context.Cancel);

            ev.AddRequestInfo(new RequestInfo { UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4" });
            context = new EventPluginContext(client, ev);
            plugin.Run(context);
            Assert.False(context.Cancel);

            ev.AddRequestInfo(new RequestInfo { UserAgent = "Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)" });
            context = new EventPluginContext(client, ev);
            plugin.Run(context);
            Assert.True(context.Cancel);
        }
コード例 #23
0
        public void ConfigurationDefaults_EnsureNoDuplicateTagsOrData() {
            var client = new ExceptionlessClient();
            var context = new EventEnrichmentContext(client);
            var ev = new Event();

            var enrichment = new ConfigurationDefaultsEnrichment();
            enrichment.Enrich(context, ev);
            Assert.Equal(0, ev.Tags.Count);

            client.Configuration.DefaultTags.Add(Event.KnownTags.Critical);
            enrichment.Enrich(context, ev);
            Assert.Equal(1, ev.Tags.Count);
            Assert.Equal(0, ev.Data.Count);

            client.Configuration.DefaultData.Add("Message", new { Exceptionless = "Is Awesome!" });
            for (int index = 0; index < 2; index++) {
                enrichment.Enrich(context, ev);
                Assert.Equal(1, ev.Tags.Count);
                Assert.Equal(1, ev.Data.Count);
            }
        }
コード例 #24
0
        public CrashReportForm(ExceptionlessClient client, Event ev) {
            InitializeComponent();

            Client = client;
            Event = ev;
            Text = String.Concat(AssemblyHelper.GetAssemblyTitle(), " Error");
            InformationHeaderLabel.Text = String.Concat(AssemblyHelper.GetAssemblyTitle(), " has encountered a problem and needs to close.  We are sorry for the inconvenience.");

            var userInfo = ev.GetUserIdentity(client.Configuration.Resolver.GetJsonSerializer());
            if (userInfo != null && !String.IsNullOrEmpty(userInfo.Identity)) {
                EmailAddressTextBox.Text = userInfo.Identity;
            } else {
                var storage = client.Configuration.Resolver.Resolve<PersistedDictionary>();
                string emailAddress;
                if (storage != null && storage.TryGetValue("EmailAddress", out emailAddress))
                    EmailAddressTextBox.Text = emailAddress;
            }

            var userDescription = Event.GetUserDescription(client.Configuration.Resolver.GetJsonSerializer());
            if (userDescription != null)
                DescriptionTextBox.Text = userDescription.Description;
        }
コード例 #25
0
        public void Enrich(EventEnrichmentContext context, Event ev) {
            if (ev.Data.ContainsKey(Event.KnownDataKeys.Version))
                return;

            object value;
            if (context.Client.Configuration.DefaultData.TryGetValue(Event.KnownDataKeys.Version, out value) && value is string) {
                ev.Data[Event.KnownDataKeys.Version] = value;
                return;
            }

            if (_checkedForVersion)
                return;
            
            _checkedForVersion = true;
            string version = null;
            try {
                version = GetVersionFromLoadedAssemblies();
            } catch (Exception) {}

            if (String.IsNullOrEmpty(version))
                return;

            ev.Data[Event.KnownDataKeys.Version] = context.Client.Configuration.DefaultData[Event.KnownDataKeys.Version] = version;
        }
コード例 #26
0
 private bool OnSubmittingEvent(Event ev, ContextData pluginContextData) {
     var args = new EventSubmittingEventArgs(this, ev, pluginContextData);
     OnSubmittingEvent(args);
     return !args.Cancel;
 }
コード例 #27
0
        /// <summary>
        /// Submits the event to be sent to the server.
        /// </summary>
        /// <param name="ev">The event data.</param>
        /// <param name="pluginContextData">
        /// Any contextual data objects to be used by Exceptionless plugins to gather default
        /// information for inclusion in the report information.
        /// </param>
        public void SubmitEvent(Event ev, ContextData pluginContextData = null) {
            if (ev == null)
                throw new ArgumentNullException("ev");

            if (!Configuration.Enabled) {
                _log.Value.Info(typeof(ExceptionlessClient), "Configuration is disabled. The event will not be submitted.");
                return;
            }
            
            if (!Configuration.IsValid) {
                _log.Value.FormattedInfo(typeof(ExceptionlessClient), "Configuration is invalid: {0}. The event will not be submitted.", String.Join(", ", Configuration.Validate().Messages));
                return;
            }

            if (!Configuration.IsLocked) {
                Configuration.LockConfig();
                if (!Configuration.IsValid) {
                    _log.Value.FormattedError(typeof(ExceptionlessClient), "Disabling client due to invalid configuration: {0}", String.Join(", ", Configuration.Validate().Messages));
                    return;
                }
            }

            var context = new EventPluginContext(this, ev, pluginContextData);
            EventPluginManager.Run(context);
            if (context.Cancel)
                return;

            // ensure all required data
            if (String.IsNullOrEmpty(ev.Type))
                ev.Type = Event.KnownTypes.Log;
            if (ev.Date == DateTimeOffset.MinValue)
                ev.Date = DateTimeOffset.Now;

            if (!OnSubmittingEvent(ev, pluginContextData)) {
                _log.Value.FormattedInfo(typeof(ExceptionlessClient), "Event submission cancelled by event handler: id={0} type={1}", ev.ReferenceId, ev.Type);
                return;
            }

            _log.Value.FormattedTrace(typeof(ExceptionlessClient), "Submitting event: type={0}{1}", ev.Type, !String.IsNullOrEmpty(ev.ReferenceId) ? " refid=" + ev.ReferenceId : String.Empty);
            _queue.Value.Enqueue(ev);

            if (String.IsNullOrEmpty(ev.ReferenceId))
                return;

            _log.Value.FormattedTrace(typeof(ExceptionlessClient), "Setting last reference id '{0}'", ev.ReferenceId);
            _lastReferenceIdManager.Value.SetLast(ev.ReferenceId);
        }
コード例 #28
0
 public EventBuilder(Event ev, ExceptionlessClient client = null, ContextData pluginContextData = null) {
     Client = client ?? ExceptionlessClient.Default;
     Target = ev;
     PluginContextData = pluginContextData ?? new ContextData();
 }
コード例 #29
0
 protected bool Equals(Event other)
 {
     return(string.Equals(Type, other.Type) && string.Equals(Source, other.Source) && Tags.CollectionEquals(other.Tags) && string.Equals(Message, other.Message) && string.Equals(Geo, other.Geo) && Value == other.Value && Equals(Data, other.Data));
 }
コード例 #30
0
 public static void Enqueue(this IObjectStorage storage, string queueName, Event ev) {
     storage.SaveObject(Path.Combine(queueName, "q", Guid.NewGuid().ToString("N") + ".0.json"), ev);
 }
コード例 #31
0
        public void Enrich(EventEnrichmentContext context, Event ev) {
            if (ev.Type != Event.KnownTypes.Error)
                return;

            ev.ReferenceId = Guid.NewGuid().ToString("N").Substring(0, 10);
        }