Class: Sciosano::Client
- Inherits:
-
Object
- Object
- Sciosano::Client
- Defined in:
- lib/sciosano/client.rb
Overview
Main client for sending reports to sciosano API
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
-
#add_breadcrumb(breadcrumb) ⇒ Object
Add a breadcrumb.
-
#breadcrumbs ⇒ Object
Get current breadcrumbs.
-
#capture_exception(exception, context = {}) ⇒ String?
Capture an exception.
-
#capture_message(message, level: :info, context: {}) ⇒ String?
Capture a message.
-
#clear_breadcrumbs ⇒ Object
Clear breadcrumbs.
-
#clear_user ⇒ Object
Clear user context.
-
#initialize(configuration) ⇒ Client
constructor
A new instance of Client.
-
#set_extra(key, value) ⇒ Object
Set extra context.
-
#set_tags(tags) ⇒ Object
Set tags.
-
#set_user(id: nil, email: nil, name: nil, **extra) ⇒ Object
Set user context.
-
#with_context(context = {}) ⇒ Object
Execute block with additional context.
Constructor Details
#initialize(configuration) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sciosano/client.rb', line 8 def initialize(configuration) @configuration = configuration @configuration.validate! @context = Context.new = Concurrent::Array.new @executor = Concurrent::ThreadPoolExecutor.new( min_threads: 1, max_threads: 5, max_queue: 100, fallback_policy: :caller_runs # Don't silently discard - run in caller thread if queue full ) log("sciosano initialized with endpoint: #{configuration.endpoint}") end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
6 7 8 |
# File 'lib/sciosano/client.rb', line 6 def configuration @configuration end |
Instance Method Details
#add_breadcrumb(breadcrumb) ⇒ Object
Add a breadcrumb
62 63 64 65 66 67 68 69 |
# File 'lib/sciosano/client.rb', line 62 def () << # Keep only max_breadcrumbs while .size > configuration. .shift end end |
#breadcrumbs ⇒ Object
Get current breadcrumbs
101 102 103 |
# File 'lib/sciosano/client.rb', line 101 def .to_a end |
#capture_exception(exception, context = {}) ⇒ String?
Capture an exception
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sciosano/client.rb', line 28 def capture_exception(exception, context = {}) return nil unless should_capture?(exception) report = Report.build_from_exception( exception, context: @context.merge(context), breadcrumbs: .to_a, configuration: configuration ) send_report(report) end |
#capture_message(message, level: :info, context: {}) ⇒ String?
Capture a message
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sciosano/client.rb', line 47 def (, level: :info, context: {}) report = Report.( , level: level, context: @context.merge(context), breadcrumbs: .to_a, configuration: configuration ) send_report(report) end |
#clear_breadcrumbs ⇒ Object
Clear breadcrumbs
106 107 108 |
# File 'lib/sciosano/client.rb', line 106 def .clear end |
#clear_user ⇒ Object
Clear user context
77 78 79 |
# File 'lib/sciosano/client.rb', line 77 def clear_user @context.user = nil end |
#set_extra(key, value) ⇒ Object
Set extra context
82 83 84 |
# File 'lib/sciosano/client.rb', line 82 def set_extra(key, value) @context.extra[key.to_s] = value end |
#set_tags(tags) ⇒ Object
Set tags
87 88 89 |
# File 'lib/sciosano/client.rb', line 87 def () @context..merge!(.transform_keys(&:to_s)) end |
#set_user(id: nil, email: nil, name: nil, **extra) ⇒ Object
Set user context
72 73 74 |
# File 'lib/sciosano/client.rb', line 72 def set_user(id: nil, email: nil, name: nil, **extra) @context.user = { id: id, email: email, name: name, **extra }.compact end |
#with_context(context = {}) ⇒ Object
Execute block with additional context
92 93 94 95 96 97 98 |
# File 'lib/sciosano/client.rb', line 92 def with_context(context = {}) old_context = @context.dup @context.merge!(context) yield ensure @context = old_context end |