Exemplo n.º 1
0
        private static RB.IRollbar InitRollbar()
        {
            var cfg           = Instance.Rollbar;
            var rollbarConfig = new RB.RollbarConfig(cfg.AccessToken)
            {
                AccessToken         = cfg.AccessToken,
                Environment         = cfg.Environment,
                Enabled             = cfg.Enabled,
                MaxReportsPerMinute = cfg.MaxReportsPerMinute,
                ReportingQueueDepth = cfg.ReportingQueueDepth,
                ScrubFields         = cfg.ScrubFields
            };

            RB.RollbarLocator.RollbarInstance.Configure(rollbarConfig);

            return(RB.RollbarLocator.RollbarInstance);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Enqueues the data.
        /// </summary>
        /// <param name="dataObject">The data object.</param>
        /// <param name="level">The level.</param>
        /// <param name="custom">The custom.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="signal">The signal.</param>
        /// <returns>PayloadBundle.</returns>
        internal PayloadBundle EnqueueData(
            object dataObject,
            ErrorLevel level,
            IDictionary <string, object> custom,
            TimeSpan?timeout     = null,
            SemaphoreSlim signal = null
            )
        {
            // here is the last chance to decide if we need to actually send this payload
            // based on the current config settings and rate-limit conditions:
            if (string.IsNullOrWhiteSpace(this._config.AccessToken) ||
                this._config.Enabled == false ||
                (this._config.LogLevel.HasValue && level < this._config.LogLevel.Value) ||
                ((this._payloadQueue.AccessTokenQueuesMetadata != null) && this._payloadQueue.AccessTokenQueuesMetadata.IsTransmissionSuspended)
                )
            {
                // nice shortcut:
                return(null);
            }

            if (this._config.RethrowExceptionsAfterReporting)
            {
                System.Exception exception = dataObject as System.Exception;
                if (exception == null)
                {
                    if (dataObject is Data data && data.Body != null)
                    {
                        exception = data.Body.OriginalException;
                    }
                }

                if (exception != null)
                {
                    try
                    {
                        // Here we need to create another logger instance with similar config but configured not to re-throw.
                        // This would prevent infinite recursive calls (in case if we used this instance or any re-throwing instance).
                        // Because we will be re-throwing the exception after reporting, let's report it fully-synchronously.
                        // This logic is on a heavy side. But, fortunately, RethrowExceptionsAfterReporting is intended to be
                        // a development time option:
                        var config = new RollbarConfig();
                        config.Reconfigure(this._config);
                        config.RethrowExceptionsAfterReporting = false;
                        using (var rollbar = RollbarFactory.CreateNew(config))
                        {
                            rollbar.AsBlockingLogger(TimeSpan.FromSeconds(1)).Log(level, dataObject, custom);
                        }
                    }
                    catch
                    {
                        // In case there was a TimeoutException (or any un-expected exception),
                        // there is nothing we can do here.
                        // We tried our best...
                    }
                    finally
                    {
                        if (exception is AggregateException aggregateException)
                        {
                            exception = aggregateException.Flatten();
                            ExceptionDispatchInfo.Capture(
                                exception.InnerException).Throw();
                        }
                        else
                        {
                            ExceptionDispatchInfo.Capture(exception).Throw();
                        }
                    }

                    return(null);
                }
            }


            PayloadBundle payloadBundle = null;

            try
            {
                payloadBundle = CreatePayloadBundle(dataObject, level, custom, timeout, signal);
            }
            catch (System.Exception exception)
            {
                RollbarErrorUtility.Report(
                    this,
                    dataObject,
                    InternalRollbarError.BundlingError,
                    null,
                    exception,
                    payloadBundle
                    );
                return(null);
            }

            try
            {
                this._payloadQueue.Enqueue(payloadBundle);
            }
            catch (System.Exception exception)
            {
                RollbarErrorUtility.Report(
                    this,
                    dataObject,
                    InternalRollbarError.EnqueuingError,
                    null,
                    exception,
                    payloadBundle
                    );
            }

            return(payloadBundle);
        }
Exemplo n.º 3
0
        public RollbarClient(RollbarConfig config)
        {
            Assumption.AssertNotNull(config, nameof(config));

            Config = config;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommunicationEventArgs"/> class.
 /// </summary>
 /// <param name="config">The configuration.</param>
 /// <param name="payload">The payload.</param>
 /// <param name="response">The response.</param>
 public CommunicationEventArgs(RollbarConfig config, Payload payload, RollbarResponse response)
     : base(config, payload)
 {
     this.Response = response;
 }
Exemplo n.º 5
0
        public IRollbar Configure(RollbarConfig settings)
        {
            this._config.Reconfigure(settings);

            return(this);
        }