Example #1
0
 public CallbackSetup(SentryOptions options) : this()
     => _options = options;
 public SystemWebRequestEventProcessor(IRequestPayloadExtractor payloadExtractor, SentryOptions options)
 {
     _options         = options ?? throw new ArgumentNullException(nameof(options));
     PayloadExtractor = payloadExtractor ?? throw new ArgumentNullException(nameof(payloadExtractor));
 }
 /// <summary>
 /// Creates an instance of <see cref="SentryStackTraceFactory"/>.
 /// </summary>
 public SentryStackTraceFactory(SentryOptions options) => _options = options;
 public AndroidNativeEventProcessor(SentryOptions options) => _options = options;
 internal UwpPlatformEventProcessor(SentryOptions options) => _options = options;
Example #6
0
 public BackgroundWorker(
     ITransport transport,
     SentryOptions options)
     : this(transport, options, null)
 {
 }
 /// <summary>
 /// Disables the integrations with DbInterception.
 /// </summary>
 /// <param name="options">The SentryOptions to remove the integration from.</param>
 public static void DisableDbInterceptionIntegration(this SentryOptions options)
 => DbIntegration?.Unregister();
        public void RequestBodyCompressionLevel_ByDefault_Optimal()
        {
            var sut = new SentryOptions();

            Assert.Equal(CompressionLevel.Optimal, sut.RequestBodyCompressionLevel);
        }
Example #9
0
 /// <summary>
 /// Log a debug message.
 /// </summary>
 internal static void LogDebug <TArg, TArg2>(
     this SentryOptions options,
     string message,
     TArg arg,
     TArg2 arg2)
 => options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Debug, null, message, arg, arg2);
Example #10
0
 /// <summary>
 /// Log a info message.
 /// </summary>
 internal static void LogInfo(
     this SentryOptions options,
     string message)
 => options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Info, null, message);
Example #11
0
 /// <summary>
 /// Log a warning message.
 /// </summary>
 internal static void LogFatal(
     this SentryOptions options,
     string message,
     Exception?exception = null)
 => options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Fatal, exception, message);
Example #12
0
 /// <summary>
 /// Log a error message.
 /// </summary>
 internal static void LogError <TArg>(
     this SentryOptions options,
     string message,
     Exception exception,
     TArg arg)
 => options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Error, exception, message, arg);
Example #13
0
 /// <summary>
 /// Log a warning message.
 /// </summary>
 internal static void LogWarning <TArg>(
     this SentryOptions options,
     string message,
     TArg arg)
 => options.DiagnosticLogger?.LogIfEnabled(SentryLevel.Warning, null, message, arg);
 public DuplicateEventDetectionEventProcessor(SentryOptions options) => _options = options;
 public NativeScopeObserver(SentryOptions options) : base("Native", options)
 {
 }
        public void DecompressionMethods_ByDefault_AllBitsSet()
        {
            var sut = new SentryOptions();

            Assert.Equal(~DecompressionMethods.None, sut.DecompressionMethods);
        }
        /// <summary>
        /// Creates an <see cref="T:System.Net.Http.HttpClient" /> configure to call Sentry for the specified <see cref="T:Sentry.Dsn" />
        /// </summary>
        /// <param name="options">The HTTP options.</param>
        public HttpClient Create(SentryOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var httpClientHandler = options.CreateHttpClientHandler?.Invoke() ?? new HttpClientHandler();

            if (options.HttpProxy != null)
            {
                httpClientHandler.Proxy = options.HttpProxy;
                options.LogInfo("Using Proxy: {0}", options.HttpProxy);
            }

            // If the platform supports automatic decompression
            if (httpClientHandler.SupportsAutomaticDecompression)
            {
                // if the SDK is configured to accept compressed data
                httpClientHandler.AutomaticDecompression = options.DecompressionMethods;
            }
            else
            {
                options.LogDebug("No response compression supported by HttpClientHandler.");
            }

            HttpMessageHandler handler = httpClientHandler;

            if (options.RequestBodyCompressionLevel != CompressionLevel.NoCompression)
            {
                if (options.RequestBodyCompressionBuffered)
                {
                    handler = new GzipBufferedRequestBodyHandler(handler, options.RequestBodyCompressionLevel);
                    options.LogDebug("Using 'GzipBufferedRequestBodyHandler' body compression strategy with level {0}.", options.RequestBodyCompressionLevel);
                }
                else
                {
                    handler = new GzipRequestBodyHandler(handler, options.RequestBodyCompressionLevel);
                    options.LogDebug("Using 'GzipRequestBodyHandler' body compression strategy with level {0}.", options.RequestBodyCompressionLevel);
                }
            }
            else
            {
                options.LogDebug("Using no request body compression strategy.");
            }

            // Adding retry after last for it to run first in the pipeline
            handler = new RetryAfterHandler(handler);

            var client = new HttpClient(handler);

            client.DefaultRequestHeaders.Add("Accept", "application/json");

            if (options.ConfigureClient is { } configureClient)
            {
                options.LogDebug("Invoking user-defined HttpClient configuration action.");
                configureClient.Invoke(client);
            }

            return(client);
        }
