Beispiel #1
0
        public override RaygunClient GetClient(RaygunSettings settings, HttpContext context)
        {
            var client = base.GetClient(settings, context);

            client.ApplicationVersion = "1.1.0";

            var identity = context?.User?.Identity as ClaimsIdentity;

            if (identity?.IsAuthenticated == true)
            {
                // Get info from authentication cookie
                var email = identity.Claims.Where(c => c.Type == ClaimTypes.Email).Select(c => c.Value).FirstOrDefault();

                client.UserInfo = new RaygunIdentifierMessage(email)
                {
                    IsAnonymous = false,
                    Email       = email,
                    FullName    = identity.Name
                };
            }

            client.SendingMessage += (sender, args) =>
            {
                // Setting the processor count as an example as I know this is never set by the provider.
                args.Message.Details.Environment.ProcessorCount = 4;
            };

            return(client);
        }
Beispiel #2
0
 public virtual void SetupErrorHandling(RaygunSettings settings)
 {
     TaskScheduler.UnobservedTaskException += (sender, args) =>
     {
         ReportError(settings, args.Exception);
     };
 }
        public override RaygunClient GetClient(RaygunSettings settings)
        {
            var client = base.GetClient(settings);

            settings.ApiKey = Config.RayGunApiKey;

            return(client);
        }
Beispiel #4
0
        public void SetUp()
        {
            RaygunSettings settings = new RaygunSettings("");

            _rumService = new RUMService(settings);
            _rumService.Enable();

            _customUserInfo = new RaygunUserInfo("Ronald_Raygun");
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RaygunFeatureUsageTrackingSession"/> class.
 /// </summary>
 /// <param name="featureName">Name of the feature.</param>
 /// <param name="raygunClient">Raygun client instance.</param>
 /// <param name="raygunSettings">Raygun settings instance.</param>
 public RaygunFeatureUsageTrackingSession(
     string featureName,
     RaygunClient raygunClient,
     RaygunSettings raygunSettings)
     : this(
         featureName,
         Guid.Empty,
         raygunClient,
         raygunSettings)
 {
 }
        /// <summary>
        /// Add the <see cref="RaygunClientHttpEnricher"/> to the enrichment configuration.
        /// </summary>
        /// <param name="enrich"></param>
        /// <param name="httpContextAccessor">Optional HttpContext accessor that provides access to the current requests HttpContext.</param>
        /// <param name="restrictedToMinimumLevel">Optional <see cref="LogEventLevel"/> to enrich log events. Defaults to LogEventLevel.Error.</param>
        /// <param name="raygunSettings">Optional <see cref="RaygunSettings"/> that is used to apply http data filtering.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static LoggerConfiguration WithHttpDataForRaygun(
            this LoggerEnrichmentConfiguration enrich,
            IHttpContextAccessor httpContextAccessor = null,
            LogEventLevel restrictedToMinimumLevel   = LogEventLevel.Error,
            RaygunSettings raygunSettings            = null)
        {
            if (enrich == null)
            {
                throw new ArgumentNullException(nameof(enrich));
            }

            return(enrich.With(new RaygunClientHttpEnricher(httpContextAccessor ?? new HttpContextAccessor(), restrictedToMinimumLevel, raygunSettings ?? new RaygunSettings())));
        }
Beispiel #7
0
        private static RaygunFeatureUsageTrackingSession GetRaygunFeatureUsageTrackingSession(string featureName)
        {
            var apiKey         = string.Empty;
            var raygunSettings = new RaygunSettings
            {
                ApiKey = apiKey
            };

#if NETSTANDARD2_0
            var raygunClient = new RaygunClient(raygunSettings);
#else
            var raygunClient = new RaygunClient(apiKey);
#endif

            return(new RaygunFeatureUsageTrackingSession(featureName, raygunClient, raygunSettings));
        }
        public App()
        {
            InitializeComponent();

            // Initialise the settings that will configure the Raygun client.
            var settings = new RaygunSettings("_API_KEY_")
            {
                LogLevel           = LogLevel.Verbose,
                BreadcrumbLevel    = RaygunBreadcrumbLevel.Debug,
                ApplicationVersion = "1.0.0",
                IgnoredViews       = new List <string>()
                {
                    "DebugView"
                },
                IgnoredUrls = new List <string>()
                {
                    "www.debug.com"
                },
            };

            // Initialise a client instance.
            var client = RaygunClient.Init(settings);

            client.BeforeSendingCrashReportEvent += BeforeSendingCrashReportEventHandler;

            // Setting tags that will be sent with every crash report.
            client.Tags = new List <string>()
            {
                "GlobalTag"
            };

            // Setting information that will be sent with every crash report.
            client.CustomData = new Dictionary <string, object>()
            {
                { "GlobalString", "Value" },
                { "GlobalValue", 123 }
            };

            // Enabling the products.
            client.EnableCrashReporting();
            client.EnableRealUserMonitoring();
            client.EnableNetworkPerformanceMonitoring();

            client.RecordBreadcrumb("Initialised Raygun", RaygunBreadcrumbType.Manual, RaygunBreadcrumbLevel.Debug);

            MainPage = new MainPage();
        }
