public void Run(EventPluginContext context) {
            int hashCode = context.Event.GetHashCode();
            int count = context.Event.Count ?? 1;
            context.Log.FormattedTrace(typeof(DuplicateCheckerPlugin), "Checking event: {0} with hash: {1}", context.Event.Message, hashCode);

            lock (_lock) {
                // Increment the occurrence count if the event is already queued for submission.
                var merged = _mergedEvents.FirstOrDefault(s => s.HashCode == hashCode);
                if (merged != null) {
                    merged.IncrementCount(count);
                    merged.UpdateDate(context.Event.Date);
                    context.Log.FormattedInfo(typeof(DuplicateCheckerPlugin), "Ignoring duplicate event with hash: {0}", hashCode);
                    context.Cancel = true;
                    return;
                }

                DateTimeOffset repeatWindow = DateTimeOffset.UtcNow.Subtract(_interval);
                if (_processed.Any(s => s.Item1 == hashCode && s.Item2 >= repeatWindow)) {
                    context.Log.FormattedInfo(typeof(DuplicateCheckerPlugin), "Adding event with hash: {0} to cache.", hashCode);
                    // This event is a duplicate for the first time, lets save it so we can delay it while keeping count
                    _mergedEvents.Enqueue(new MergedEvent(hashCode, context, count));
                    context.Cancel = true;
                    return;
                }

                context.Log.FormattedInfo(typeof(DuplicateCheckerPlugin), "Enqueueing event with hash: {0} to cache.", hashCode);
                _processed.Enqueue(Tuple.Create(hashCode, DateTimeOffset.UtcNow));
                
                while (_processed.Count > 50)
                    _processed.Dequeue();
            }
        }
        public void Run(EventPluginContext context) {
            if (context.Event.Data.ContainsKey(Event.KnownDataKeys.Version))
                return;

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

            if (_checkedForVersion)
                return;
            
            _checkedForVersion = true;

            string version = GetVersionFromRuntimeInfo(context.Log);
#if !PORTABLE && !NETSTANDARD1_2
            if (String.IsNullOrEmpty(version))
                version = GetVersionFromLoadedAssemblies(context.Log);
#endif
            if (String.IsNullOrEmpty(version))
                return;

            context.Event.Data[Event.KnownDataKeys.Version] = context.Client.Configuration.DefaultData[Event.KnownDataKeys.Version] = version;
        }
        public void Run(EventPluginContext context) {
            if (context.Event.IsSessionHeartbeat())
                return;
            
            if (context.Event.IsSessionEnd()) {
                if (_heartbeat != null) {
                    _heartbeat.Dispose();
                    _heartbeat = null;
                }

                return;
            }

            var user = context.Event.GetUserIdentity();
            if (user == null || String.IsNullOrEmpty(user.Identity))
                return;
            
            if (_heartbeat == null) {
                _heartbeat = new SessionHeartbeat(user, context.Client);
            } else if (_heartbeat.User.Identity != user.Identity) {
                if (_heartbeat != null)
                    _heartbeat.Dispose();

                _heartbeat = new SessionHeartbeat(user, context.Client);
            } else {
                if (_heartbeat != null)
                    _heartbeat.DelayNext();
            }
        }
예제 #4
0
 public void Run(EventPluginContext context) {
     try {
         _pluginAction(context);
     } catch (Exception ex) {
         context.Log.FormattedError(typeof(ActionPlugin), ex, "An error occurred while running an custom plugin: {0}", ex.Message);
     }
 }
        public void Run(EventPluginContext context) {
            if (!context.Event.IsError())
                return;

            InnerError current = context.Event.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)) {
                    context.Log.FormattedInfo(typeof(ExceptionlessClient), "Ignoring duplicate error event: hash={0}", hashCode);
                    context.Cancel = true;
                    return;
                }

                // 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;
            }
        }
        public void Run(EventPluginContext context) {
            var exception = context.ContextData.GetException();
            if (exception == null)
                return;

            context.Event.Type = Event.KnownTypes.Error;
            context.Event.Data[Event.KnownDataKeys.SimpleError] = exception.ToSimpleErrorModel();
        }
        public void Run(EventPluginContext context) {
            if (!context.Client.Configuration.IncludePrivateInformation)
                return;

            var user = context.Event.GetUserIdentity(context.Client.Configuration.Resolver.GetJsonSerializer());
            if (user == null)
                context.Event.SetUserIdentity(Environment.UserName);
        }