Example #18
0
 public Hub(SentryOptions options)
     : this(new SentryClient(options), options)
 {
 }
Example #19
0
 /// <summary>
 /// Creates an instance of <see cref="MonoSentryStackTraceFactory"/>.
 /// </summary>
 public MonoSentryStackTraceFactory(SentryOptions options) : base(options) => _options = options;
Example #20
0
 /// <summary>
 /// Creates a new instance of <see cref="RequestBodyExtractionDispatcher"/>.
 /// </summary>
 /// <param name="extractors">Extractors to use.</param>
 /// <param name="options">Sentry Options.</param>
 /// <param name="sizeSwitch">The max request size to capture.</param>
 public RequestBodyExtractionDispatcher(IEnumerable <IRequestPayloadExtractor> extractors, SentryOptions options, Func <RequestSize> sizeSwitch)
 {
     Extractors  = extractors ?? throw new ArgumentNullException(nameof(extractors));
     _options    = options ?? throw new ArgumentNullException(nameof(options));
     _sizeSwitch = sizeSwitch ?? throw new ArgumentNullException(nameof(sizeSwitch));
 }
Example #21
0
 public MainExceptionProcessor(SentryOptions options, Func <ISentryStackTraceFactory> sentryStackTraceFactoryAccessor)
 {
     _options = options;
     SentryStackTraceFactoryAccessor = sentryStackTraceFactoryAccessor;
 }
Example #22
0
        private async Task WorkerAsync(
            ConcurrentQueue <SentryEvent> queue,
            SentryOptions options,
            ITransport transport,
            SemaphoreSlim queuedEventSemaphore,
            CancellationToken cancellation)
        {
            var shutdownTimeout   = new CancellationTokenSource();
            var shutdownRequested = false;

            try
            {
                while (!shutdownTimeout.IsCancellationRequested)
                {
                    // If the cancellation was signaled,
                    // set the latest we can keep reading off of the queue (while there's still stuff to read)
                    // No longer synchronized with queuedEventSemaphore (Enqueue will throw object disposed),
                    // run until the end of the queue or shutdownTimeout
                    if (!shutdownRequested)
                    {
                        try
                        {
                            await queuedEventSemaphore.WaitAsync(cancellation).ConfigureAwait(false);
                        }
                        // Cancellation requested, scheduled shutdown but continue in case there are more items
                        catch (OperationCanceledException)
                        {
                            if (options.ShutdownTimeout == TimeSpan.Zero)
                            {
                                options.DiagnosticLogger?.LogDebug(
                                    "Exiting immediately due to 0 shutdown timeout. #{0} in queue.", queue.Count);
                                return;
                            }
                            else
                            {
                                options.DiagnosticLogger?.LogDebug(
                                    "Shutdown scheduled. Stopping by: {0}. #{1} in queue.", options.ShutdownTimeout,
                                    queue.Count);
                                shutdownTimeout.CancelAfter(options.ShutdownTimeout);
                            }

                            shutdownRequested = true;
                        }
                    }

                    if (queue.TryPeek(out var @event)) // Work with the event while it's in the queue
                    {
                        try
                        {
                            var task = transport.CaptureEventAsync(@event, shutdownTimeout.Token);
                            options.DiagnosticLogger?.LogDebug("Event {0} in-flight to Sentry. #{1} in queue.", @event.EventId, queue.Count);
                            await task.ConfigureAwait(false);
                        }
                        catch (OperationCanceledException)
                        {
                            options.DiagnosticLogger?.LogInfo("Shutdown token triggered. Time to exit. #{0} in queue.",
                                                              queue.Count);
                            return;
                        }
                        catch (Exception exception)
                        {
                            options.DiagnosticLogger?.LogError("Error while processing event {1}: {0}. #{2} in queue.",
                                                               exception, @event.EventId, queue.Count);
                        }
                        finally
                        {
                            _ = queue.TryDequeue(out _);
                            _ = Interlocked.Decrement(ref _currentItems);
                            OnFlushObjectReceived?.Invoke(@event, EventArgs.Empty);
                        }
                    }
                    else
                    {
                        Debug.Assert(shutdownRequested);
                        options.DiagnosticLogger?.LogInfo("Exiting the worker with an empty queue.");

                        // Empty queue. Exit.
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                options.DiagnosticLogger?.LogFatal("Exception in the background worker.", e);
                throw;
            }
            finally
            {
                queuedEventSemaphore.Dispose();
            }
        }
        public void MaxRequestBodySize_ByDefault_None()
        {
            var sut = new SentryOptions();

            Assert.Equal(RequestSize.None, sut.MaxRequestBodySize);
        }
 internal ProcessInfo(SentryOptions options)
 {
     _options    = options;
     StartupTime = DateTimeOffset.UtcNow;
     BootTime    = DateTimeOffset.UtcNow - TimeSpan.FromTicks(Stopwatch.GetTimestamp());
 }
 public SentryLogger(SentryOptions options, HttpContext context)
 {
     _options = options;
     _context = context;
 }