Beispiel #9
0
        private RaygunSettings SutFactory(
            string endpoint         = null,
            string apiKey           = null,
            string tags             = null,
            string version          = null,
            bool?throwOnError       = null,
            bool?excludeLocalErrors = null)
        {
            ConfigurationManager.AppSettings["raygun:apiEndpoint"]            = endpoint;
            ConfigurationManager.AppSettings["raygun:apiKey"]                 = apiKey;
            ConfigurationManager.AppSettings["raygun:tags"]                   = tags;
            ConfigurationManager.AppSettings["raygun:applicationVersion"]     = version;
            ConfigurationManager.AppSettings["raygun:throwOnError"]           = throwOnError?.ToString();
            ConfigurationManager.AppSettings["raygun:excludeErrorsFromLocal"] = excludeLocalErrors?.ToString();

            return(RaygunSettings.LoadFromAppSettings());
        }
        //public override RaygunClient GetClient(RaygunSettings settings)
        public override RaygunClient GetClient(RaygunSettings settings, HttpContext context)
        {
            settings.ApiKey = _apiKey;

            var client = base.GetClient(settings, context);

            //client.SendingMessage += (sender, args) =>
            //{
            //    if (args.Message.Details.User == null)
            //    {
            //        // Possbily an unhandled exception because we "should" be supplying user data when we handle errors
            //        // todo: figure out a way to get the user information from the context here
            //        // NOTE:  when RG 5.3.2 gets its bug fixed we can get user info from the HTTP Context
            //        // related: https://raygun.com/forums/thread/65336#65335 &  https://raygun.com/forums/thread/65407
            //        args.Message.Details.User = new RaygunIdentifierMessage(UnhandledExceptionTag)
            //        {
            //            UUID = "abc123",
            //            Email = "*****@*****.**",
            //            FullName = "Ronald Raygun",
            //        };

            //        args.Message.Details.Tags = new[] { UnhandledExceptionTag };

            //    }

            //    // If you want to cancel the message based on some decision:
            //    // args.Cancel = true;
            //};


            // strip out all cookie info:
            client.IgnoreCookieNames("*");

            // strip addl fields that may have sensitive data in it
            client.IgnoreServerVariableNames("ALL_HTTP", "ALL_RAW", "HTTP_COOKIE");

            // strip out certain headers
            client.IgnoreHeaderNames("Connection", "Host");

            // ignore password field on the form
            client.IgnoreFormFieldNames("*password*");

            return(client);
        }
