Module: Condux::EventPayload

Defined in:
lib/condux/event_payload.rb

Overview

Builds the Sentry "exception" payload (type/value/mechanism/stacktrace) from an exception.

Constant Summary collapse

RUBY_LIB_DIR =
RbConfig::CONFIG["rubylibdir"]

Class Method Summary collapse

Class Method Details

.exception(error, handled: true) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/condux/event_payload.rb', line 12

def exception(error, handled: true)
  exception = {
    "type" => error.class.name,
    "value" => error.message.to_s,
    # The relay reads mechanism.handled for the unhandled badge. A direct capture_exception is a handled
    # capture; a framework integration reporting an uncaught exception passes handled: false.
    "mechanism" => { "type" => "generic", "handled" => handled },
  }
  frames = stack_frames(error)
  exception["stacktrace"] = { "frames" => frames } unless frames.empty?
  { "values" => [exception] }
end

.in_app?(path) ⇒ Boolean

Application frames drive grouping + the culprit; gems and the standard library are noise.

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/condux/event_payload.rb', line 42

def in_app?(path)
  return false if path.nil?

  !path.include?("/gems/") && !(RUBY_LIB_DIR && path.start_with?(RUBY_LIB_DIR))
end

.stack_frames(error) ⇒ Object

Ruby backtrace locations are innermost-first (the raise site first); reverse to oldest-first (raise site last), the order the relay's fingerprinter and issue detail expect.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/condux/event_payload.rb', line 27

def stack_frames(error)
  locations = error.backtrace_locations
  return [] unless locations

  locations.reverse.map do |loc|
    {
      "filename" => loc.path,
      "function" => loc.label,
      "lineno" => loc.lineno,
      "in_app" => in_app?(loc.path),
    }
  end
end