Class: CloseYourIt::ErrorEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/closeyourit/events/error_event.rb

Overview

Trasforma un’eccezione Ruby nel **payload evento Sentry** che il backend CloseYourIt ingerisce (Errors::Ingest::Normalize). Usa ‘backtrace_locations` (niente regex) e mette la cause-chain in `exception.values` ordinata dall’esterna alla principale (Sentry: values.last = il crash).

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception, configuration, handled: false, level: "error", contexts: nil) ⇒ ErrorEvent

Returns a new instance of ErrorEvent.



17
18
19
20
21
22
23
24
# File 'lib/closeyourit/events/error_event.rb', line 17

def initialize(exception, configuration, handled: false, level: "error", contexts: nil)
  super(configuration)
  @exception = exception
  @handled = handled
  @level = level
  @contexts = contexts
  @scrubber = Scrubber.new(configuration)
end

Class Method Details

.from_exception(exception, configuration:, handled: false, level: "error", contexts: nil) ⇒ Object



13
14
15
# File 'lib/closeyourit/events/error_event.rb', line 13

def self.from_exception(exception, configuration:, handled: false, level: "error", contexts: nil)
  new(exception, configuration, handled: handled, level: level, contexts: contexts)
end

Instance Method Details

#ingest_path(project_id) ⇒ Object



45
46
47
# File 'lib/closeyourit/events/error_event.rb', line 45

def ingest_path(project_id)
  "/api/v1/projects/#{project_id}/events"
end

#to_hObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/closeyourit/events/error_event.rb', line 26

def to_h
  base = compact(
    "event_id" => SecureRandom.uuid.delete("-"),
    "timestamp" => @occurred_at,
    "platform" => "ruby",
    "level" => @level,
    "environment" => environment,
    "release" => @configuration.release,
    "server_name" => server_name,
    "exception" => { "values" => exception_values },
    "contexts" => { "runtime" => { "name" => "ruby", "version" => RUBY_VERSION } },
    "sdk" => sdk
  )
  # Fonde il contesto per-richiesta/job (user/tags/extra/contexts/request) raccolto nello Scope.
  merged = deep_merge(base, CloseYourIt::Scope.current.to_event_hash)
  # Context extra passato esplicitamente (es. rails_error dall'ErrorReporter).
  @contexts ? deep_merge(merged, { "contexts" => @contexts }) : merged
end