lib/sentry/client.rb in sentry-ruby-5.17.2 vs lib/sentry/client.rb in sentry-ruby-5.17.3

- old
+ new

@@ -47,38 +47,53 @@ # @return [Event, nil] def capture_event(event, scope, hint = {}) return unless configuration.sending_allowed? if event.is_a?(ErrorEvent) && !configuration.sample_allowed? - transport.record_lost_event(:sample_rate, 'event') + transport.record_lost_event(:sample_rate, 'error') return end event_type = event.is_a?(Event) ? event.type : event["type"] + data_category = Envelope::Item.data_category(event_type) event = scope.apply_to_event(event, hint) if event.nil? log_debug("Discarded event because one of the event processors returned nil") - transport.record_lost_event(:event_processor, event_type) + transport.record_lost_event(:event_processor, data_category) return end if async_block = configuration.async dispatch_async_event(async_block, event, hint) elsif configuration.background_worker_threads != 0 && hint.fetch(:background, true) queued = dispatch_background_event(event, hint) - transport.record_lost_event(:queue_overflow, event_type) unless queued + transport.record_lost_event(:queue_overflow, data_category) unless queued else send_event(event, hint) end event rescue => e log_error("Event capturing failed", e, debug: configuration.debug) nil end + # Capture an envelope directly. + # @param envelope [Envelope] the envelope to be captured. + # @return [void] + def capture_envelope(envelope) + Sentry.background_worker.perform { send_envelope(envelope) } + end + + # Flush pending events to Sentry. + # @return [void] + def flush + transport.flush if configuration.sending_to_dsn_allowed? + spotlight_transport.flush if spotlight_transport + end + # Initializes an Event object with the given exception. Returns `nil` if the exception's class is excluded from reporting. # @param exception [Exception] the exception to be reported. # @param hint [Hash] the hint data that'll be passed to `before_send` callback and the scope's event processors. # @return [Event, nil] def event_from_exception(exception, hint = {}) @@ -150,37 +165,54 @@ end # @!macro send_event def send_event(event, hint = nil) event_type = event.is_a?(Event) ? event.type : event["type"] + data_category = Envelope::Item.data_category(event_type) if event_type != TransactionEvent::TYPE && configuration.before_send event = configuration.before_send.call(event, hint) if event.nil? log_debug("Discarded event because before_send returned nil") - transport.record_lost_event(:before_send, 'event') + transport.record_lost_event(:before_send, data_category) return end end if event_type == TransactionEvent::TYPE && configuration.before_send_transaction event = configuration.before_send_transaction.call(event, hint) if event.nil? log_debug("Discarded event because before_send_transaction returned nil") - transport.record_lost_event(:before_send, 'transaction') + transport.record_lost_event(:before_send, data_category) return end end transport.send_event(event) if configuration.sending_to_dsn_allowed? spotlight_transport.send_event(event) if spotlight_transport event rescue => e log_error("Event sending failed", e, debug: configuration.debug) - transport.record_lost_event(:network_error, event_type) + transport.record_lost_event(:network_error, data_category) + raise + end + + # Send an envelope directly to Sentry. + # @param envelope [Envelope] the envelope to be sent. + # @return [void] + def send_envelope(envelope) + transport.send_envelope(envelope) if configuration.sending_to_dsn_allowed? + spotlight_transport.send_envelope(envelope) if spotlight_transport + rescue => e + log_error("Envelope sending failed", e, debug: configuration.debug) + + envelope.items.map(&:data_category).each do |data_category| + transport.record_lost_event(:network_error, data_category) + end + raise end # @deprecated use Sentry.get_traceparent instead. #