class Sentry::Client

def buffer_log_event(event, scope)

Returns:
  • (LogEvent) -

Parameters:
  • event (LogEvent) -- the log event to be buffered
def buffer_log_event(event, scope)
  return unless event.is_a?(LogEvent)
  @log_event_buffer.add_item(scope.apply_to_telemetry(event))
  event
end

def buffer_metric_event(event, scope)

Returns:
  • (MetricEvent) -

Parameters:
  • event (MetricEvent) -- the metric event to be buffered
def buffer_metric_event(event, scope)
  return unless event.is_a?(MetricEvent)
  event = scope.apply_to_telemetry(event)
  @metric_event_buffer.add_item(event)
  event
end

def capture_envelope(envelope)

Returns:
  • (void) -

Parameters:
  • envelope (Envelope) -- the envelope to be captured.
def capture_envelope(envelope)
  Sentry.background_worker.perform { send_envelope(envelope) }
end

def capture_event(event, scope, hint = {})

Returns:
  • (Event, nil) -

Parameters:
  • hint (Hash) -- the hint data that'll be passed to `before_send` callback and the scope's event processors.
  • scope (Scope) -- the scope with contextual data that'll be applied to the event before it's sent.
  • event (Event) -- the event to be sent.
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, "error")
    return
  end
  data_category = Envelope::Item.data_category(event.type)
  is_transaction = event.is_a?(TransactionEvent)
  spans_before = is_transaction ? event.spans.size : 0
  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, data_category)
    transport.record_lost_event(:event_processor, "span", num: spans_before + 1) if is_transaction
    return
  elsif is_transaction
    spans_delta = spans_before - event.spans.size
    transport.record_lost_event(:event_processor, "span", num: spans_delta) if spans_delta > 0
  end
  if configuration.background_worker_threads != 0 && hint.fetch(:background, true)
    unless dispatch_background_event(event, hint)
      transport.record_lost_event(:queue_overflow, data_category)
      transport.record_lost_event(:queue_overflow, "span", num: spans_before + 1) if is_transaction
    end
  else
    send_event(event, hint)
  end
  event
rescue => e
  log_error("Event capturing failed", e, debug: configuration.debug)
  nil
end

def dispatch_background_event(event, hint)

def dispatch_background_event(event, hint)
  Sentry.background_worker.perform do
    send_event(event, hint)
  end
end

