コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
        public void PopulateEvent(Event ev) {
            if (MinDate.HasValue || MaxDate.HasValue)
                ev.Date = RandomData.GetDateTime(MinDate ?? DateTime.MinValue, MaxDate ?? DateTime.MaxValue);

            ev.Type = EventTypes.Random();
            if (ev.Type == Event.KnownTypes.FeatureUsage)
                ev.Source = FeatureNames.Random();
            else if (ev.Type == Event.KnownTypes.NotFound)
                ev.Source = PageNames.Random();
            else if (ev.Type == Event.KnownTypes.Log) {
                ev.Source = LogSources.Random();
                ev.Message = RandomData.GetString();

                string level = LogLevels.Random();
                if (!String.IsNullOrEmpty(level))
                    ev.Data[Event.KnownDataKeys.Level] = level;
            }

            if (RandomData.GetBool(80))
                ev.Geo = RandomData.GetCoordinate();

            if (RandomData.GetBool(20))
                ev.Value = RandomData.GetDecimal();

            ev.SetUserIdentity(Identities.Random());
            ev.SetVersion(RandomData.GetVersion("2.0", "4.0"));

            ev.AddRequestInfo(new RequestInfo {
                //ClientIpAddress = ClientIpAddresses.Random(),
                Path = PageNames.Random()
            });

            ev.Data.Add(Event.KnownDataKeys.EnvironmentInfo, new EnvironmentInfo {
                IpAddress = MachineIpAddresses.Random() + ", " + MachineIpAddresses.Random(),
                MachineName = MachineNames.Random()
            });

            for (int i = 0; i < RandomData.GetInt(1, 3); i++) {
                string key = RandomData.GetWord();
                while (ev.Data.ContainsKey(key) || key == Event.KnownDataKeys.Error)
                    key = RandomData.GetWord();

                ev.Data.Add(key, RandomData.GetString());
            }

            int tagCount = RandomData.GetInt(1, 3);
            for (int i = 0; i < tagCount; i++) {
                string tag = EventTags.Random();
                if (!ev.Tags.Contains(tag))
                    ev.Tags.Add(tag);
            }

            if (ev.Type == Event.KnownTypes.Error) {
                if (RandomData.GetBool()) {
                    // limit error variation so that stacking will occur
                    if (_randomErrors == null)
                        _randomErrors = new List<Error>(Enumerable.Range(1, 25).Select(i => GenerateError()));

                    ev.Data[Event.KnownDataKeys.Error] = _randomErrors.Random();
                } else {
                    // limit error variation so that stacking will occur
                    if (_randomSimpleErrors == null)
                        _randomSimpleErrors = new List<SimpleError>(Enumerable.Range(1, 25).Select(i => GenerateSimpleError()));

                    ev.Data[Event.KnownDataKeys.SimpleError] = _randomSimpleErrors.Random();
                }
            }
        }