예제 #8
0
        public void Run(EventPluginContext context)
        {
            if (!context.ContextData.ContainsKey("HttpActionContext"))
            {
                return;
            }

            var actionContext = context.ContextData.GetHttpActionContext();

            if (actionContext == null)
            {
                return;
            }

            var serializer = context.Client.Configuration.Resolver.GetJsonSerializer();

            if (context.Client.Configuration.IncludePrivateInformation)
            {
                var user = context.Event.GetUserIdentity(serializer);
                if (user == null)
                {
                    IPrincipal principal = GetPrincipal(actionContext.Request);
                    if (principal != null && principal.Identity.IsAuthenticated)
                    {
                        context.Event.SetUserIdentity(principal.Identity.Name);
                    }
                }
            }

            var ri = context.Event.GetRequestInfo(serializer);

            if (ri != null)
            {
                return;
            }

            try {
                ri = actionContext.GetRequestInfo(context.Client.Configuration);
            } catch (Exception ex) {
                context.Log.Error(typeof(ExceptionlessWebApiPlugin), ex, "Error adding request info.");
            }

            if (ri == null)
            {
                return;
            }

            var error = context.Event.GetError(serializer);

            if (error != null && error.Code == "404")
            {
                context.Event.Type   = Event.KnownTypes.NotFound;
                context.Event.Source = ri.GetFullPath(includeHttpMethod: true, includeHost: false, includeQueryString: false);
            }

            context.Event.AddRequestInfo(ri);
        }
        public void Run(EventPluginContext context) {
            if (context.Event.IsSessionStart() || String.IsNullOrEmpty(context.Client.Configuration.CurrentSessionIdentifier))
                context.Client.Configuration.CurrentSessionIdentifier = Guid.NewGuid().ToString("N");

            if (context.Event.IsSessionStart())
                context.Event.ReferenceId = context.Client.Configuration.CurrentSessionIdentifier;
            else
                context.Event.SetEventReference("session", context.Client.Configuration.CurrentSessionIdentifier);
        }
