/// <summary> /// Configures the Rollbar singleton-like notifier. /// </summary> private void ConfigureRollbarInfrastructure() { RollbarInfrastructureConfig config = new RollbarInfrastructureConfig( RollbarSamplesSettings.AccessToken, RollbarSamplesSettings.Environment ); config.RollbarLoggerConfig.RollbarDeveloperOptions.LogLevel = ErrorLevel.Debug; //RollbarDataSecurityOptions dataSecurityOptions = new RollbarDataSecurityOptions(); //dataSecurityOptions.ScrubFields = new string[] //{ // "url", // "method", //}; //config.RollbarLoggerConfig.RollbarDataSecurityOptions.Reconfigure(dataSecurityOptions); var telemetryOptions = new RollbarTelemetryOptions(true, 20) { TelemetryAutoCollectionTypes = TelemetryType.Log | TelemetryType.Error | TelemetryType.Network }; config.RollbarTelemetryOptions.Reconfigure(telemetryOptions); RollbarInfrastructure.Instance.Init(config); RollbarInfrastructure.Instance.QueueController.InternalEvent += OnRollbarInternalEvent; var telemetryBody = new LogTelemetry("Rollbar infrastructure initialized!"); RollbarInfrastructure.Instance.TelemetryCollector.Capture(new Telemetry(TelemetrySource.Server, TelemetryLevel.Info, telemetryBody)); RollbarLocator.RollbarInstance.Info("Rollbar is ready to roll!"); }
/// <summary> /// Loads the application settings. /// </summary> /// <param name="telemetryConfig">The configuration.</param> /// <param name="telemetryConfigSection">The application settings.</param> /// <returns>false when the configuration was not found, otherwise true.</returns> public static bool LoadAppSettings(RollbarTelemetryOptions telemetryConfig, RollbarTelemetryConfigSection?telemetryConfigSection) { if (telemetryConfigSection == null) { return(false); } if (telemetryConfigSection.TelemetryEnabled.HasValue) { telemetryConfig.TelemetryEnabled = telemetryConfigSection.TelemetryEnabled.Value; } if (telemetryConfigSection.TelemetryQueueDepth.HasValue) { telemetryConfig.TelemetryQueueDepth = telemetryConfigSection.TelemetryQueueDepth.Value; } if (telemetryConfigSection.TelemetryAutoCollectionTypes.HasValue) { telemetryConfig.TelemetryAutoCollectionTypes = telemetryConfigSection.TelemetryAutoCollectionTypes.Value; } if (telemetryConfigSection.TelemetryAutoCollectionInterval.HasValue) { telemetryConfig.TelemetryAutoCollectionInterval = telemetryConfigSection.TelemetryAutoCollectionInterval.Value; } return(true); }
public void LoadRollbarTelemetryAppSettingsTest() { RollbarTelemetryOptions config = new RollbarTelemetryOptions(false, 5, TelemetryType.None, TimeSpan.FromMilliseconds(100)); Console.WriteLine(JsonConvert.SerializeObject(config)); Assert.AreEqual(false, config.TelemetryEnabled); Assert.AreEqual(5, config.TelemetryQueueDepth); Assert.AreEqual(TelemetryType.None, config.TelemetryAutoCollectionTypes); Assert.AreEqual(TimeSpan.FromMilliseconds(100), config.TelemetryAutoCollectionInterval); AppSettingsUtility.LoadAppSettings(config, Path.Combine(Environment.CurrentDirectory, "TestData"), "appsettings.json"); Console.WriteLine(JsonConvert.SerializeObject(config)); // The test data looks like this: //=============================== //"RollbarTelemetry": { // "TelemetryEnabled": true, // "TelemetryQueueDepth": 100, // "TelemetryAutoCollectionTypes": "Network, Log, Error", // "TelemetryAutoCollectionInterval": "00:00:00.3000000", //}, Assert.AreEqual(true, config.TelemetryEnabled); Assert.AreEqual(100, config.TelemetryQueueDepth); Assert.AreEqual(TelemetryType.Network | TelemetryType.Log | TelemetryType.Error, config.TelemetryAutoCollectionTypes); Assert.AreEqual(TimeSpan.FromMilliseconds(300), config.TelemetryAutoCollectionInterval); }
/// <summary> /// Loads the application settings. /// </summary> /// <param name="config">The configuration.</param> /// <param name="appSettings">The application settings.</param> /// <returns>false when the configuration was not found, otherwise true.</returns> public static bool LoadAppSettings(RollbarTelemetryOptions config, IConfiguration appSettings) { Assumption.AssertNotNull(config, nameof(config)); const string rollbarAppConfigSectionName = "RollbarTelemetry"; return(AppSettingsUtility.LoadAppSettings(config, rollbarAppConfigSectionName, appSettings)); }
/// <summary> /// Configures the Rollbar singleton-like notifier. /// </summary> private static void ConfigureRollbarSingleton() { // minimally required Rollbar configuration: RollbarInfrastructureConfig config = new RollbarInfrastructureConfig( RollbarSamplesSettings.AccessToken, RollbarSamplesSettings.Environment ); // optional: RollbarOfflineStoreOptions offlineStoreOptions = new RollbarOfflineStoreOptions(); offlineStoreOptions.EnableLocalPayloadStore = true; config.RollbarOfflineStoreOptions.Reconfigure(offlineStoreOptions); // optional: RollbarTelemetryOptions telemetryOptions = new RollbarTelemetryOptions(true, 3); config.RollbarTelemetryOptions.Reconfigure(telemetryOptions); // optional: //HttpProxyOptions proxyOptions = new HttpProxyOptions("http://something.com"); //config.RollbarLoggerConfig.HttpProxyOptions.Reconfigure(proxyOptions); // optional: RollbarDataSecurityOptions dataSecurityOptions = new RollbarDataSecurityOptions(); dataSecurityOptions.ScrubFields = new string[] { "access_token", // normally, you do not want scrub this specific field (it is operationally critical), but it just proves safety net built into the notifier... "username", "criticalObj[Sample.NetCore.ConsoleApp.Program+InstanceType]._baseNullField", "data.custom.criticalObj[Sample.NetCore.ConsoleApp.Program+InstanceType].<TypeName>k__BackingField", }; config.RollbarLoggerConfig.RollbarDataSecurityOptions.Reconfigure(dataSecurityOptions); // optional: RollbarPayloadAdditionOptions payloadAdditionOptions = new RollbarPayloadAdditionOptions(); payloadAdditionOptions.Person = new Person() { Id = "007", Email = "*****@*****.**", UserName = "******", }; config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Reconfigure(payloadAdditionOptions); // initialize the Rollbar Infrastructure: RollbarInfrastructure.Instance.Init(config); // optional step if you would like to monitor all Rollbar instances' internal events within your application: RollbarInfrastructure.Instance.QueueController.InternalEvent += OnRollbarInternalEvent; // optional step if you would like to monitor this Rollbar instance's internal events within your application: //RollbarLocator.RollbarInstance.InternalEvent += OnRollbarInternalEvent; }
/// <summary> /// Loads the telemetry configuration. /// </summary> /// <returns>ITelemetryConfig or null if no configuration store was found.</returns> public IRollbarTelemetryOptions?LoadTelemetryConfig() { RollbarTelemetryOptions config = new RollbarTelemetryOptions(); if (this.Load(config)) { return(config); } return(null); }
/// <summary> /// Loads the application settings. /// </summary> /// <param name="config">The configuration.</param> /// <param name="appSettingsFolderPath">The application settings folder path.</param> /// <param name="appSettingsFileName">Name of the application settings file.</param> /// <returns>false when the configuration was not found, otherwise true.</returns> public static bool LoadAppSettings(RollbarTelemetryOptions config, string appSettingsFolderPath, string appSettingsFileName) { Assumption.AssertNotNull(config, nameof(config)); IConfiguration?appSettingsConfig = AppSettingsUtility.LoadAppSettings(appSettingsFolderPath, appSettingsFileName); if (appSettingsConfig == null) { return(false); } AppSettingsUtility.LoadAppSettings(config, appSettingsConfig); return(true); }
public void TestTelemetryFixedQueueDepth() { RollbarTelemetryCollector.Instance.FlushQueue(); Assert.IsFalse(RollbarTelemetryCollector.Instance.IsAutocollecting); var config = RollbarTelemetryCollector.Instance.Config; var config1 = new RollbarTelemetryOptions(true, 10); config.Reconfigure(config1); List <dto.Telemetry> telemetryItems = new List <dto.Telemetry>(2 * config.TelemetryQueueDepth); while (telemetryItems.Count <= config.TelemetryQueueDepth) { telemetryItems.AddRange(GenerateTelemetryItems()); } Assert.IsTrue(config.TelemetryEnabled); Assert.AreEqual(0, RollbarTelemetryCollector.Instance.GetItemsCount()); Assert.IsTrue(telemetryItems.Count > config.TelemetryQueueDepth); foreach (var item in telemetryItems) { RollbarTelemetryCollector.Instance.Capture(item); } Assert.AreEqual(config.TelemetryQueueDepth, RollbarTelemetryCollector.Instance.GetItemsCount()); int oldCount = RollbarTelemetryCollector.Instance.GetItemsCount(); RollbarTelemetryCollector.Instance.FlushQueue(); Assert.AreEqual(0, RollbarTelemetryCollector.Instance.GetItemsCount()); var config2 = new RollbarTelemetryOptions(true, config1.TelemetryQueueDepth / 2); config.Reconfigure(config2); foreach (var item in telemetryItems) { RollbarTelemetryCollector.Instance.Capture(item); } Assert.AreEqual(config.TelemetryQueueDepth, RollbarTelemetryCollector.Instance.GetItemsCount()); Assert.IsTrue(oldCount > RollbarTelemetryCollector.Instance.GetItemsCount()); }
public void CustomTelemetryOptionsMakeIntoTelemetryCollector() { int expectedTelemetryQueueDepth = 20; var config = new RollbarInfrastructureConfig("access_token", "special_environment"); Assert.IsFalse(config.RollbarTelemetryOptions.TelemetryEnabled); Assert.IsTrue(config.RollbarTelemetryOptions.TelemetryQueueDepth != expectedTelemetryQueueDepth); Assert.IsTrue(config.RollbarTelemetryOptions.TelemetryAutoCollectionTypes == TelemetryType.None); var telemetryOptions = new RollbarTelemetryOptions(true, 20) { TelemetryAutoCollectionTypes = TelemetryType.Log | TelemetryType.Error | TelemetryType.Network }; config.RollbarTelemetryOptions.Reconfigure(telemetryOptions); if (RollbarInfrastructure.Instance.IsInitialized) { RollbarInfrastructure.Instance.Config.Reconfigure(config); } else { RollbarInfrastructure.Instance.Init(config); } Assert.IsTrue(RollbarInfrastructure.Instance.TelemetryCollector.Config.TelemetryEnabled); Assert.AreEqual(expectedTelemetryQueueDepth, RollbarInfrastructure.Instance.TelemetryCollector.Config.TelemetryQueueDepth); Assert.IsTrue((RollbarInfrastructure.Instance.TelemetryCollector.Config.TelemetryAutoCollectionTypes & TelemetryType.Log) == TelemetryType.Log); Assert.IsTrue((RollbarInfrastructure.Instance.TelemetryCollector.Config.TelemetryAutoCollectionTypes & TelemetryType.Error) == TelemetryType.Error); Assert.IsTrue((RollbarInfrastructure.Instance.TelemetryCollector.Config.TelemetryAutoCollectionTypes & TelemetryType.Network) == TelemetryType.Network); Assert.IsTrue((RollbarInfrastructure.Instance.TelemetryCollector.Config.TelemetryAutoCollectionTypes & TelemetryType.Manual) == TelemetryType.None); Assert.AreEqual(expectedTelemetryQueueDepth, RollbarInfrastructure.Instance.TelemetryCollector.QueueDepth); }
public void CustomTelemetryOptionsReconfigured() { int expectedTelemetryQueueDepth = 20; var config = new RollbarInfrastructureConfig("access_token", "special_environment"); Assert.IsFalse(config.RollbarTelemetryOptions.TelemetryEnabled); Assert.IsTrue(config.RollbarTelemetryOptions.TelemetryQueueDepth != expectedTelemetryQueueDepth); Assert.IsTrue(config.RollbarTelemetryOptions.TelemetryAutoCollectionTypes == TelemetryType.None); var telemetryOptions = new RollbarTelemetryOptions(true, 20) { TelemetryAutoCollectionTypes = TelemetryType.Log | TelemetryType.Error | TelemetryType.Network }; config.RollbarTelemetryOptions.Reconfigure(telemetryOptions); Assert.IsTrue(config.RollbarTelemetryOptions.TelemetryEnabled); Assert.AreEqual(expectedTelemetryQueueDepth, config.RollbarTelemetryOptions.TelemetryQueueDepth); Assert.IsTrue((config.RollbarTelemetryOptions.TelemetryAutoCollectionTypes & TelemetryType.Log) == TelemetryType.Log); Assert.IsTrue((config.RollbarTelemetryOptions.TelemetryAutoCollectionTypes & TelemetryType.Error) == TelemetryType.Error); Assert.IsTrue((config.RollbarTelemetryOptions.TelemetryAutoCollectionTypes & TelemetryType.Network) == TelemetryType.Network); Assert.IsTrue((config.RollbarTelemetryOptions.TelemetryAutoCollectionTypes & TelemetryType.Manual) == TelemetryType.None); }
/// <summary> /// Loads the provided configuration object based on found configuration store (if any). /// </summary> /// <param name="config">The configuration.</param> /// <returns><c>true</c> if configuration was found, <c>false</c> otherwise.</returns> public bool Load(RollbarTelemetryOptions config) { return(this._loader != null && this._loader.Load(config)); }
/// <summary> /// Loads the provided configuration object based on found configuration store (if any). /// </summary> /// <param name="config">The configuration.</param> /// <returns><c>true</c> if configuration was found, <c>false</c> otherwise.</returns> public bool Load(RollbarTelemetryOptions config) { return(AppSettingsUtility.LoadAppSettings(config)); }
/// <summary> /// Loads the application settings. /// </summary> /// <param name="telemetryConfig">The configuration.</param> /// <returns>false when the configuration was not found, otherwise true.</returns> public static bool LoadAppSettings(RollbarTelemetryOptions telemetryConfig) { return(AppConfigUtility.LoadAppSettings(telemetryConfig, RollbarTelemetryConfigSection.GetConfiguration())); }