Class: Sentry::SingleExceptionInterface

Inherits:
Interface
  • Object
show all
Includes:
CustomInspection
Defined in:
lib/sentry/interfaces/single_exception.rb

Constant Summary collapse

SKIP_INSPECTION_ATTRIBUTES =
[:@stacktrace]
PROBLEMATIC_LOCAL_VALUE_REPLACEMENT =
"[ignored due to error]".freeze
OMISSION_MARK =
"...".freeze
MAX_LOCAL_BYTES =
1024

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception:, mechanism:, stacktrace: nil) ⇒ SingleExceptionInterface

Returns a new instance of SingleExceptionInterface.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sentry/interfaces/single_exception.rb', line 17

def initialize(exception:, mechanism:, stacktrace: nil)
  @type = exception.class.to_s
  exception_message =
    if exception.respond_to?(:detailed_message)
      exception.detailed_message(highlight: false)
    else
      exception.message || ""
    end
  exception_message = exception_message.inspect unless exception_message.is_a?(String)

  @value = Utils::EncodingHelper.encode_to_utf_8(exception_message.byteslice(0..Event::MAX_MESSAGE_SIZE_IN_BYTES))

  @module = exception.class.to_s.split('::')[0...-1].join('::')
  @thread_id = Thread.current.object_id
  @stacktrace = stacktrace
  @mechanism = mechanism
end

Instance Attribute Details

#mechanismObject (readonly)

Returns the value of attribute mechanism.



14
15
16
# File 'lib/sentry/interfaces/single_exception.rb', line 14

def mechanism
  @mechanism
end

#moduleObject (readonly)

Returns the value of attribute module.



14
15
16
# File 'lib/sentry/interfaces/single_exception.rb', line 14

def module
  @module
end

#stacktraceObject (readonly)

Returns the value of attribute stacktrace.



14
15
16
# File 'lib/sentry/interfaces/single_exception.rb', line 14

def stacktrace
  @stacktrace
end

#thread_idObject (readonly)

Returns the value of attribute thread_id.



14
15
16
# File 'lib/sentry/interfaces/single_exception.rb', line 14

def thread_id
  @thread_id
end

#typeObject (readonly)

Returns the value of attribute type.



14
15
16
# File 'lib/sentry/interfaces/single_exception.rb', line 14

def type
  @type
end

#valueObject

Returns the value of attribute value.



15
16
17
# File 'lib/sentry/interfaces/single_exception.rb', line 15

def value
  @value
end

Class Method Details

.build_with_stacktrace(exception:, stacktrace_builder:, mechanism:) ⇒ Object

patch this method if you want to change an exception’s stacktrace frames also see ‘StacktraceBuilder.build`.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/sentry/interfaces/single_exception.rb', line 44

def self.build_with_stacktrace(exception:, stacktrace_builder:, mechanism:)
  stacktrace = stacktrace_builder.build(backtrace: exception.backtrace)

  if locals = exception.instance_variable_get(:@sentry_locals)
    locals.each do |k, v|
      locals[k] =
        begin
          v = v.inspect unless v.is_a?(String)

          if v.length >= MAX_LOCAL_BYTES
            v = v.byteslice(0..MAX_LOCAL_BYTES - 1) + OMISSION_MARK
          end

          Utils::EncodingHelper.encode_to_utf_8(v)
        rescue StandardError
          PROBLEMATIC_LOCAL_VALUE_REPLACEMENT
        end
    end

    stacktrace.frames.last.vars = locals
  end

  new(exception: exception, stacktrace: stacktrace, mechanism: mechanism)
end

Instance Method Details

#to_hashObject



35
36
37
38
39
40
# File 'lib/sentry/interfaces/single_exception.rb', line 35

def to_hash
  data = super
  data[:stacktrace] = data[:stacktrace].to_hash if data[:stacktrace]
  data[:mechanism] = data[:mechanism].to_hash
  data
end