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.
-
#session_tracker ⇒ Object
readonly
Returns the value of attribute session_tracker.
-
#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
-
#current_session_id ⇒ Object
The active release-health session id (nil before start / after shutdown).
-
#drain_offline_queue ⇒ Object
Replay any telemetry persisted by a previous process/outage.
- #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
-
#start_session ⇒ Object
Begin the release-health session.
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 22 23 24 25 26 |
# File 'lib/allstak/client.rb', line 6 def initialize(config, logger) @config = config @logger = logger @transport = Transport::HttpTransport.new(config, logger) # Release-health session tracker: one session per process. Started by # AllStak.configure after the release is resolved; ended in #shutdown. @session_tracker = SessionTracker.new(config, @transport, logger) @errors = Modules::Errors.new(@transport, config, logger, session_id_provider: -> { @session_tracker&.current_session_id }) @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 |
#session_tracker ⇒ Object (readonly)
Returns the value of attribute session_tracker.
4 5 6 |
# File 'lib/allstak/client.rb', line 4 def session_tracker @session_tracker 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
73 74 75 76 77 |
# File 'lib/allstak/client.rb', line 73 def capture_error(exception_class, , **kw) kw = (kw) mark_session_for(kw) @errors.capture_error(exception_class, , **kw) end |
#capture_exception(exc, **kw) ⇒ Object
67 68 69 70 71 |
# File 'lib/allstak/client.rb', line 67 def capture_exception(exc, **kw) kw = (kw) mark_session_for(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.
83 84 85 86 |
# File 'lib/allstak/client.rb', line 83 def (, level: "info", **kw) kw = (kw) @errors.capture_error("Message", .to_s, level: level.to_s, **kw) end |
#clear_user ⇒ Object
63 64 65 |
# File 'lib/allstak/client.rb', line 63 def clear_user @errors.clear_user end |
#current_session_id ⇒ Object
The active release-health session id (nil before start / after shutdown).
29 30 31 |
# File 'lib/allstak/client.rb', line 29 def current_session_id @session_tracker&.current_session_id end |
#drain_offline_queue ⇒ Object
Replay any telemetry persisted by a previous process/outage. Runs on a daemon thread so init never blocks on the network; fully fail-open. Called by AllStak.configure after the client is built. No-op when the offline queue is disabled/unavailable.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/allstak/client.rb', line 43 def drain_offline_queue transport = @transport return unless transport.respond_to?(:drain_spool) thread = Thread.new do begin transport.drain_spool rescue StandardError => e @logger&.debug("[AllStak] offline drain failed: #{e.class}: #{e.}") end end thread.abort_on_exception = false self rescue StandardError self end |
#flush ⇒ Object
108 109 110 111 112 113 |
# File 'lib/allstak/client.rb', line 108 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`.
103 104 105 106 |
# File 'lib/allstak/client.rb', line 103 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`.
90 91 92 93 |
# File 'lib/allstak/client.rb', line 90 def set_tag(key, value) @tags[key.to_s] = value.to_s self end |
#set_tags(pairs) ⇒ Object
Bulk-set tags.
96 97 98 99 |
# File 'lib/allstak/client.rb', line 96 def (pairs) pairs.each { |k, v| set_tag(k, v) } self end |
#set_user(id: nil, email: nil, ip: nil) ⇒ Object
59 60 61 |
# File 'lib/allstak/client.rb', line 59 def set_user(id: nil, email: nil, ip: nil) @errors.set_user(id: id, email: email, ip: ip) end |
#shutdown ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/allstak/client.rb', line 115 def shutdown flush @logs.shutdown @http.shutdown @tracing.shutdown @database.shutdown # Graceful shutdown: end the release-health session last so its # /sessions/end carries the final accumulated status. Best-effort. @session_tracker&.end rescue nil end |
#start_session ⇒ Object
Begin the release-health session. Idempotent + fail-open. Called by AllStak.configure once the release has been finalized.
35 36 37 |
# File 'lib/allstak/client.rb', line 35 def start_session @session_tracker&.start end |