Esempio n. 1
0
        /// <summary>
        /// Queues the event to be sent to Sentry
        /// </summary>
        /// <remarks>
        /// An optional scope, if provided, will be applied to the event.
        /// </remarks>
        /// <param name="event">The event to send to Sentry.</param>
        /// <param name="scope">The optional scope to augment the event with.</param>
        /// <returns></returns>
        /// <inheritdoc />
        public Guid CaptureEvent(SentryEvent @event, Scope scope = null)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(SentryClient));
            }

            if (@event == null)
            {
                return(Guid.Empty);
            }

            if (_options.SampleRate is float sample)
            {
                if (Random.NextDouble() > sample)
                {
                    // TODO: Log here event dropped due to sampling
                    return(Guid.Empty);
                }
            }

            // Evaluate and copy before invoking the callback
            scope?.Evaluate();
            scope?.Apply(@event);

            foreach (var processor in _options.GetAllEventProcessors())
            {
                @event = processor.Process(@event);
                if (@event == null)
                {
                    // TODO: Log here which processor dropped it
                    return(Guid.Empty);
                }
            }

            @event = BeforeSend(@event);
            if (@event == null) // Rejected event
            {
                // TODO: Log BeforeSend callback dropped it
                return(Guid.Empty);
            }

            if (Worker.EnqueueEvent(@event))
            {
                return(@event.EventId);
            }

            // TODO: Notify error handler
            Debug.WriteLine("Failed to enqueue event. Current queue depth: " + Worker.QueuedItems);
            return(Guid.Empty);
        }
        private Guid DoSendEvent(SentryEvent @event, Scope scope)
        {
            if (_options.SampleRate is float sample)
            {
                if (Random.NextDouble() > sample)
                {
                    _options.DiagnosticLogger?.LogDebug("Event sampled.");
                    return(Guid.Empty);
                }
            }

            _options.DiagnosticLogger?.LogInfo("Capturing event. Has scope: {0}", scope != null);

            // Evaluate and copy before invoking the callback
            scope?.Evaluate();
            scope?.Apply(@event);

            foreach (var processor in _options.GetAllEventProcessors())
            {
                @event = processor.Process(@event);
                if (@event == null)
                {
                    _options.DiagnosticLogger?.LogInfo("Event dropped by processor {0}", processor.GetType().Name);
                    return(Guid.Empty);
                }
            }

            @event = BeforeSend(@event);
            if (@event == null) // Rejected event
            {
                _options.DiagnosticLogger?.LogInfo("Event dropped by BeforeSend callback.");
                return(Guid.Empty);
            }

            if (Worker.EnqueueEvent(@event))
            {
                _options.DiagnosticLogger?.LogDebug("Event queued up.");
                return(@event.EventId);
            }

            _options.DiagnosticLogger?.LogWarning("The attempt to queue the event failed. Items in queue: {0}",
                                                  Worker.QueuedItems);
            return(Guid.Empty);
        }