예제 #10
0
 public void Run(EventPluginContext context) {
     try {
         int maxEntriesToInclude = context.Client.Configuration.Settings.GetInt32(MaxEntriesToIncludeKey, DefaultMaxEntriesToInclude);
         if (maxEntriesToInclude > 0)
             AddRecentTraceLogEntries(context.Event, _listener, maxEntriesToInclude);
     } catch (Exception ex) {
         context.Log.FormattedError(typeof(TraceLogPlugin), ex, "Error adding trace information: {0}", ex.Message);
     }
 }
        public void Run(EventPluginContext context) {
            foreach (string tag in context.Client.Configuration.DefaultTags)
                context.Event.Tags.Add(tag);

            foreach (var data in context.Client.Configuration.DefaultData) {
                if (!context.Event.Data.ContainsKey(data.Key))
                    context.Event.SetProperty(data.Key, data.Value, client: context.Client);
            }
        }
        public void Run(EventPluginContext context)
        {
            var httpContext = context.ContextData.GetHttpContext();

            if (httpContext == null && _httpContextAccessor != null)
            {
                httpContext = _httpContextAccessor.HttpContext;
            }

            var serializer = context.Client.Configuration.Resolver.GetJsonSerializer();

            if (context.Client.Configuration.IncludeUserName)
            {
                AddUser(context, httpContext, serializer);
            }

            if (httpContext == null)
            {
                return;
            }

            var ri = context.Event.GetRequestInfo(serializer);

            if (ri != null)
            {
                return;
            }

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

            if (ri == null)
            {
                return;
            }

            context.Event.AddRequestInfo(ri);
            var error = context.Event.GetError(serializer);

            if (error == null || error.Code != "404")
            {
                return;
            }

            context.Event.Type   = Event.KnownTypes.NotFound;
            context.Event.Source = ri.GetFullPath(includeHttpMethod: true, includeHost: false, includeQueryString: false);
            if (!context.Client.Configuration.Settings.GetTypeAndSourceEnabled(context.Event.Type, context.Event.Source))
            {
                context.Log.Info(String.Format("Cancelling event from excluded type: {0} and source: {1}", context.Event.Type, context.Event.Source));
                context.Cancel = true;
            }
        }
        public void Run(EventPluginContext context) {
            var request = context.Event.GetRequestInfo(context.Client.Configuration.Resolver.GetJsonSerializer());
            if (request == null)
                return;

            if (request.UserAgent.AnyWildcardMatches(context.Client.Configuration.UserAgentBotPatterns, true)) {
                context.Log.Info(String.Concat("Cancelling event as the request infos user agent matches a known bot pattern: ", request.UserAgent), typeof(IgnoreUserAgentPlugin).Name);
                context.Cancel = true;
            }
        }
        public void Run(EventPluginContext context) {
            if (!context.Event.IsSessionStart() && !context.Event.IsSessionEnd() && !context.Event.IsSessionHeartbeat())
                return;

            var user = context.Event.GetUserIdentity();
            if (user != null && !String.IsNullOrEmpty(user.Identity))
                return;

            context.Log.Info("Cancelling session event as no user identity was specified.");
            context.Cancel = true;
        }
        public void Run(EventPluginContext context) {
            if (!context.Event.IsSessionStart())
                return;

            var user = context.Event.GetUserIdentity(context.Client.Configuration.Resolver.GetJsonSerializer());
            if (user != null && !String.IsNullOrEmpty(user.Identity))
                return;

            context.Log.Info("Cancelling session event as no user identity was specified.");
            context.Cancel = true;
        }
            public void Run(EventPluginContext context)
            {
                if (!context.ContextData.IsUnhandledError || !context.Event.IsError() || !context.ContextData.HasException())
                {
                    return;
                }

                var exception = context.ContextData.GetException();

                context.Cancel = exception?.GetType()?.IsAssignableFrom(typeof(RapicgenException)) != true;
            }
        public void Run(EventPluginContext context)
        {
            foreach (var callback in context.Client.Configuration.EventExclusions)
            {
                try {
                    if (!callback(context.Event))
                    {
                        context.Log.Info("Cancelling event from custom event exclusion.");
                        context.Cancel = true;
                        return;
                    }
                } catch (Exception ex) {
                    context.Log.Error(ex, "Error running custom event exclusion: " + ex.Message);
                }
            }

            if (context.Event.IsLog())
            {
                var minLogLevel = context.Client.Configuration.Settings.GetMinLogLevel(context.Event.Source);
                var logLevel    = LogLevel.FromString(context.Event.Data.GetValueOrDefault(Event.KnownDataKeys.Level, "Other").ToString());

                if (logLevel != LogLevel.Other && (logLevel == LogLevel.Off || logLevel < minLogLevel))
                {
                    context.Log.Info("Cancelling log event due to minimum log level.");
                    context.Cancel = true;
                }

                return;
            }

            if (!context.Client.Configuration.Settings.GetTypeAndSourceEnabled(context.Event.Type, context.Event.Source))
            {
                context.Log.Info(String.Format("Cancelling event from excluded type: {0} and source: {1}", context.Event.Type, context.Event.Source));
                context.Cancel = true;
                return;
            }

            try {
                var exception = context.ContextData.GetException();
                while (exception != null)
                {
                    if (!context.Client.Configuration.Settings.GetTypeAndSourceEnabled(Event.KnownTypes.Error, exception.GetType().FullName))
                    {
                        context.Log.Info("Cancelling error from excluded exception type: " + exception.GetType().FullName);
                        context.Cancel = true;
                        return;
                    }

                    exception = exception.InnerException;
                }
            } catch (Exception ex) {
                context.Log.Error(ex, "Error checking excluded exception types: " + ex.Message);
            }
        }
