Class: Sciosano::Report
- Inherits:
-
Object
- Object
- Sciosano::Report
- Defined in:
- lib/sciosano/report.rb
Overview
Report represents an error or message to be sent to sciosano
Instance Attribute Summary collapse
-
#breadcrumbs ⇒ Object
readonly
Returns the value of attribute breadcrumbs.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#report_type ⇒ Object
readonly
Returns the value of attribute report_type.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#user_description ⇒ Object
readonly
Returns the value of attribute user_description.
Class Method Summary collapse
-
.build_from_exception(exception, context:, breadcrumbs:, configuration:) ⇒ Report
Build report from an exception.
-
.build_from_message(message, level:, context:, breadcrumbs:, configuration:) ⇒ Report
Build report from a message.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Report
constructor
A new instance of Report.
-
#to_h ⇒ Hash
Convert to hash.
-
#to_json(*_args) ⇒ String
Convert to JSON for API.
Constructor Details
#initialize(attrs = {}) ⇒ Report
Returns a new instance of Report.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sciosano/report.rb', line 9 def initialize(attrs = {}) @id = attrs[:id] || SecureRandom.uuid @report_type = attrs[:report_type] || "error" @source = attrs[:source] || "backend" @error = attrs[:error] @user_description = attrs[:user_description] @context = attrs[:context] || {} @environment = attrs[:environment] || {} @breadcrumbs = attrs[:breadcrumbs] || [] @tags = attrs[:tags] || {} @timestamp = attrs[:timestamp] || Time.now.utc.iso8601(3) end |
Instance Attribute Details
#breadcrumbs ⇒ Object (readonly)
Returns the value of attribute breadcrumbs.
6 7 8 |
# File 'lib/sciosano/report.rb', line 6 def @breadcrumbs end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'lib/sciosano/report.rb', line 6 def context @context end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
6 7 8 |
# File 'lib/sciosano/report.rb', line 6 def environment @environment end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/sciosano/report.rb', line 6 def error @error end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/sciosano/report.rb', line 6 def id @id end |
#report_type ⇒ Object (readonly)
Returns the value of attribute report_type.
6 7 8 |
# File 'lib/sciosano/report.rb', line 6 def report_type @report_type end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/sciosano/report.rb', line 6 def source @source end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
6 7 8 |
# File 'lib/sciosano/report.rb', line 6 def @tags end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/sciosano/report.rb', line 6 def @timestamp end |
#user_description ⇒ Object (readonly)
Returns the value of attribute user_description.
6 7 8 |
# File 'lib/sciosano/report.rb', line 6 def user_description @user_description end |
Class Method Details
.build_from_exception(exception, context:, breadcrumbs:, configuration:) ⇒ Report
Build report from an exception
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sciosano/report.rb', line 29 def self.build_from_exception(exception, context:, breadcrumbs:, configuration:) new( report_type: "error", source: "backend", error: build_error_hash(exception), context: build_context_hash(context, configuration), environment: build_environment_hash(configuration), breadcrumbs: .map(&:to_h), tags: context. ) end |
.build_from_message(message, level:, context:, breadcrumbs:, configuration:) ⇒ Report
Build report from a message
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sciosano/report.rb', line 49 def self.(, level:, context:, breadcrumbs:, configuration:) new( report_type: "feedback", source: "backend", user_description: , context: build_context_hash(context, configuration), environment: build_environment_hash(configuration), breadcrumbs: .map(&:to_h), tags: context..merge("level" => level.to_s) ) end |
Instance Method Details
#to_h ⇒ Hash
Convert to hash
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/sciosano/report.rb', line 71 def to_h { reportType: report_type, source: source, error: error, userDescription: user_description, context: context, environment: environment, breadcrumbs: , tags: , timestamp: }.compact end |
#to_json(*_args) ⇒ String
Convert to JSON for API
64 65 66 |
# File 'lib/sciosano/report.rb', line 64 def to_json(*_args) JSON.generate(to_h) end |