Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarLogger" /> class.
        /// </summary>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        internal RollbarLogger(IRollbarLoggerConfig?rollbarConfig)
        {
            Assumption.AssertTrue(RollbarInfrastructure.Instance.IsInitialized, nameof(RollbarInfrastructure.Instance.IsInitialized));

            if (RollbarTelemetryCollector.Instance != null &&
                !RollbarTelemetryCollector.Instance.IsAutocollecting
                )
            {
                RollbarTelemetryCollector.Instance.StartAutocollection();
            }

            if (rollbarConfig != null)
            {
                ValidateConfiguration(rollbarConfig);
                this._config = new RollbarLoggerConfig(this).Reconfigure(rollbarConfig);
            }
            else
            {
                this._config = new RollbarLoggerConfig(this);
            }

            // let's init proper Rollbar client:
            var rollbarClient = new RollbarClient(this);

            // let's init the corresponding queue and register it:
            this._payloadQueue = new PayloadQueue(this, rollbarClient);
            RollbarQueueController.Instance?.Register(this._payloadQueue);
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigAttributesPackageDecorator"/> class.
 /// </summary>
 /// <param name="packageToDecorate">The package to decorate.</param>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 public ConfigAttributesPackageDecorator(
     IRollbarPackage?packageToDecorate,
     IRollbarLoggerConfig rollbarConfig
     )
     : this(packageToDecorate, rollbarConfig, false)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpRequestMessagePackageDecorator"/> class.
 /// </summary>
 /// <param name="packageToDecorate">The package to decorate.</param>
 /// <param name="httpRequestMessage">The HTTP request message.</param>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 public HttpRequestMessagePackageDecorator(
     IRollbarPackage packageToDecorate,
     HttpRequestMessage httpRequestMessage,
     IRollbarLoggerConfig rollbarConfig
     )
     : this(packageToDecorate, httpRequestMessage, rollbarConfig, null, false)
 {
 }