예제 #18
0
        public void ConfigurationDefaults_SerializedProperties()
        {
            var client = new ExceptionlessClient();

            client.Configuration.DefaultData.Add(Event.KnownDataKeys.EnvironmentInfo, new EnvironmentInfo {
                MachineName = "blake"
            });
            client.Configuration.DefaultData.Add(Event.KnownDataKeys.Error, new Error {
                Message = "blake"
            });
            client.Configuration.DefaultData.Add(Event.KnownDataKeys.Level, "Debug");
            client.Configuration.DefaultData.Add(Event.KnownDataKeys.ManualStackingKey, "blake");
            client.Configuration.DefaultData.Add(Event.KnownDataKeys.RequestInfo, new RequestInfo {
                Host = "blake"
            });
            client.Configuration.DefaultData.Add(Event.KnownDataKeys.SimpleError, new SimpleError {
                Message = "blake"
            });
            client.Configuration.DefaultData.Add(Event.KnownDataKeys.SubmissionMethod, "test");
            client.Configuration.DefaultData.Add(Event.KnownDataKeys.TraceLog, new List <string>());
            client.Configuration.DefaultData.Add(Event.KnownDataKeys.UserDescription, new UserDescription("*****@*****.**", "blake"));
            client.Configuration.DefaultData.Add(Event.KnownDataKeys.UserInfo, new UserInfo("blake"));
            client.Configuration.DefaultData.Add(Event.KnownDataKeys.Version, "1.0");

            var serializer = client.Configuration.Resolver.GetJsonSerializer();
            var context    = new EventPluginContext(client, new Event());
            var plugin     = new ConfigurationDefaultsPlugin();

            plugin.Run(context);
            Assert.Equal(11, context.Event.Data.Count);
            Assert.True(context.Event.Data[Event.KnownDataKeys.EnvironmentInfo] is string);
            Assert.Equal("blake", context.Event.GetEnvironmentInfo().MachineName);
            Assert.Equal("blake", context.Event.GetEnvironmentInfo(serializer).MachineName);
            Assert.True(context.Event.Data[Event.KnownDataKeys.Error] is string);
            Assert.Equal("blake", context.Event.GetError().Message);
            Assert.Equal("blake", context.Event.GetError(serializer).Message);
            Assert.Equal("Debug", context.Event.Data[Event.KnownDataKeys.Level]);
            Assert.Equal("blake", context.Event.Data[Event.KnownDataKeys.ManualStackingKey]);
            Assert.True(context.Event.Data[Event.KnownDataKeys.RequestInfo] is string);
            Assert.Equal("blake", context.Event.GetRequestInfo().Host);
            Assert.Equal("blake", context.Event.GetRequestInfo(serializer).Host);
            Assert.True(context.Event.Data[Event.KnownDataKeys.SimpleError] is string);
            Assert.Equal("blake", context.Event.GetSimpleError().Message);
            Assert.Equal("blake", context.Event.GetSimpleError(serializer).Message);
            Assert.Equal("test", context.Event.Data[Event.KnownDataKeys.SubmissionMethod]);
            Assert.True(context.Event.Data[Event.KnownDataKeys.TraceLog] is string);
            Assert.True(context.Event.Data[Event.KnownDataKeys.UserDescription] is string);
            Assert.Equal("blake", context.Event.GetUserDescription().Description);
            Assert.Equal("blake", context.Event.GetUserDescription(serializer).Description);
            Assert.True(context.Event.Data[Event.KnownDataKeys.UserInfo] is string);
            Assert.Equal("blake", context.Event.GetUserIdentity().Identity);
            Assert.Equal("blake", context.Event.GetUserIdentity(serializer).Identity);
            Assert.Equal("1.0", context.Event.Data[Event.KnownDataKeys.Version]);
        }
예제 #19
0
        public void Run(EventPluginContext context)
        {
            foreach (string tag in context.Client.Configuration.DefaultTags)
            {
                context.Event.Tags.Add(tag);
            }

            foreach (var data in context.Client.Configuration.DefaultData)
            {
                context.Event.Data[data.Key] = data.Value;
            }
        }
예제 #20
0
        public void EnvironmentInfo_IncorrectEventType(string eventType)
        {
            var client  = new ExceptionlessClient();
            var context = new EventPluginContext(client, new Event {
                Type = eventType
            });

            var plugin = new EnvironmentInfoPlugin();

            plugin.Run(context);
            Assert.Equal(0, context.Event.Data.Count);
        }
예제 #21
0
        public void Run(EventPluginContext context)
        {
            var exception = context.ContextData.GetException();

            if (exception == null)
            {
                return;
            }

            context.Event.Type = Event.KnownTypes.Error;
            context.Event.Data[Event.KnownDataKeys.SimpleError] = exception.ToSimpleErrorModel();
        }
