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); }
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 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); }
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); }
public void CancelSessionsWithNoUserTest(string eventType, string identity, bool cancelled) { var ev = new Event { Type = eventType }; ev.SetUserIdentity(identity); var context = new EventPluginContext(new ExceptionlessClient(), ev); var plugin = new CancelSessionsWithNoUserPlugin(); plugin.Run(context); Assert.Equal(cancelled, context.Cancel); }
public void PrivateInformation_WillNotUpdateIdentity() { var client = new ExceptionlessClient(); var plugin = new SetEnvironmentUserPlugin(); var ev = new Event { Type = Event.KnownTypes.Log, Message = "test" }; ev.SetUserIdentity(null, "Blake"); var context = new EventPluginContext(client, ev); plugin.Run(context); var user = context.Event.GetUserIdentity(); Assert.Null(user.Identity); Assert.Equal("Blake", user.Name); }
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(); } } }