class Sentry::Scope

Constants

ATTRIBUTES

Public Class Methods

new(max_breadcrumbs: nil) click to toggle source
# File lib/sentry/scope.rb, line 12
def initialize(max_breadcrumbs: nil)
  @max_breadcrumbs = max_breadcrumbs
  set_default_value
end

Private Class Methods

os_context() click to toggle source
# File lib/sentry/scope.rb, line 194
def os_context
  @os_context ||=
    begin
      uname = Etc.uname
      {
        name: uname[:sysname] || RbConfig::CONFIG["host_os"],
        version: uname[:version],
        build: uname[:release],
        kernel_version: uname[:version]
      }
    end
end
runtime_context() click to toggle source
# File lib/sentry/scope.rb, line 207
def runtime_context
  @runtime_context ||= {
    name: RbConfig::CONFIG["ruby_install_name"],
    version: RUBY_DESCRIPTION || Sentry.sys_command("ruby -v")
  }
end

Public Instance Methods

add_breadcrumb(breadcrumb) click to toggle source
# File lib/sentry/scope.rb, line 46
def add_breadcrumb(breadcrumb)
  breadcrumbs.record(breadcrumb)
end
add_event_processor(&block) click to toggle source
# File lib/sentry/scope.rb, line 163
def add_event_processor(&block)
  @event_processors << block
end
apply_to_event(event, hint = nil) click to toggle source
# File lib/sentry/scope.rb, line 21
def apply_to_event(event, hint = nil)
  event.tags = tags.merge(event.tags)
  event.user = user.merge(event.user)
  event.extra = extra.merge(event.extra)
  event.contexts = contexts.merge(event.contexts)
  event.transaction = transaction_name if transaction_name

  if span
    event.contexts[:trace] = span.get_trace_context
  end

  event.fingerprint = fingerprint
  event.level = level
  event.breadcrumbs = breadcrumbs
  event.rack_env = rack_env if rack_env

  unless @event_processors.empty?
    @event_processors.each do |processor_block|
      event = processor_block.call(event, hint)
    end
  end

  event
end
clear() click to toggle source
# File lib/sentry/scope.rb, line 17
def clear
  set_default_value
end
clear_breadcrumbs() click to toggle source
# File lib/sentry/scope.rb, line 50
def clear_breadcrumbs
  set_new_breadcrumb_buffer
end
dup() click to toggle source
Calls superclass method
# File lib/sentry/scope.rb, line 54
def dup
  copy = super
  copy.breadcrumbs = breadcrumbs.dup
  copy.contexts = contexts.deep_dup
  copy.extra = extra.deep_dup
  copy.tags = tags.deep_dup
  copy.user = user.deep_dup
  copy.transaction_names = transaction_names.deep_dup
  copy.fingerprint = fingerprint.deep_dup
  copy.span = span.deep_dup
  copy
end
get_span() click to toggle source
# File lib/sentry/scope.rb, line 153
def get_span
  span
end
get_transaction() click to toggle source
# File lib/sentry/scope.rb, line 149
def get_transaction
  span.transaction if span
end
set_context(key, value) click to toggle source
# File lib/sentry/scope.rb, line 132
def set_context(key, value)
  check_argument_type!(value, Hash)
  @contexts.merge!(key => value)
end
set_contexts(contexts_hash) click to toggle source
# File lib/sentry/scope.rb, line 127
def set_contexts(contexts_hash)
  check_argument_type!(contexts_hash, Hash)
  @contexts.merge!(contexts_hash)
end
set_extra(key, value) click to toggle source
# File lib/sentry/scope.rb, line 114
def set_extra(key, value)
  @extra.merge!(key => value)
end
set_extras(extras_hash) click to toggle source
# File lib/sentry/scope.rb, line 109
def set_extras(extras_hash)
  check_argument_type!(extras_hash, Hash)
  @extra.merge!(extras_hash)
end
set_fingerprint(fingerprint) click to toggle source
# File lib/sentry/scope.rb, line 157
def set_fingerprint(fingerprint)
  check_argument_type!(fingerprint, Array)

  @fingerprint = fingerprint
end
set_level(level) click to toggle source
# File lib/sentry/scope.rb, line 137
def set_level(level)
  @level = level
end
set_rack_env(env) click to toggle source
# File lib/sentry/scope.rb, line 94
def set_rack_env(env)
  env = env || {}
  @rack_env = env
end
set_span(span) click to toggle source
# File lib/sentry/scope.rb, line 99
def set_span(span)
  check_argument_type!(span, Span)
  @span = span
end
set_tag(key, value) click to toggle source
# File lib/sentry/scope.rb, line 123
def set_tag(key, value)
  @tags.merge!(key => value)
end
set_tags(tags_hash) click to toggle source
# File lib/sentry/scope.rb, line 118
def set_tags(tags_hash)
  check_argument_type!(tags_hash, Hash)
  @tags.merge!(tags_hash)
end
set_transaction_name(transaction_name) click to toggle source
# File lib/sentry/scope.rb, line 141
def set_transaction_name(transaction_name)
  @transaction_names << transaction_name
end
set_user(user_hash) click to toggle source
# File lib/sentry/scope.rb, line 104
def set_user(user_hash)
  check_argument_type!(user_hash, Hash)
  @user = user_hash
end
transaction_name() click to toggle source
# File lib/sentry/scope.rb, line 145
def transaction_name
  @transaction_names.last
end
update_from_options( contexts: nil, extra: nil, tags: nil, user: nil, level: nil, fingerprint: nil ) click to toggle source
# File lib/sentry/scope.rb, line 78
def update_from_options(
  contexts: nil,
  extra: nil,
  tags: nil,
  user: nil,
  level: nil,
  fingerprint: nil
)
  self.contexts.merge!(contexts) if contexts
  self.extra.merge!(extra) if extra
  self.tags.merge!(tags) if tags
  self.user = user if user
  self.level = level if level
  self.fingerprint = fingerprint if fingerprint
end
update_from_scope(scope) click to toggle source
# File lib/sentry/scope.rb, line 67
def update_from_scope(scope)
  self.breadcrumbs = scope.breadcrumbs
  self.contexts = scope.contexts
  self.extra = scope.extra
  self.tags = scope.tags
  self.user = scope.user
  self.transaction_names = scope.transaction_names
  self.fingerprint = scope.fingerprint
  self.span = scope.span
end

Private Instance Methods

set_default_value() click to toggle source
# File lib/sentry/scope.rb, line 174
def set_default_value
  @contexts = { :os => self.class.os_context, :runtime => self.class.runtime_context }
  @extra = {}
  @tags = {}
  @user = {}
  @level = :error
  @fingerprint = []
  @transaction_names = []
  @event_processors = []
  @rack_env = {}
  @span = nil
  set_new_breadcrumb_buffer
end
set_new_breadcrumb_buffer() click to toggle source
# File lib/sentry/scope.rb, line 188
def set_new_breadcrumb_buffer
  @breadcrumbs = BreadcrumbBuffer.new(@max_breadcrumbs)
end