예제 #22
0
 public void Run(EventPluginContext context)
 {
     try {
         int maxEntriesToInclude = context.Client.Configuration.Settings.GetInt32(MaxEntriesToIncludeKey, DefaultMaxEntriesToInclude);
         if (maxEntriesToInclude > 0)
         {
             AddRecentTraceLogEntries(context.Event, _listener, maxEntriesToInclude);
         }
     } catch (Exception ex) {
         context.Log.FormattedError(typeof(TraceLogPlugin), ex, "Error adding trace information: {0}", ex.Message);
     }
 }
예제 #23
0
        public void EnvironmentInfo_ShouldAddSessionStart()
        {
            var client  = new ExceptionlessClient();
            var context = new EventPluginContext(client, new Event {
                Type = Event.KnownTypes.SessionStart
            });

            var plugin = new EnvironmentInfoPlugin();

            plugin.Run(context);
            Assert.Equal(1, context.Event.Data.Count);
            Assert.NotNull(context.Event.Data[Event.KnownDataKeys.EnvironmentInfo]);
        }
예제 #24
0
        public void ShouldAddSessionStart()
        {
            var client  = CreateClient();
            var context = new EventPluginContext(client, new Event {
                Type = Event.KnownTypes.Session
            });

            var plugin = new EnvironmentInfoPlugin();

            plugin.Run(context);
            Assert.Single(context.Event.Data);
            Assert.NotNull(context.Event.Data[Event.KnownDataKeys.EnvironmentInfo]);
        }
예제 #25
0
        public void Run(EventPluginContext context)
        {
            // Only update feature usage events.
            if (context.Event.Type != Event.KnownTypes.FeatureUsage)
            {
                return;
            }

            var uptime = TimeSpan.FromSeconds((double)Stopwatch.GetTimestamp() / Stopwatch.Frequency);

            // Store the system uptime as an extended property.
            context.Event.SetProperty("System Uptime", $"{uptime.Days} Days {uptime.Hours} Hours {uptime.Minutes} Minutes {uptime.Seconds} Seconds");
        }
예제 #26
0
        public void WillRespectIncludeUserName()
        {
            var client = CreateClient(c => c.IncludeUserName = false);
            var plugin = new SetEnvironmentUserPlugin();

            var context = new EventPluginContext(client, new Event {
                Type = Event.KnownTypes.Log, Message = "test"
            });

            plugin.Run(context);

            Assert.Null(context.Event.GetUserIdentity());
        }
예제 #27
0
        public void Run(EventPluginContext context) {
            var exception = context.ContextData.GetException();
            if (exception == null)
                return;

            if (exception.IsProcessed()) {
                context.Cancel = true;
                return;
            }
            
            context.Event.Type = Event.KnownTypes.Error;
            context.Event.Data[Event.KnownDataKeys.Error] = exception.ToErrorModel(context.Client);
            exception.MarkProcessed();
        }
        /// <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) {
                _log.Value.FormattedInfo(typeof(ExceptionlessClient), "Event submission cancelled by event pipeline: refid={0} type={1} message={2}", ev.ReferenceId, ev.Type, ev.Message);
                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: refid={0} type={1} message={2}", ev.ReferenceId, ev.Type, ev.Message);
                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)) {
                _log.Value.FormattedTrace(typeof(ExceptionlessClient), "Setting last reference id: {0}", ev.ReferenceId);
                _lastReferenceIdManager.Value.SetLast(ev.ReferenceId);
            }

            OnSubmittedEvent(new EventSubmittedEventArgs(this, ev, pluginContextData));
        }
        public void Run(EventPluginContext context)
        {
            if (!context.Client.Configuration.IncludeUserName)
            {
                return;
            }

            var user = context.Event.GetUserIdentity(context.Client.Configuration.Resolver.GetJsonSerializer());

            if (user == null)
            {
                context.Event.SetUserIdentity(Environment.UserName);
            }
        }
        public void CancelSessionsWithNoUserTest(string eventType, string identity, bool cancelled)
        {
            var ev = new Event {
                Type = eventType
            };

            ev.SetUserIdentity(identity);

            var context = new EventPluginContext(CreateClient(), ev);
            var plugin  = new CancelSessionsWithNoUserPlugin();

            plugin.Run(context);
            Assert.Equal(cancelled, context.Cancel);
        }
        public void Run(EventPluginContext context)
        {
            var request = context.Event.GetRequestInfo(context.Client.Configuration.Resolver.GetJsonSerializer());

            if (request == null)
            {
                return;
            }

            if (request.UserAgent.AnyWildcardMatches(context.Client.Configuration.UserAgentBotPatterns, true))
            {
                context.Log.Info(String.Concat("Cancelling event as the request infos user agent matches a known bot pattern: ", request.UserAgent), typeof(IgnoreUserAgentPlugin).Name);
                context.Cancel = true;
            }
        }