def event_from_check_in(

Returns:
  • (Event) -

Parameters:
  • check_in_id (String, nil) -- for updating the status of an existing monitor
  • monitor_config (Cron::MonitorConfig, nil) -- configuration for this monitor
  • duration (Integer, nil) -- seconds elapsed since this monitor started
  • hint (Hash) -- the hint data that'll be passed to `before_send` callback and the scope's event processors.
  • status (Symbol) -- status of this check-in, one of {CheckInEvent::VALID_STATUSES}
  • slug (String) -- identifier of this monitor
def event_from_check_in(
  slug,
  status,
  hint = {},
  duration: nil,
  monitor_config: nil,
  check_in_id: nil
)
  return unless configuration.sending_allowed?
  CheckInEvent.new(
    configuration: configuration,
    integration_meta: Sentry.integrations[hint[:integration]],
    slug: slug,
    status: status,
    duration: duration,
    monitor_config: monitor_config,
    check_in_id: check_in_id
  )
end

def event_from_exception(exception, hint = {})

Returns:
  • (Event, nil) -

Parameters:
  • hint (Hash) -- the hint data that'll be passed to `before_send` callback and the scope's event processors.
  • exception (Exception) -- the exception to be reported.
def event_from_exception(exception, hint = {})
  return unless @configuration.sending_allowed?
  ignore_exclusions = hint.delete(:ignore_exclusions) { false }
  return if !ignore_exclusions && !@configuration.exception_class_allowed?(exception)
  integration_meta = Sentry.integrations[hint[:integration]]
  mechanism = hint.delete(:mechanism) { Mechanism.new }
  ErrorEvent.new(configuration: configuration, integration_meta: integration_meta).tap do |event|
    event.add_exception_interface(exception, mechanism: mechanism)
    event.add_threads_interface(crashed: true)
    event.level = :error
  end
end

def event_from_log(message, level:, **options)

Returns:
  • (LogEvent) - the created log event

Options Hash: (**options)
  • :parameters (Array) -- Array of values to replace template tokens in the message

Parameters:
  • options (Hash) -- additional options
  • level (Symbol) -- the log level (:trace, :debug, :info, :warn, :error, :fatal)
  • message (String) -- the log message
def event_from_log(message, level:, **options)
  return unless configuration.sending_allowed?
  attributes = options.reject { |k, _| k == :level || k == :severity || k == :origin }
  origin = options[:origin]
  body = Utils::EncodingHelper.safe_utf_8_string(message)
  sanitized_attributes = attributes.transform_values do |value|
    if value.is_a?(String)
      Utils::EncodingHelper.safe_utf_8_string(value)
    else
      value
    end
  end
  LogEvent.new(level: level, body: body, attributes: sanitized_attributes, origin: origin)
end

def event_from_message(message, hint = {}, backtrace: nil)

Returns:
  • (Event) -

Parameters:
  • hint (Hash) -- the hint data that'll be passed to `before_send` callback and the scope's event processors.
  • message (String) -- the message to be reported.
def event_from_message(message, hint = {}, backtrace: nil)
  return unless @configuration.sending_allowed?
  integration_meta = Sentry.integrations[hint[:integration]]
  event = ErrorEvent.new(configuration: configuration, integration_meta: integration_meta, message: message)
  event.add_threads_interface(backtrace: backtrace || caller)
  event.level = :error
  event
end

def event_from_transaction(transaction)

Returns:
  • (TransactionEvent) -

Parameters:
  • transaction (Transaction) -- the transaction to be recorded.
def event_from_transaction(transaction)
  TransactionEvent.new(configuration: configuration, transaction: transaction)
end

def flush

Returns:
  • (void) -
def flush
  transport.flush if configuration.sending_to_dsn_allowed?
  spotlight_transport.flush if spotlight_transport
  @log_event_buffer&.flush
  @metric_event_buffer&.flush
end

def initialize(configuration)

Parameters:
  • configuration (Configuration) --
def initialize(configuration)
  @configuration = configuration
  @sdk_logger = configuration.sdk_logger
  if transport_class = configuration.transport.transport_class
    @transport = transport_class.new(configuration)
  else
    @transport =
      case configuration.dsn&.scheme
      when "http", "https"
        HTTPTransport.new(configuration)
      else
        DummyTransport.new(configuration)
      end
  end
  @spotlight_transport = SpotlightTransport.new(configuration) if configuration.spotlight
  if configuration.enable_logs
    @log_event_buffer = LogEventBuffer.new(configuration, self)
  end
  if configuration.enable_metrics
    @metric_event_buffer = MetricEventBuffer.new(configuration, self)
  end
end

def send_envelope(envelope)

Returns:
  • (void) -

Parameters:
  • envelope (Envelope) -- the envelope to be sent.
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

def send_event(event, hint = nil)

@!macro send_event
def send_event(event, hint = nil)
  data_category = Envelope::Item.data_category(event.type)
  spans_before = event.is_a?(TransactionEvent) ? event.spans.size : 0
  if event.is_a?(ErrorEvent) && configuration.before_send
    event = configuration.before_send.call(event, hint)
    if !event.is_a?(ErrorEvent)
      # Avoid serializing the event object in this case because we aren't sure what it is and what it contains
      log_debug(<<~MSG)
        Discarded event because before_send didn't return a Sentry::ErrorEvent object but an instance of #{event.class}
      MSG
      transport.record_lost_event(:before_send, data_category)
      return
    end
  end
  if event.is_a?(TransactionEvent) && configuration.before_send_transaction
    event = configuration.before_send_transaction.call(event, hint)
    if !event.is_a?(TransactionEvent)
      # Avoid serializing the event object in this case because we aren't sure what it is and what it contains
      log_debug(<<~MSG)
        Discarded event because before_send_transaction didn't return a Sentry::TransactionEvent object but an instance of #{event.class}
      MSG
      transport.record_lost_event(:before_send, "transaction")
      transport.record_lost_event(:before_send, "span", num: spans_before + 1)
      return
    end
    spans_after = event.is_a?(TransactionEvent) ? event.spans.size : 0
    spans_delta = spans_before - spans_after
    transport.record_lost_event(:before_send, "span", num: spans_delta) if spans_delta > 0
  end
  if event.is_a?(CheckInEvent) && configuration.before_send_check_in
    event = configuration.before_send_check_in.call(event, hint)
    if !event.is_a?(CheckInEvent)
      # Avoid serializing the event object in this case because we aren't sure what it is and what it contains
      log_debug(<<~MSG)
        Discarded event because before_send_check_in didn't return a Sentry::CheckInEvent object but an instance of #{event.class}
      MSG
      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, data_category)
  transport.record_lost_event(:network_error, "span", num: spans_before + 1) if event.is_a?(TransactionEvent)
  raise
end