Class: Dispatch::Rails::EventBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/dispatch/rails/event_builder.rb

Overview

Turns a Ruby exception (+ optional Rack env / user) into the Sentry-shaped event hash the Dispatch ingest endpoint understands. In-app frames are flagged and given source context (the lines around the failing line), which is what makes the AI fix pipeline’s patches accurate.

Constant Summary collapse

CONTEXT_LINES =
5
MAX_CONTEXT_FRAMES =
12
MAX_FRAMES =
100
MAX_CAUSES =
5
MAX_PARAMS_BYTES =
8_000
SAFE_HEADERS =
%w[User-Agent Referer Accept Content-Type Host X-Request-Id].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception, handled:, env: nil, user: nil, tags: {}, level: "error") ⇒ EventBuilder

Returns a new instance of EventBuilder.



23
24
25
26
27
28
29
30
31
32
# File 'lib/dispatch/rails/event_builder.rb', line 23

def initialize(exception, handled:, env: nil, user: nil, tags: {}, level: "error")
  @exception = exception
  @handled = handled
  @env = env
  @user = user
  @tags = tags || {}
  @level = level
  @source_cache = {}
  @config = Dispatch::Rails.configuration
end

Class Method Details

.call(exception, handled:, env: nil, user: nil, tags: {}, level: "error") ⇒ Object



19
20
21
# File 'lib/dispatch/rails/event_builder.rb', line 19

def self.call(exception, handled:, env: nil, user: nil, tags: {}, level: "error")
  new(exception, handled: handled, env: env, user: user, tags: tags, level: level).call
end

Instance Method Details

#callObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dispatch/rails/event_builder.rb', line 34

def call
  {
    event_id: SecureRandom.uuid.delete("-"),
    timestamp: Time.now.to_f,
    platform: "ruby",
    level: @level,
    environment: @config.effective_environment,
    release: @config.release,
    server_name: hostname,
    transaction: transaction, # Sentry's name for the controller#action
    exception: { values: exception_values },
    request: request_hash,
    user: user_hash,
    tags: tags_hash,
    sdk: { name: "dispatch-rails", version: Dispatch::Rails::VERSION }
  }.compact
end