예제 #32
0
        public void LargeEventsFromFiles()
        {
            foreach (var ev in _events)
            {
                var pluginContextData = new ContextData();

                for (int index = 0; index < 2; index++)
                {
                    var context = new EventPluginContext(_client, ev, pluginContextData);

                    _errorPlugin.Run(context);
                    _duplicateCheckerPlugin.Run(context);
                }
            }
        }
예제 #33
0
        public void Run(EventPluginContext context)
        {
            foreach (string tag in context.Client.Configuration.DefaultTags)
            {
                context.Event.Tags.Add(tag);
            }

            foreach (var data in context.Client.Configuration.DefaultData)
            {
                if (!context.Event.Data.ContainsKey(data.Key))
                {
                    context.Event.SetProperty(data.Key, data.Value, client: context.Client);
                }
            }
        }
        public void EnvironmentInfo_CanRunInParallel()
        {
            var client = CreateClient();
            var ev     = new Event {
                Type = Event.KnownTypes.Session
            };
            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]);
            });
        }
        public void PrivateInformation_WillSetIdentity()
        {
            var client = CreateClient();
            var plugin = new SetEnvironmentUserPlugin();

            var context = new EventPluginContext(client, new Event {
                Type = Event.KnownTypes.Log, Message = "test"
            });

            plugin.Run(context);

            var user = context.Event.GetUserIdentity();

            Assert.Equal(Environment.UserName, user.Identity);
        }
        private static void AddUser(EventPluginContext context, HttpActionContext actionContext, IJsonSerializer serializer)
        {
            var user = context.Event.GetUserIdentity(serializer);

            if (user != null)
            {
                return;
            }

            var principal = GetPrincipal(actionContext != null ? actionContext.Request : null);

            if (principal != null && principal.Identity.IsAuthenticated)
            {
                context.Event.SetUserIdentity(principal.Identity.Name);
            }
        }
        public void Run(EventPluginContext context)
        {
            if (!context.ContextData.HasException())
            {
                return;
            }

            var exception = context.ContextData.GetException();

            if (exception is ServerException)
            {
                var field = typeof(Exception).GetField("_remoteStackTraceString",
                                                       BindingFlags.NonPublic | BindingFlags.Instance);
                context.Event.SetProperty("Server Stack Trace", field.GetValue(exception));
            }
        }
        public void Run(EventPluginContext context)
        {
            if (!context.ContextData.HasException())
            {
                return;
            }

            var exception         = context.ContextData.GetException();
            var typeLoadException = exception as ReflectionTypeLoadException;

            if (typeLoadException != null)
            {
                var loaderExceptions = typeLoadException.LoaderExceptions;
                context.Event.SetProperty("Loader Exceptions", string.Join("\r\n\r\n", loaderExceptions.Select(x => x.ToString())));
            }
        }
        public void Run(EventPluginContext context) {
            if (context.Event.Data.ContainsKey(Event.KnownDataKeys.EnvironmentInfo))
                return;
            
            try {
                var collector = context.Resolver.GetEnvironmentInfoCollector();
                if (collector == null)
                    return;

                var info = collector.GetEnvironmentInfo();
                info.InstallId = context.Client.Configuration.GetInstallId();
                context.Event.Data[Event.KnownDataKeys.EnvironmentInfo] = info;
            } catch (Exception ex) {
                context.Log.FormattedError(typeof(EnvironmentInfoPlugin), ex, "Error adding environment information: {0}", ex.Message);
            }
        }
