class Sentry::Hub

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/sentry/hub.rbs

class Sentry::Hub
  def add_breadcrumb: (Sentry::Breadcrumb breadcrumb, hint: Hash) -> untyped
  def current_client: () -> Sentry::Client
  def current_layer: () -> Sentry::Hub::Layer
  def current_scope: () -> Sentry::Scope
  def start_session: () -> Sentry::Session
end

def add_breadcrumb(breadcrumb, hint: {})

Experimental RBS support (using type sampling data from the type_fusion project).

def add_breadcrumb: (Sentry::Breadcrumb breadcrumb, hint: (severity | Integer | )) -> untyped

This signature was generated using 2 samples from 1 application.

def add_breadcrumb(breadcrumb, hint: {})
  return unless configuration.enabled_in_current_env?
  if before_breadcrumb = current_client.configuration.before_breadcrumb
    breadcrumb = before_breadcrumb.call(breadcrumb, hint)
  end
  return unless breadcrumb
  current_scope.add_breadcrumb(breadcrumb)
end

def bind_client(client)

def bind_client(client)
  layer = current_layer
  if layer
    layer.client = client
  end
end

def capture_event(event, **options, &block)

def capture_event(event, **options, &block)
  check_argument_type!(event, Sentry::Event)
  return unless current_client
  hint = options.delete(:hint) || {}
  scope = current_scope.dup
  if block
    block.call(scope)
  elsif custom_scope = options[:scope]
    scope.update_from_scope(custom_scope)
  elsif !options.empty?
    scope.update_from_options(**options)
  end
  event = current_client.capture_event(event, scope, hint)
  if event && configuration.debug
    configuration.log_debug(event.to_json_compatible)
  end
  @last_event_id = event&.event_id unless event.is_a?(Sentry::TransactionEvent)
  event
end

def capture_exception(exception, **options, &block)

def capture_exception(exception, **options, &block)
  if RUBY_PLATFORM == "java"
    check_argument_type!(exception, ::Exception, ::Java::JavaLang::Throwable)
  else
    check_argument_type!(exception, ::Exception)
  end
  return if Sentry.exception_captured?(exception)
  return unless current_client
  options[:hint] ||= {}
  options[:hint][:exception] = exception
  event = current_client.event_from_exception(exception, options[:hint])
  return unless event
  current_scope.session&.update_from_exception(event.exception)
  capture_event(event, **options, &block).tap do
    # mark the exception as captured so we can use this information to avoid duplicated capturing
    exception.instance_variable_set(Sentry::CAPTURED_SIGNATURE, true)
  end
end

def capture_message(message, **options, &block)

def capture_message(message, **options, &block)
  check_argument_type!(message, ::String)
  return unless current_client
  options[:hint] ||= {}
  options[:hint][:message] = message
  backtrace = options.delete(:backtrace)
  event = current_client.event_from_message(message, options[:hint], backtrace: backtrace)
  return unless event
  capture_event(event, **options, &block)
end

def clone

def clone
  layer = current_layer
  if layer
    scope = layer.scope&.dup
    Hub.new(layer.client, scope)
  end
end

def configuration

def configuration
  current_client.configuration
end

def configure_scope(&block)

def configure_scope(&block)
  block.call(current_scope)
end

def current_client

Experimental RBS support (using type sampling data from the type_fusion project).

def current_client: () -> Sentry::Client

This signature was generated using 5 samples from 1 application.

def current_client
  current_layer&.client
end

def current_layer

Experimental RBS support (using type sampling data from the type_fusion project).

def current_layer: () -> Sentry::Hub::Layer

This signature was generated using 5 samples from 1 application.

def current_layer
  @stack.last
end

def current_scope

Experimental RBS support (using type sampling data from the type_fusion project).

def current_scope: () -> Sentry::Scope

This signature was generated using 2 samples from 1 application.

def current_scope
  current_layer&.scope
end

def end_session

def end_session
  return unless current_scope
  session = current_scope.session
  current_scope.set_session(nil)
  return unless session
  session.close
  Sentry.session_flusher.add_session(session)
end

def initialize(client, scope)

def initialize(client, scope)
  first_layer = Layer.new(client, scope)
  @stack = [first_layer]
  @last_event_id = nil
end

def new_from_top

def new_from_top
  Hub.new(current_client, current_scope)
end

def pop_scope

def pop_scope
  @stack.pop
end

def push_scope

def push_scope
  new_scope =
    if current_scope
      current_scope.dup
    else
      Scope.new
    end
  @stack << Layer.new(current_client, new_scope)
end

def start_session

Experimental RBS support (using type sampling data from the type_fusion project).

def start_session: () -> Sentry::Session

This signature was generated using 1 sample from 1 application.

def start_session
  return unless current_scope
  current_scope.set_session(Session.new)
end

def start_transaction(transaction: nil, custom_sampling_context: {}, instrumenter: :sentry, **options)

def start_transaction(transaction: nil, custom_sampling_context: {}, instrumenter: :sentry, **options)
  return unless configuration.tracing_enabled?
  return unless instrumenter == configuration.instrumenter
  transaction ||= Transaction.new(**options.merge(hub: self))
  sampling_context = {
    transaction_context: transaction.to_hash,
    parent_sampled: transaction.parent_sampled
  }
  sampling_context.merge!(custom_sampling_context)
  transaction.set_initial_sample_decision(sampling_context: sampling_context)
  transaction.start_profiler!
  transaction
end

def with_background_worker_disabled(&block)

but it temporarily disables dispatching events to it
this doesn't do anything to the already initialized background worker
def with_background_worker_disabled(&block)
  original_background_worker_threads = configuration.background_worker_threads
  configuration.background_worker_threads = 0
  block.call
ensure
  configuration.background_worker_threads = original_background_worker_threads
end

def with_child_span(instrumenter: :sentry, **attributes, &block)

def with_child_span(instrumenter: :sentry, **attributes, &block)
  return yield(nil) unless instrumenter == configuration.instrumenter
  current_span = current_scope.get_span
  return yield(nil) unless current_span
  result = nil
  begin
    current_span.with_child_span(**attributes) do |child_span|
      current_scope.set_span(child_span)
      result = yield(child_span)
    end
  ensure
    current_scope.set_span(current_span)
  end
  result
end

def with_scope(&block)

def with_scope(&block)
  push_scope
  yield(current_scope)
ensure
  pop_scope
end

def with_session_tracking(&block)

def with_session_tracking(&block)
  return yield unless configuration.auto_session_tracking
  start_session
  yield
ensure
  end_session
end