class Sentry::Hub
Attributes
last_event_id[R]
Public Class Methods
new(client, scope)
click to toggle source
# File lib/sentry/hub.rb, line 10 def initialize(client, scope) first_layer = Layer.new(client, scope) @stack = [first_layer] @last_event_id = nil end
Public Instance Methods
bind_client(client)
click to toggle source
# File lib/sentry/hub.rb, line 42 def bind_client(client) layer = current_layer if layer layer.client = client end end
capture_event(event, **options, &block)
click to toggle source
# File lib/sentry/hub.rb, line 116 def capture_event(event, **options, &block) return unless current_client check_argument_type!(event, Sentry::Event) 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) @last_event_id = event&.event_id event end
capture_exception(exception, **options, &block)
click to toggle source
# File lib/sentry/hub.rb, line 92 def capture_exception(exception, **options, &block) return unless current_client check_argument_type!(exception, ::Exception) options[:hint] ||= {} options[:hint][:exception] = exception event = current_client.event_from_exception(exception, options[:hint]) return unless event capture_event(event, **options, &block) end
capture_message(message, **options, &block)
click to toggle source
# File lib/sentry/hub.rb, line 106 def capture_message(message, **options, &block) 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) capture_event(event, **options, &block) end
clone()
click to toggle source
# File lib/sentry/hub.rb, line 32 def clone layer = current_layer if layer scope = layer.scope&.dup Hub.new(layer.client, scope) end end
configuration()
click to toggle source
# File lib/sentry/hub.rb, line 24 def configuration current_client.configuration end
configure_scope(&block)
click to toggle source
# File lib/sentry/hub.rb, line 50 def configure_scope(&block) block.call(current_scope) end
current_client()
click to toggle source
# File lib/sentry/hub.rb, line 20 def current_client current_layer&.client end
current_scope()
click to toggle source
# File lib/sentry/hub.rb, line 28 def current_scope current_layer&.scope end
new_from_top()
click to toggle source
# File lib/sentry/hub.rb, line 16 def new_from_top Hub.new(current_client, current_scope) end
pop_scope()
click to toggle source
# File lib/sentry/hub.rb, line 72 def pop_scope @stack.pop end
push_scope()
click to toggle source
# File lib/sentry/hub.rb, line 61 def push_scope new_scope = if current_scope current_scope.dup else Scope.new end @stack << Layer.new(current_client, new_scope) end
start_transaction(transaction: nil, custom_sampling_context: {}, **options)
click to toggle source
# File lib/sentry/hub.rb, line 76 def start_transaction(transaction: nil, custom_sampling_context: {}, **options) return unless configuration.tracing_enabled? 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 end
with_background_worker_disabled(&block)
click to toggle source
this doesn't do anything to the already initialized background worker but it temporarily disables dispatching events to it
# File lib/sentry/hub.rb, line 152 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
with_scope() { |current_scope| ... }
click to toggle source
# File lib/sentry/hub.rb, line 54 def with_scope(&block) push_scope yield(current_scope) ensure pop_scope end
Private Instance Methods
current_layer()
click to toggle source
# File lib/sentry/hub.rb, line 163 def current_layer @stack.last end