예제 #40
0
        public void Run(EventPluginContext context)
        {
            if (context.Event.IsSessionStart() || String.IsNullOrEmpty(context.Client.Configuration.CurrentSessionIdentifier))
            {
                context.Client.Configuration.CurrentSessionIdentifier = Guid.NewGuid().ToString("N");
            }

            if (context.Event.IsSessionStart())
            {
                context.Event.ReferenceId = context.Client.Configuration.CurrentSessionIdentifier;
            }
            else
            {
                context.Event.SetEventReference("session", context.Client.Configuration.CurrentSessionIdentifier);
            }
        }
        public void Run(EventPluginContext context)
        {
            if (context.Event.IsSessionHeartbeat())
            {
                return;
            }

            if (context.Event.IsSessionEnd())
            {
                if (_heartbeat != null)
                {
                    _heartbeat.Dispose();
                    _heartbeat = null;
                }

                return;
            }

            var user = context.Event.GetUserIdentity(context.Client.Configuration.Resolver.GetJsonSerializer());

            if (user == null || String.IsNullOrEmpty(user.Identity))
            {
                return;
            }

            if (_heartbeat == null)
            {
                _heartbeat = new SessionHeartbeat(user, context.Client);
            }
            else if (_heartbeat.User.Identity != user.Identity)
            {
                if (_heartbeat != null)
                {
                    _heartbeat.Dispose();
                }

                _heartbeat = new SessionHeartbeat(user, context.Client);
            }
            else
            {
                if (_heartbeat != null)
                {
                    _heartbeat.DelayNext();
                }
            }
        }
        public void Run(EventPluginContext context) {
            foreach (var callback in context.Client.Configuration.EventExclusions) {
                try {
                    if (!callback(context.Event)) {
                        context.Log.Info("Cancelling event from custom event exclusion.");
                        context.Cancel = true;
                        return;
                    }
                } catch (Exception ex) {
                    context.Log.Error(ex, "Error running custom event exclusion: " + ex.Message);
                }
            }

            if (context.Event.IsLog()) {
                var minLogLevel = context.Client.Configuration.Settings.GetMinLogLevel(context.Event.Source);
                var logLevel = LogLevel.FromString(context.Event.Data.GetValueOrDefault(Event.KnownDataKeys.Level, "Other").ToString());

                if (logLevel != LogLevel.Other && (logLevel == LogLevel.Off || logLevel < minLogLevel)) {
                    context.Log.Info("Cancelling log event due to minimum log level.");
                    context.Cancel = true;
                }

                return;
            }

            if (!context.Client.Configuration.Settings.GetTypeAndSourceEnabled(context.Event.Type, context.Event.Source)) {
                context.Log.Info(String.Format("Cancelling event from excluded type: {0} and source: {1}", context.Event.Type, context.Event.Source));
                context.Cancel = true;
                return;
            }
            
            try {
                var exception = context.ContextData.GetException();
                while (exception != null) {
                    if (!context.Client.Configuration.Settings.GetTypeAndSourceEnabled(Event.KnownTypes.Error, exception.GetType().FullName)) {
                        context.Log.Info("Cancelling error from excluded exception type: " + exception.GetType().FullName);
                        context.Cancel = true;
                        return;
                    }

                    exception = exception.InnerException;
                }
            } catch (Exception ex) {
                context.Log.Error(ex, "Error checking excluded exception types: " + ex.Message);
            }
        }
        private static void AddUser(EventPluginContext context, HttpContext httpContext, IJsonSerializer serializer)
        {
            var user = context.Event.GetUserIdentity(serializer);

            if (user != null)
            {
                return;
            }

            // TODO: Should we fall back to Thread.CurrentPrincipal?
            var principal = httpContext?.User;

            if (principal != null && principal.Identity.IsAuthenticated)
            {
                context.Event.SetUserIdentity(principal.Identity.Name);
            }
        }
        public void Run(EventPluginContext context) {
            //TODO: This needs to be uncommented when the client is sending session start and end.
            if (context.Event.Data.ContainsKey(Event.KnownDataKeys.EnvironmentInfo)) // || context.Event.Type != Event.KnownTypes.SessionStart)
                return;

            try {
                var collector = context.Resolver.GetEnvironmentInfoCollector();
                if (collector == null)
                    return;

                var info = collector.GetEnvironmentInfo();
                info.InstallId = context.Client.Configuration.GetInstallId();
                context.Event.Data.Add(Event.KnownDataKeys.EnvironmentInfo, info);
            } catch (Exception ex) {
                context.Log.FormattedError(typeof(EnvironmentInfoPlugin), ex, "Error adding environment information: {0}", ex.Message);
            }
        }
