Class: Lapsoss::Event
- Inherits:
-
Data
- Object
- Data
- Lapsoss::Event
- Defined in:
- lib/lapsoss/event.rb
Overview
Immutable event structure using Ruby 3.3 Data class
Instance Attribute Summary collapse
-
#backtrace_frames ⇒ Object
readonly
Returns the value of attribute backtrace_frames.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#transaction ⇒ Object
readonly
Returns the value of attribute transaction.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.build(type:, level: :info, **attributes) ⇒ Object
Factory method with smart defaults.
- .generate_fingerprint(type, message, exception, environment) ⇒ Object
- .process_backtrace(exception) ⇒ Object
Instance Method Summary collapse
-
#as_json(options = nil) ⇒ Object
ActiveSupport::JSON serialization.
- #backtrace ⇒ Object
- #breadcrumbs ⇒ Object
- #exception_message ⇒ Object
-
#exception_type ⇒ Object
Helper methods.
- #extra ⇒ Object
- #has_backtrace? ⇒ Boolean
- #has_exception? ⇒ Boolean
- #request_context ⇒ Object
-
#scrubbed ⇒ Object
Apply data scrubbing.
- #tags ⇒ Object
- #to_json(options = nil) ⇒ Object
- #user_context ⇒ Object
Instance Attribute Details
#backtrace_frames ⇒ Object (readonly)
Returns the value of attribute backtrace_frames
10 11 12 |
# File 'lib/lapsoss/event.rb', line 10 def backtrace_frames @backtrace_frames end |
#context ⇒ Object (readonly)
Returns the value of attribute context
10 11 12 |
# File 'lib/lapsoss/event.rb', line 10 def context @context end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment
10 11 12 |
# File 'lib/lapsoss/event.rb', line 10 def environment @environment end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception
10 11 12 |
# File 'lib/lapsoss/event.rb', line 10 def exception @exception end |
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint
10 11 12 |
# File 'lib/lapsoss/event.rb', line 10 def fingerprint @fingerprint end |
#level ⇒ Object (readonly)
Returns the value of attribute level
10 11 12 |
# File 'lib/lapsoss/event.rb', line 10 def level @level end |
#message ⇒ Object (readonly)
Returns the value of attribute message
10 11 12 |
# File 'lib/lapsoss/event.rb', line 10 def end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp
10 11 12 |
# File 'lib/lapsoss/event.rb', line 10 def end |
#transaction ⇒ Object (readonly)
Returns the value of attribute transaction
10 11 12 |
# File 'lib/lapsoss/event.rb', line 10 def transaction @transaction end |
#type ⇒ Object (readonly)
Returns the value of attribute type
10 11 12 |
# File 'lib/lapsoss/event.rb', line 10 def type @type end |
Class Method Details
.build(type:, level: :info, **attributes) ⇒ Object
Factory method with smart defaults
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lapsoss/event.rb', line 23 def self.build(type:, level: :info, **attributes) = attributes[:timestamp] || Time.now environment = attributes[:environment].presence || Lapsoss.configuration.environment context = attributes[:context] || {} # Process exception if present exception = attributes[:exception] = attributes[:message].presence || exception&. backtrace_frames = process_backtrace(exception) if exception # Generate fingerprint fingerprint = attributes.fetch(:fingerprint) { generate_fingerprint(type, , exception, environment) } new( type: type, level: level, timestamp: , message: , exception: exception, context: context, environment: environment, fingerprint: fingerprint, backtrace_frames: backtrace_frames, transaction: attributes[:transaction] ) end |
.generate_fingerprint(type, message, exception, environment) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/lapsoss/event.rb', line 104 def self.generate_fingerprint(type, , exception, environment) return nil unless Lapsoss.configuration.fingerprint_callback || Lapsoss.configuration.fingerprint_patterns.present? fingerprinter = Fingerprinter.new( custom_callback: Lapsoss.configuration.fingerprint_callback, patterns: Lapsoss.configuration.fingerprint_patterns, normalize_paths: Lapsoss.configuration.normalize_fingerprint_paths, normalize_ids: Lapsoss.configuration.normalize_fingerprint_ids, include_environment: Lapsoss.configuration.fingerprint_include_environment ) # Create a temporary event-like object for fingerprinting temp_event = Struct.new(:type, :message, :exception, :environment).new( type, , exception, environment ) fingerprinter.generate_fingerprint(temp_event) end |
.process_backtrace(exception) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/lapsoss/event.rb', line 96 def self.process_backtrace(exception) return nil unless exception&.backtrace.present? config = Lapsoss.configuration processor = BacktraceProcessor.new(config) processor.process_exception_backtrace(exception) end |
Instance Method Details
#as_json(options = nil) ⇒ Object
ActiveSupport::JSON serialization
53 54 55 |
# File 'lib/lapsoss/event.rb', line 53 def as_json( = nil) to_h.compact_blank.as_json() end |
#backtrace ⇒ Object
70 |
# File 'lib/lapsoss/event.rb', line 70 def backtrace = exception&.backtrace |
#breadcrumbs ⇒ Object
80 |
# File 'lib/lapsoss/event.rb', line 80 def = context[:breadcrumbs] || [] |
#exception_message ⇒ Object
64 |
# File 'lib/lapsoss/event.rb', line 64 def = exception&. |
#exception_type ⇒ Object
Helper methods
62 |
# File 'lib/lapsoss/event.rb', line 62 def exception_type = exception&.class&.name |
#extra ⇒ Object
78 |
# File 'lib/lapsoss/event.rb', line 78 def extra = context[:extra] || {} |
#has_backtrace? ⇒ Boolean
68 |
# File 'lib/lapsoss/event.rb', line 68 def has_backtrace? = backtrace_frames.present? |
#has_exception? ⇒ Boolean
66 |
# File 'lib/lapsoss/event.rb', line 66 def has_exception? = exception.present? |
#request_context ⇒ Object
72 |
# File 'lib/lapsoss/event.rb', line 72 def request_context = context.dig(:extra, :request) || context.dig(:extra, "request") |
#scrubbed ⇒ Object
Apply data scrubbing
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/lapsoss/event.rb', line 83 def scrubbed scrubber = Scrubber.new( scrub_fields: Lapsoss.configuration.scrub_fields, scrub_all: Lapsoss.configuration.scrub_all, whitelist_fields: Lapsoss.configuration.whitelist_fields, randomize_scrub_length: Lapsoss.configuration.randomize_scrub_length ) with(context: scrubber.scrub(context)) end |
#tags ⇒ Object
76 |
# File 'lib/lapsoss/event.rb', line 76 def = context[:tags] || {} |
#to_json(options = nil) ⇒ Object
57 58 59 |
# File 'lib/lapsoss/event.rb', line 57 def to_json( = nil) ActiveSupport::JSON.encode(as_json()) end |
#user_context ⇒ Object
74 |
# File 'lib/lapsoss/event.rb', line 74 def user_context = context[:user] |