Class: AllStak::Client
- Inherits:
-
Object
- Object
- AllStak::Client
- Defined in:
- lib/allstak/client.rb
Overview
The AllStak SDK client. Create once via configure.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
-
#cron ⇒ Object
readonly
Returns the value of attribute cron.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#logs ⇒ Object
readonly
Returns the value of attribute logs.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#tracing ⇒ Object
readonly
Returns the value of attribute tracing.
Instance Method Summary collapse
- #capture_error(exception_class, message, **kw) ⇒ Object
- #capture_exception(exc, **kw) ⇒ Object
-
#capture_message(message, level: "info", **kw) ⇒ Object
Capture a standalone string as an “error group” at the given level.
- #clear_user ⇒ Object
- #flush ⇒ Object
-
#initialize(config, logger) ⇒ Client
constructor
A new instance of Client.
-
#set_context(key, value) ⇒ Object
Attach a key/value context entry (goes into metadata on every event).
-
#set_tag(key, value) ⇒ Object
Attach a key/value tag to every subsequent event sent by the SDK.
-
#set_tags(pairs) ⇒ Object
Bulk-set tags.
- #set_user(id: nil, email: nil, ip: nil) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(config, logger) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/allstak/client.rb', line 6 def initialize(config, logger) @config = config @logger = logger @transport = Transport::HttpTransport.new(config, logger) @errors = Modules::Errors.new(@transport, config, logger) @logs = Modules::Logs.new(@transport, config, logger) @http = Modules::HttpMonitor.new(@transport, config, logger) @tracing = Modules::Tracing.new(@transport, config, logger) @database = Modules::Database.new(@transport, config, logger) @cron = Modules::Cron.new(@transport, logger, config) @tags = {} @contexts = {} at_exit { shutdown rescue nil } end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/allstak/client.rb', line 4 def config @config end |
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
4 5 6 |
# File 'lib/allstak/client.rb', line 4 def contexts @contexts end |
#cron ⇒ Object (readonly)
Returns the value of attribute cron.
4 5 6 |
# File 'lib/allstak/client.rb', line 4 def cron @cron end |
#database ⇒ Object (readonly)
Returns the value of attribute database.
4 5 6 |
# File 'lib/allstak/client.rb', line 4 def database @database end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/allstak/client.rb', line 4 def errors @errors end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
4 5 6 |
# File 'lib/allstak/client.rb', line 4 def http @http end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
4 5 6 |
# File 'lib/allstak/client.rb', line 4 def logger @logger end |
#logs ⇒ Object (readonly)
Returns the value of attribute logs.
4 5 6 |
# File 'lib/allstak/client.rb', line 4 def logs @logs end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
4 5 6 |
# File 'lib/allstak/client.rb', line 4 def @tags end |
#tracing ⇒ Object (readonly)
Returns the value of attribute tracing.
4 5 6 |
# File 'lib/allstak/client.rb', line 4 def tracing @tracing end |
Instance Method Details
#capture_error(exception_class, message, **kw) ⇒ Object
36 37 38 39 |
# File 'lib/allstak/client.rb', line 36 def capture_error(exception_class, , **kw) kw = (kw) @errors.capture_error(exception_class, , **kw) end |
#capture_exception(exc, **kw) ⇒ Object
31 32 33 34 |
# File 'lib/allstak/client.rb', line 31 def capture_exception(exc, **kw) kw = (kw) @errors.capture_exception(exc, **kw) end |
#capture_message(message, level: "info", **kw) ⇒ Object
Capture a standalone string as an “error group” at the given level. Cross-SDK parity with JS/Python/PHP/Java ‘captureMessage`. Implemented on top of capture_error so the dashboard surfaces it as an “info”/“warning”/“error” level entry in the Errors list.
45 46 47 48 |
# File 'lib/allstak/client.rb', line 45 def (, level: "info", **kw) kw = (kw) @errors.capture_error("Message", .to_s, level: level.to_s, **kw) end |
#clear_user ⇒ Object
27 28 29 |
# File 'lib/allstak/client.rb', line 27 def clear_user @errors.clear_user end |
#flush ⇒ Object
70 71 72 73 74 75 |
# File 'lib/allstak/client.rb', line 70 def flush @logs.flush @http.flush @tracing.flush @database.flush end |
#set_context(key, value) ⇒ Object
Attach a key/value context entry (goes into metadata on every event). Cross-SDK parity with JS/Python ‘setContext`.
65 66 67 68 |
# File 'lib/allstak/client.rb', line 65 def set_context(key, value) @contexts[key.to_s] = value self end |
#set_tag(key, value) ⇒ Object
Attach a key/value tag to every subsequent event sent by the SDK. Cross-SDK parity with JS ‘setTag` and Python `set_tag`.
52 53 54 55 |
# File 'lib/allstak/client.rb', line 52 def set_tag(key, value) @tags[key.to_s] = value.to_s self end |
#set_tags(pairs) ⇒ Object
Bulk-set tags.
58 59 60 61 |
# File 'lib/allstak/client.rb', line 58 def (pairs) pairs.each { |k, v| set_tag(k, v) } self end |
#set_user(id: nil, email: nil, ip: nil) ⇒ Object
23 24 25 |
# File 'lib/allstak/client.rb', line 23 def set_user(id: nil, email: nil, ip: nil) @errors.set_user(id: id, email: email, ip: ip) end |
#shutdown ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/allstak/client.rb', line 77 def shutdown flush @logs.shutdown @http.shutdown @tracing.shutdown @database.shutdown end |