Beispiel #11
0
        public RaygunUnhandledExceptionMiddleware(AppFunc next, RaygunSettings settings)
        {
            if (next == null)
            {
                throw new ArgumentNullException("next");
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            _next = next;

            if (!string.IsNullOrEmpty(settings.ApiKey))
            {
                _client = new RaygunClient(settings);
            }
        }
Beispiel #12
0
        public override void SetupConfiguration(IAppBuilder app, RaygunSettings settings)
        {
            app.UseRaygun(options =>
            {
                options.LogUnhandledExceptions = true;
                options.LogUnhandledRequests   = true;
                options.Settings = settings;
            });

            app.Use((context, next) =>
            {
                if (context.Request.Path.StartsWithSegments(new PathString("/exception")))
                {
                    throw new NotImplementedException("Route: /exception");
                }

                return(next());
            });

            app.UseNancy(options =>
            {
                options.PerformPassThrough = context =>
                {
                    if (context.Response.StatusCode == HttpStatusCode.InternalServerError)
                    {
                        Exception exception;
                        if (context.TryGetException(out exception))
                        {
                            if (exception is RequestExecutionException)
                            {
                                exception = exception.InnerException;
                            }

                            ReportError(settings, context.GetOwinEnvironment(), exception);
                        }
                    }

                    return(false);
                };
            });
        }
Beispiel #13
0
        internal RaygunFeatureUsageTrackingSession(
            string featureName,
            Guid parentReference,
            RaygunClient raygunClient,
            RaygunSettings raygunSettings)
        {
            if (string.IsNullOrWhiteSpace(featureName))
            {
                throw new ArgumentNullException(nameof(featureName));
            }

            _raygunClient   = raygunClient;
            _raygunSettings = raygunSettings;

            ParentReference  = parentReference;
            FeatureName      = featureName;
            FeatureReference = Guid.NewGuid();

            var userCustomData = new Dictionary <string, string>
            {
                { "EventType", "FeatureUsage" },
                { "EventReference", FeatureReference.ToString() },
                { "ParentReference", parentReference.ToString() }
            };

            // keep an eye on
            // https://raygun.com/forums/thread/92182
#if NETSTANDARD2_0 || NET5_0
            var messageBuilder = RaygunMessageBuilder.New(raygunSettings)
#else
            var messageBuilder = RaygunMessageBuilder.New
#endif
                                 .SetClientDetails()
                                 .SetEnvironmentDetails()
                                 .SetUserCustomData(userCustomData);
            var raygunMessage = messageBuilder.Build();
            _raygunClient.SendInBackground(raygunMessage);
        }
        public override RaygunClient GetClient(RaygunSettings settings, HttpContext context)
        {
            var client = base.GetClient(settings, context);

            client.ApplicationVersion = "1.1.0";

            var identity = context?.User?.Identity as ClaimsIdentity;

            if (identity?.IsAuthenticated == true)
            {
                var email    = identity.Claims.Where(c => c.Type == ClaimTypes.Email).Select(c => c.Value).FirstOrDefault();
                var fullName = identity.Claims.Where(c => c.Type == ClaimTypes.Name).Select(c => c.Value).FirstOrDefault();

                client.UserInfo = new RaygunIdentifierMessage(email)
                {
                    IsAnonymous = false,
                    Email       = email,
                    FullName    = fullName //identity.Name
                };
            }

            return(client);
        }
Beispiel #15
0
        public override RaygunClient GetClient(RaygunSettings settings, HttpContext context)
        {
            var client = base.GetClient(settings, context);

            client.IgnoreFormFieldNames("*Password");
            client.ApplicationVersion = typeof(Program).Assembly.GetName().Version?.ToString(3);
            client.SendingMessage    += (_, args) =>
            {
                args.Message.Details.Tags ??= new List <string>();
                args.Message.Details.Tags.Add(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"));
            };

            var identity = context?.User?.Identity as ClaimsIdentity;

            if (identity?.IsAuthenticated == true)
            {
                client.UserInfo = new RaygunIdentifierMessage(identity.Name)
                {
                    IsAnonymous = false
                };
            }

            return(client);
        }
 private RaygunAspNetCoreMessageBuilder(RaygunSettings settings)
 {
     _raygunMessage = new RaygunMessage();
       _settings = settings;
 }
Beispiel #17
0
 public abstract void SetupConfiguration(IAppBuilder app, RaygunSettings settings);
Beispiel #18
0
 public virtual RaygunSettings GetRaygunSettings(RaygunSettings baseSettings)
 {
     return(baseSettings);
 }
 public static RaygunAspNetCoreMessageBuilder New(RaygunSettings settings)
 {
     return new RaygunAspNetCoreMessageBuilder(settings);
 }
Beispiel #20
0
 public virtual void ReportError(RaygunSettings settings, OwinEnvironment environment, Exception exception)
 {
     new RaygunClient(settings).SendInBackground(environment, exception);
 }
Beispiel #21
0
 public virtual RaygunClient GetClient(RaygunSettings settings)
 {
     return(new RaygunClient(settings));
 }
Beispiel #22
0
 private RaygunAspNetCoreMessageBuilder(RaygunSettings settings)
 {
     _raygunMessage = new RaygunMessage();
     _settings      = settings;
 }
        public static RaygunEnvironmentMessage Build(RaygunSettings settings)
        {
            RaygunEnvironmentMessage message = new RaygunEnvironmentMessage();

            try
            {
                DateTime now = DateTime.Now;
                message.UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours;
                message.Locale    = CultureInfo.CurrentCulture.DisplayName;
            }
            catch { }

            // The cross platform APIs for getting this information don't exist right now.
            // In the mean time, chuck conditionals around the whole thing.

#if NET451
            // Different environments can fail to load the environment details.
            // For now if they fail to load for whatever reason then just
            // swallow the exception. A good addition would be to handle
            // these cases and load them correctly depending on where its running.
            // see http://raygun.io/forums/thread/3655

            try
            {
                message.WindowBoundsWidth  = SystemInformation.VirtualScreen.Width;
                message.WindowBoundsHeight = SystemInformation.VirtualScreen.Height;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Error retrieving window dimensions: {0}", ex.Message);
            }

            try
            {
                ComputerInfo info = new ComputerInfo();
                message.OSVersion = info.OSVersion;

                bool mediumTrust = settings.MediumTrust || !HasUnrestrictedFeatureSet;

                if (!mediumTrust)
                {
                    // ProcessorCount cannot run in medium trust under net35, once we have
                    // moved to net40 minimum we can move this out of here
                    message.ProcessorCount          = Environment.ProcessorCount;
                    message.Architecture            = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
                    message.TotalPhysicalMemory     = (ulong)info.TotalPhysicalMemory / 0x100000; // in MB
                    message.AvailablePhysicalMemory = (ulong)info.AvailablePhysicalMemory / 0x100000;
                    message.TotalVirtualMemory      = info.TotalVirtualMemory / 0x100000;
                    message.AvailableVirtualMemory  = info.AvailableVirtualMemory / 0x100000;
                    message.DiskSpaceFree           = GetDiskSpace();
                    message.Cpu       = GetCpu();
                    message.OSVersion = GetOSVersion();
                }
            }
            catch (SecurityException)
            {
                System.Diagnostics.Trace.WriteLine("RaygunClient error: couldn't access environment variables. If you are running in Medium Trust, in web.config in RaygunSettings set mediumtrust=\"true\"");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Error retrieving environment info: {0}", ex.Message);
            }
#endif
            return(message);
        }
Beispiel #24
0
 public static RaygunAspNetCoreMessageBuilder New(RaygunSettings settings)
 {
     return(new RaygunAspNetCoreMessageBuilder(settings));
 }
        public static RaygunEnvironmentMessage Build(RaygunSettings settings)
        {
            RaygunEnvironmentMessage message = new RaygunEnvironmentMessage();

              try
              {
            DateTime now = DateTime.Now;
            message.UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours;
            message.Locale = CultureInfo.CurrentCulture.DisplayName;
              }
              catch { }

              // The cross platform APIs for getting this information don't exist right now.
              // In the mean time, chuck conditionals around the whole thing.

            #if NET451
              // Different environments can fail to load the environment details.
              // For now if they fail to load for whatever reason then just
              // swallow the exception. A good addition would be to handle
              // these cases and load them correctly depending on where its running.
              // see http://raygun.io/forums/thread/3655

              try
              {
            message.WindowBoundsWidth = SystemInformation.VirtualScreen.Width;
            message.WindowBoundsHeight = SystemInformation.VirtualScreen.Height;
              }
              catch (Exception ex)
              {
            System.Diagnostics.Trace.WriteLine("Error retrieving window dimensions: {0}", ex.Message);
              }

              try
              {
            ComputerInfo info = new ComputerInfo();
            message.OSVersion = info.OSVersion;

            bool mediumTrust = settings.MediumTrust || !HasUnrestrictedFeatureSet;

            if (!mediumTrust)
            {
              // ProcessorCount cannot run in medium trust under net35, once we have
              // moved to net40 minimum we can move this out of here
              message.ProcessorCount = Environment.ProcessorCount;
              message.Architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
              message.TotalPhysicalMemory = (ulong)info.TotalPhysicalMemory / 0x100000; // in MB
              message.AvailablePhysicalMemory = (ulong)info.AvailablePhysicalMemory / 0x100000;
              message.TotalVirtualMemory = info.TotalVirtualMemory / 0x100000;
              message.AvailableVirtualMemory = info.AvailableVirtualMemory / 0x100000;
              message.DiskSpaceFree = GetDiskSpace();
              message.Cpu = GetCpu();
              message.OSVersion = GetOSVersion();
            }
              }
              catch (SecurityException)
              {
            System.Diagnostics.Trace.WriteLine("RaygunClient error: couldn't access environment variables. If you are running in Medium Trust, in web.config in RaygunSettings set mediumtrust=\"true\"");
              }
              catch (Exception ex)
              {
            System.Diagnostics.Trace.WriteLine("Error retrieving environment info: {0}", ex.Message);
              }
            #endif
              return message;
        }
Beispiel #26
0
 public void ReportError(RaygunSettings settings, Exception exception)
 {
     ReportError(settings, null, exception);
 }
 public RaygunClientHttpEnricher(IHttpContextAccessor httpContextAccessor, LogEventLevel restrictedToMinimumLevel, RaygunSettings raygunSettings)
 {
     _httpContextAccessor      = httpContextAccessor;
     _restrictedToMinimumLevel = restrictedToMinimumLevel;
     _raygunSettings           = raygunSettings;
 }
Beispiel #28
0
 public void SetUp()
 {
     _settings = new RaygunSettings();
     _builder  = RaygunMessageBuilder.New(_settings);
 }