Class: CloseYourIt::ErrorEvent
- 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
- #ingest_path(project_id) ⇒ Object
-
#initialize(exception, configuration, handled: false, level: "error", contexts: nil) ⇒ ErrorEvent
constructor
A new instance of ErrorEvent.
- #to_h ⇒ Object
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
47 48 49 |
# File 'lib/closeyourit/events/error_event.rb', line 47 def ingest_path(project_id) "/api/v1/projects/#{project_id}/events" end |
#to_h ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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, # Correlazione log↔errori: stesso trace_id dei log della medesima richiesta (popolato dallo Scope). "trace_id" => CloseYourIt::Scope.current.trace_id, "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 |