Beispiel #4
0
        /// <summary>
        /// Configures the using specified settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <returns>IRollbar.</returns>
        public IRollbar Configure(IRollbarLoggerConfig settings)
        {
            ValidateConfiguration(settings);

            this._config.Reconfigure(settings);

            return(this);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpRequestMessagePackageDecorator"/> class.
 /// </summary>
 /// <param name="packageToDecorate">The package to decorate.</param>
 /// <param name="httpRequestMessage">The HTTP request message.</param>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 /// <param name="mustApplySynchronously">if set to <c>true</c> [must apply synchronously].</param>
 public HttpRequestMessagePackageDecorator(
     IRollbarPackage packageToDecorate,
     HttpRequestMessage httpRequestMessage,
     IRollbarLoggerConfig rollbarConfig,
     bool mustApplySynchronously
     )
     : this(packageToDecorate, httpRequestMessage, rollbarConfig, null, mustApplySynchronously)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpRequestMessagePackageDecorator"/> class.
 /// </summary>
 /// <param name="packageToDecorate">The package to decorate.</param>
 /// <param name="httpRequestMessage">The HTTP request message.</param>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 /// <param name="arbitraryKeyValuePairs">The arbitrary key value pairs.</param>
 public HttpRequestMessagePackageDecorator(
     IRollbarPackage packageToDecorate,
     HttpRequestMessage httpRequestMessage,
     IRollbarLoggerConfig rollbarConfig,
     IDictionary <string, object?>?arbitraryKeyValuePairs
     )
     : this(packageToDecorate, httpRequestMessage, rollbarConfig, arbitraryKeyValuePairs, false)
 {
 }
Beispiel #7
0
 /// <summary>
 /// Validates the configuration.
 /// </summary>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 private static void ValidateConfiguration(IRollbarLoggerConfig rollbarConfig)
 {
     switch (rollbarConfig)
     {
     case IValidatable v:
         Validator.Validate(v, InternalRollbarError.ConfigurationError, "Failed to configure using invalid configuration prototype!");
         break;
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RollbarLogger" /> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 /// <param name="rollbarOptions">The options.</param>
 /// <param name="httpContextAccessor">The HTTP context accessor.</param>
 public RollbarLogger(string name
                      , IRollbarLoggerConfig rollbarConfig
                      , RollbarOptions?rollbarOptions
                      , IHttpContextAccessor?httpContextAccessor
                      )
     : base(name, rollbarConfig, rollbarOptions)
 {
     this._httpContextAccessor = httpContextAccessor;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarLogger"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        /// <param name="rollbarOptions">The rollbar options.</param>
        public RollbarLogger(
            string name,
            IRollbarLoggerConfig rollbarConfig,
            RollbarOptions?rollbarOptions = default
            )
        {
            this._name = name;

            this._rollbarOptions = rollbarOptions ?? new RollbarOptions();

            this._rollbar = RollbarFactory.CreateNew(rollbarConfig);
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarClient"/> class.
        /// </summary>
        /// <param name="rollbarLoggerConfig">The rollbar logger configuration.</param>
        public RollbarClient(IRollbarLoggerConfig rollbarLoggerConfig)
            : base(rollbarLoggerConfig)
        {
            var httpClient =
                RollbarQueueController.Instance?.ProvideHttpClient(
                    rollbarLoggerConfig.HttpProxyOptions.ProxyAddress,
                    rollbarLoggerConfig.HttpProxyOptions.ProxyUsername,
                    rollbarLoggerConfig.HttpProxyOptions.ProxyPassword
                    );

            this.Set(httpClient);

            this._expectedPostToApiTimeout =
                RollbarInfrastructure.Instance.Config.RollbarInfrastructureOptions.PayloadPostTimeout;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpRequestMessagePackageDecorator"/> class.
        /// </summary>
        /// <param name="packageToDecorate">The package to decorate.</param>
        /// <param name="httpRequestMessage">The HTTP request message.</param>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        /// <param name="arbitraryKeyValuePairs">The arbitrary key value pairs.</param>
        /// <param name="mustApplySynchronously">if set to <c>true</c> [must apply synchronously].</param>
        public HttpRequestMessagePackageDecorator(
            IRollbarPackage packageToDecorate,
            HttpRequestMessage httpRequestMessage,
            IRollbarLoggerConfig rollbarConfig,
            IDictionary <string, object?>?arbitraryKeyValuePairs,
            bool mustApplySynchronously
            )
            : base(packageToDecorate, mustApplySynchronously)
        {
            Assumption.AssertNotNull(httpRequestMessage, nameof(httpRequestMessage));
            Assumption.AssertNotNull(rollbarConfig, nameof(rollbarConfig));

            this._httpRequestMessage     = httpRequestMessage;
            this._rollbarConfig          = rollbarConfig;
            this._arbitraryKeyValuePairs = arbitraryKeyValuePairs;
        }
        /// <summary>
        /// Sets the fixture up.
        /// </summary>
        //[TestInitialize]
        public virtual void SetupFixture()
        {
            RollbarUnitTestEnvironmentUtil.SetupLiveTestRollbarInfrastructure();

            RollbarDataSecurityOptions dataSecurityOptions = new RollbarDataSecurityOptions();

            dataSecurityOptions.ScrubFields = new string[] { "secret", "super_secret", };
            RollbarInfrastructure.Instance
            .Config
            .RollbarLoggerConfig
            .RollbarDataSecurityOptions
            .Reconfigure(dataSecurityOptions);

            this._loggerConfig = RollbarInfrastructure.Instance.Config.RollbarLoggerConfig;

            this.Reset();
        }
        /// <summary>
        /// Provides the live rollbar configuration.
        /// </summary>
        /// <param name="rollbarAccessToken">The rollbar access token.</param>
        /// <param name="rollbarEnvironment">The rollbar environment.</param>
        /// <returns>IRollbarConfig.</returns>
        protected IRollbarLoggerConfig ProvideLiveRollbarConfig(string rollbarAccessToken, string rollbarEnvironment)
        {
            if (this._loggerConfig == null)
            {
                RollbarDestinationOptions destinationOptions =
                    new RollbarDestinationOptions(rollbarAccessToken, rollbarEnvironment);

                RollbarDataSecurityOptions dataSecurityOptions = new RollbarDataSecurityOptions();
                dataSecurityOptions.ScrubFields = new string[] { "secret", "super_secret", };

                RollbarLoggerConfig loggerConfig = new RollbarLoggerConfig();
                loggerConfig.RollbarDestinationOptions.Reconfigure(destinationOptions);
                loggerConfig.RollbarDataSecurityOptions.Reconfigure(dataSecurityOptions);

                this._loggerConfig = loggerConfig;
            }
            return(this._loggerConfig);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarLogger" /> class.
        /// </summary>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        internal RollbarSingleThreadedLogger(IRollbarLoggerConfig?rollbarConfig)
        {
            if (rollbarConfig != null)
            {
                ValidateConfiguration(rollbarConfig);
                this._config = new RollbarLoggerConfig(this).Reconfigure(rollbarConfig);
            }
            else
            {
                this._config = new RollbarLoggerConfig(this);
            }

            HttpClient httpClient =
                HttpClientUtility.CreateHttpClient(
                    rollbarConfig?.HttpProxyOptions.ProxyAddress,
                    rollbarConfig?.HttpProxyOptions.ProxyUsername,
                    rollbarConfig?.HttpProxyOptions.ProxyPassword
                    );

            this._rollbarClient = new RollbarBlazorClient(this, httpClient);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarClientBase"/> class.
        /// </summary>
        /// <param name="rollbarLoggerConfig">The rollbar logger configuration.</param>
        /// <exception cref="Rollbar.RollbarException">
        /// Undefined destination end-point!
        /// </exception>
        protected RollbarClientBase(IRollbarLoggerConfig rollbarLoggerConfig)
        {
            Assumption.AssertNotNull(
                rollbarLoggerConfig,
                nameof(rollbarLoggerConfig)
                );
            Assumption.AssertNotNullOrEmpty(
                rollbarLoggerConfig.RollbarDestinationOptions.EndPoint,
                nameof(rollbarLoggerConfig.RollbarDestinationOptions.EndPoint)
                );

            if (string.IsNullOrWhiteSpace(rollbarLoggerConfig.RollbarDestinationOptions.EndPoint))
            {
                throw new RollbarException(InternalRollbarError.InfrastructureError, "Undefined destination end-point!");
            }

            this._rollbarLoggerConfig = rollbarLoggerConfig;

            this._payloadPostUri =
                new Uri($"{rollbarLoggerConfig.RollbarDestinationOptions.EndPoint}item/");

            var sp =
                ServicePointManager.FindServicePoint(
                    new Uri(rollbarLoggerConfig.RollbarDestinationOptions.EndPoint)
                    );

            try
            {
                sp.ConnectionLeaseTimeout = 60 * 1000; // 1 minute
            }
            catch (NotImplementedException)
            {
                // just a crash prevention.
                // this is a work around the unimplemented property within Mono runtime...
            }

            this._payloadScrubber = new(rollbarLoggerConfig.RollbarDataSecurityOptions.GetFieldsToScrub());

            this._payloadTruncator = new(null);
        }
Beispiel #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigAttributesPackageDecorator"/> class.
        /// </summary>
        /// <param name="packageToDecorate">The package to decorate.</param>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        /// <param name="mustApplySynchronously">if set to <c>true</c> [must apply synchronously].</param>
        public ConfigAttributesPackageDecorator(
            IRollbarPackage?packageToDecorate,
            IRollbarLoggerConfig rollbarConfig,
            bool mustApplySynchronously
            )
            : base(packageToDecorate, mustApplySynchronously)
        {
            Assumption.AssertNotNull(rollbarConfig, nameof(rollbarConfig));

            this._rollbarConfig = rollbarConfig;

            // telemetry data is based on the configuration,
            // so let's include it if applicable:
            if (RollbarTelemetryCollector.Instance != null &&
                RollbarTelemetryCollector.Instance.Config != null &&
                RollbarTelemetryCollector.Instance.Config.TelemetryEnabled
                )
            {
                this._capturedTelemetryRecords =
                    RollbarTelemetryCollector.Instance.GetQueueContent();
            }
        }
Beispiel #17
0
        public void BasicPayloadBundleTest()
        {
            const int totalExceptionFrames = 5;

            System.Exception exceptionObj = ExceptionSimulator.GetExceptionWith(totalExceptionFrames);
            IRollbarPackage  package      = new ObjectPackage(exceptionObj, true);

            Assert.IsTrue(package.MustApplySynchronously);
            Assert.IsNull(package.RollbarData);
            //var rollbarData = package.PackageAsRollbarData();
            //Assert.AreSame(rollbarData, package.RollbarData);

            RollbarDestinationOptions destinationOptions =
                new RollbarDestinationOptions("ACCESS_TOKEN", "ENV");
            IRollbarLoggerConfig config = infrastructureConfig.RollbarLoggerConfig;

            config.RollbarDestinationOptions.Reconfigure(destinationOptions);
            using (IRollbar rollbarLogger = RollbarFactory.CreateNew(config))
            {
                PayloadBundle bundle  = new PayloadBundle(rollbarLogger as RollbarLogger, package, ErrorLevel.Critical);
                var           payload = bundle.GetPayload();
            }
        }
Beispiel #18
0
        /// <summary>
        /// Packages as payload data.
        /// </summary>
        /// <param name="utcTimestamp">The UTC timestamp of when the object-to-log was captured.</param>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        /// <param name="level">The level.</param>
        /// <param name="obj">The object.</param>
        /// <param name="custom">The custom.</param>
        /// <returns>Data.</returns>
        public static Data?PackageAsPayloadData(
            DateTime utcTimestamp,
            IRollbarLoggerConfig rollbarConfig,
            ErrorLevel level,
            object obj,
            IDictionary <string, object?>?custom = null
            )
        {
            if (!rollbarConfig.RollbarDeveloperOptions.Enabled)
            {
                // nice shortcut:
                return(null);
            }

            if (level < rollbarConfig.RollbarDeveloperOptions.LogLevel)
            {
                // nice shortcut:
                return(null);
            }

            Data?data = obj as Data;

            if (data != null)
            {
                //we do not have to update the timestamp of the data here
                //because we already have the incoming object to log of DTOs.Data type
                //so the timestamp value assigned during its construction should work better:
                data.Level = level;
                return(data);
            }

            IRollbarPackage?rollbarPackagingStrategy = obj as IRollbarPackage;

            if (rollbarPackagingStrategy != null)
            {
                data = rollbarPackagingStrategy.PackageAsRollbarData();
                if (data != null)
                {
                    data.Environment = rollbarConfig?.RollbarDestinationOptions.Environment;
                    data.Level       = level;
                    //update the data timestamp from the data creation timestamp to the passed
                    //object-to-log capture timestamp:
                    data.Timestamp = DateTimeUtil.ConvertToUnixTimestampInSeconds(utcTimestamp);
                }
                return(data);
            }

            Body?body = obj as Body;

            if (body == null)
            {
                body = RollbarUtility.PackageAsPayloadBody(obj, ref custom);
            }

            data       = new Data(rollbarConfig, body, custom);
            data.Level = level;
            //update the data timestamp from the data creation timestamp to the passed
            //object-to-log capture timestamp:
            data.Timestamp = DateTimeUtil.ConvertToUnixTimestampInSeconds(utcTimestamp);
            return(data);
        }
Beispiel #19
0
 /// <summary>
 /// Configures the using specified settings.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <returns>IRollbar.</returns>
 IRollbar IRollbar.Configure(IRollbarLoggerConfig settings)
 {
     return(this.Configure(settings));
 }