예제 #45
0
        public void Run(EventPluginContext context)
        {
            if (!context.Event.IsSessionStart() && !context.Event.IsSessionEnd() && !context.Event.IsSessionHeartbeat())
            {
                return;
            }

            var user = context.Event.GetUserIdentity(context.Client.Configuration.Resolver.GetJsonSerializer());

            if (user != null && !String.IsNullOrEmpty(user.Identity))
            {
                return;
            }

            context.Log.Info("Cancelling session event as no user identity was specified.");
            context.Cancel = true;
        }
        public void EventExclusionPlugin_SourceType(string type, string source, string settingKey, string settingValue, bool cancelled)
        {
            var client = CreateClient();

            if (settingKey != null)
            {
                client.Configuration.Settings.Add(settingKey, settingValue);
            }

            var ev = new Event {
                Type = type, Source = source
            };
            var context = new EventPluginContext(client, ev);
            var plugin  = new EventExclusionPlugin();

            plugin.Run(context);
            Assert.Equal(cancelled, context.Cancel);
        }
예제 #47
0
        public void CanCancel()
        {
            var client = new ExceptionlessClient();

            foreach (var plugin in client.Configuration.Plugins)
            {
                client.Configuration.RemovePlugin(plugin.Key);
            }

            client.Configuration.AddPlugin("cancel", 1, ctx => ctx.Cancel = true);
            client.Configuration.AddPlugin("add-tag", 2, ctx => ctx.Event.Tags.Add("Was Not Canceled"));

            var context = new EventPluginContext(client, new Event());

            EventPluginManager.Run(context);
            Assert.True(context.Cancel);
            Assert.Equal(0, context.Event.Tags.Count);
        }
        public void Run(EventPluginContext context) {
            if (String.IsNullOrEmpty(context.Client.Configuration.CurrentSessionIdentifier)) {
                var user = context.Event.GetUserIdentity(context.Client.Configuration.Resolver.GetJsonSerializer());
                if (user == null || String.IsNullOrEmpty(user.Identity))
                    return;

                context.Client.Configuration.CurrentSessionIdentifier = user.Identity;
            }

            if (_heartbeat == null) {
                _heartbeat = new SessionHeartbeat(context.Client.Configuration.CurrentSessionIdentifier, _interval, context.Client);
            } else if (_heartbeat.SessionIdentifier != context.Client.Configuration.CurrentSessionIdentifier) {
                if (_heartbeat != null)
                    _heartbeat.Dispose();

                _heartbeat = new SessionHeartbeat(context.Client.Configuration.CurrentSessionIdentifier, _interval, context.Client);
            } else {
                if (_heartbeat != null)
                    _heartbeat.DelayNext();
            }
        }
        public void Run(EventPluginContext context) {
            var aggregateException = context.ContextData.GetException() as AggregateException;
            if (aggregateException == null)
                return;

            var exception = aggregateException.Flatten();
            if (exception.InnerExceptions.Count == 1) {
                context.ContextData.SetException(exception.InnerException);
                return;
            }

            foreach (var ex in exception.InnerExceptions) {
                var ctx = new ContextData(context.ContextData);
                ctx.SetException(ex);

                var serializer = context.Resolver.GetJsonSerializer();
                context.Client.SubmitEvent(serializer.Deserialize(serializer.Serialize(context.Event), typeof(Event)) as Event, ctx);
            }

            context.Cancel = true;
        }
 public void Run(EventPluginContext context) {
     string submissionMethod = context.ContextData.GetSubmissionMethod();
     if (!String.IsNullOrEmpty(submissionMethod))
         context.Event.AddObject(submissionMethod, Event.KnownDataKeys.SubmissionMethod);
 }
        public void Run(EventPluginContext context) {
            if (!String.IsNullOrEmpty(context.Event.ReferenceId) || context.Event.Type != Event.KnownTypes.Error)
                return;

            context.Event.ReferenceId = Guid.NewGuid().ToString("N").Substring(0, 10);
        }
 public MergedEvent(int hashCode, EventPluginContext context, int count) {
     HashCode = hashCode;
     _context = context;
     _count = count;
 }