Module: AllStak
- Defined in:
- lib/allstak.rb,
lib/allstak/client.rb,
lib/allstak/config.rb,
lib/allstak/version.rb,
lib/allstak/sampling.rb,
lib/allstak/sanitizer.rb,
lib/allstak/propagation.rb,
lib/allstak/modules/cron.rb,
lib/allstak/modules/logs.rb,
lib/allstak/global_handler.rb,
lib/allstak/modules/errors.rb,
lib/allstak/modules/tracing.rb,
lib/allstak/session_tracker.rb,
lib/allstak/modules/database.rb,
lib/allstak/integrations/rack.rb,
lib/allstak/integrations/rails.rb,
lib/allstak/models/user_context.rb,
lib/allstak/integrations/sidekiq.rb,
lib/allstak/modules/http_monitor.rb,
lib/allstak/integrations/net_http.rb,
lib/allstak/transport/event_spool.rb,
lib/allstak/transport/flush_buffer.rb,
lib/allstak/transport/http_transport.rb,
lib/allstak/integrations/active_record.rb
Overview
Official AllStak Ruby SDK.
Quick start:
require "allstak"
AllStak.configure do |c|
c.api_key = ENV["ALLSTAK_API_KEY"]
c.environment = "production"
c.release = "myapp@1.2.3"
c.service_name = "myapp-api"
end
use AllStak::Integrations::Rack::Middleware
AllStak.capture_exception(exc)
AllStak.log.info("hello", metadata: { foo: "bar" })
AllStak.cron.job("daily-report") { generate_report }
Defined Under Namespace
Modules: GitRelease, GlobalHandler, Integrations, Models, Modules, Propagation, Sampling, Sanitizer, Transport
Classes: Client, Config, SessionTracker
Constant Summary
collapse
- VERSION =
"0.2.1"
Class Attribute Summary collapse
Class Method Summary
collapse
-
.capture_error(exception_class, message, **kw) ⇒ Object
-
.capture_exception(exc, **kw) ⇒ Object
-
.capture_message(message, level: "info", **kw) ⇒ Object
Cross-SDK parity with JS captureMessage / Python capture_message / Java captureMessage.
-
.capture_unhandled(exc) ⇒ Object
Manually capture an exception as a global, unhandled event (mechanism=at_exit, handled=false) and flush synchronously.
-
.clear_user ⇒ Object
-
.client ⇒ Object
-
.configure ⇒ Object
-
.cron ⇒ Object
-
.database ⇒ Object
-
.flush ⇒ Object
-
.http ⇒ Object
-
.initialized? ⇒ Boolean
-
.log ⇒ Object
-
.register_runtime_release(config, logger) ⇒ Object
-
.reset! ⇒ Object
-
.set_context(key, value) ⇒ Object
Attach a custom context entry to every future event.
-
.set_tag(key, value) ⇒ Object
Attach a tag that sticks to every future event.
-
.set_tags(pairs) ⇒ Object
-
.set_user(**kw) ⇒ Object
-
.shutdown ⇒ Object
-
.tracing ⇒ Object
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
55
56
57
|
# File 'lib/allstak.rb', line 55
def logger
@logger
end
|
Class Method Details
.capture_error(exception_class, message, **kw) ⇒ Object
146
147
148
|
# File 'lib/allstak.rb', line 146
def capture_error(exception_class, message, **kw)
@client&.capture_error(exception_class, message, **kw)
end
|
.capture_exception(exc, **kw) ⇒ Object
142
143
144
|
# File 'lib/allstak.rb', line 142
def capture_exception(exc, **kw)
@client&.capture_exception(exc, **kw)
end
|
.capture_message(message, level: "info", **kw) ⇒ Object
Cross-SDK parity with JS captureMessage / Python capture_message / Java captureMessage. Emits a string as an error-group entry at the given level. Safe no-op if the SDK is not configured.
153
154
155
|
# File 'lib/allstak.rb', line 153
def capture_message(message, level: "info", **kw)
@client&.capture_message(message, level: level, **kw)
end
|
.capture_unhandled(exc) ⇒ Object
Manually capture an exception as a global, unhandled event (mechanism=at_exit, handled=false) and flush synchronously. Use this at the top of a worker/thread/process boundary where the framework would not otherwise route the exception through the Rack middleware. Safe no-op when the SDK is not configured.
.clear_user ⇒ Object
170
171
172
|
# File 'lib/allstak.rb', line 170
def clear_user
@client&.clear_user
end
|
.client ⇒ Object
112
113
114
|
# File 'lib/allstak.rb', line 112
def client
@client or raise "AllStak not configured. Call AllStak.configure { |c| ... } first."
end
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/allstak.rb', line 57
def configure
@mutex.synchronize do
@config ||= Config.new
yield @config if block_given?
@config.finalize_release!
@logger = Logger.new($stderr).tap do |l|
l.level = @config.debug ? Logger::DEBUG : Logger::WARN
l.progname = "allstak"
end
if @config.valid?
@client = Client.new(@config, @logger)
register_runtime_release(@config, @logger)
@client.start_session
@client.drain_offline_queue
AllStak::Integrations::ActiveRecordIntegration::Subscriber.install!
AllStak::Integrations::NetHTTP.install!
AllStak::Integrations::Sidekiq.install!
AllStak::Integrations::Rails.install!
if @config.install_at_exit_handler
begin
Thread.report_on_exception = true if Thread.respond_to?(:report_on_exception=)
rescue StandardError
end
AllStak::GlobalHandler.install!(@logger)
end
else
@logger.warn("[AllStak] api_key not set — SDK not started")
@client = nil
end
@client
end
end
|
.cron ⇒ Object
206
207
208
|
# File 'lib/allstak.rb', line 206
def cron
@client&.cron
end
|
.database ⇒ Object
202
203
204
|
# File 'lib/allstak.rb', line 202
def database
@client&.database
end
|
.flush ⇒ Object
210
211
212
|
# File 'lib/allstak.rb', line 210
def flush
@client&.flush
end
|
.http ⇒ Object
198
199
200
|
# File 'lib/allstak.rb', line 198
def http
@client&.http
end
|
.initialized? ⇒ Boolean
108
109
110
|
# File 'lib/allstak.rb', line 108
def initialized?
!@client.nil?
end
|
.log ⇒ Object
190
191
192
|
# File 'lib/allstak.rb', line 190
def log
@client&.logs
end
|
.register_runtime_release(config, logger) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/allstak.rb', line 116
def register_runtime_release(config, logger)
return unless config.auto_register_release
return if config.release.to_s.empty? || config.api_key.to_s.empty?
return if ENV["MT_TEST"] ||
ENV["RACK_ENV"] == "test" ||
ENV["RAILS_ENV"] == "test" ||
ENV["RUBYOPT"].to_s.include?("minitest") ||
$PROGRAM_NAME.to_s.include?("rspec")
thread = Thread.new do
begin
AllStak::Transport::HttpTransport.new(config, logger).post("/ingest/v1/releases", {
version: config.release,
environment: config.environment || "production",
commitSha: config.commit_sha,
branch: config.branch,
author: "#{config.sdk_name}/#{config.sdk_version}",
message: "Registered automatically by AllStak Ruby SDK at runtime"
})
rescue StandardError => e
logger.debug("[AllStak] runtime release registration failed: #{e.class}: #{e.message}") if logger
end
end
thread.abort_on_exception = false
end
|
.reset! ⇒ Object
219
220
221
222
223
224
225
|
# File 'lib/allstak.rb', line 219
def reset!
@mutex.synchronize do
@client&.shutdown rescue nil
@client = nil
@config = nil
end
end
|
.set_context(key, value) ⇒ Object
Attach a custom context entry to every future event. Cross-SDK parity with JS/Python setContext.
186
187
188
|
# File 'lib/allstak.rb', line 186
def set_context(key, value)
@client&.set_context(key, value)
end
|
.set_tag(key, value) ⇒ Object
Attach a tag that sticks to every future event. Cross-SDK parity with JS setTag / Python set_tag.
176
177
178
|
# File 'lib/allstak.rb', line 176
def set_tag(key, value)
@client&.set_tag(key, value)
end
|
180
181
182
|
# File 'lib/allstak.rb', line 180
def set_tags(pairs)
@client&.set_tags(pairs)
end
|
.set_user(**kw) ⇒ Object
166
167
168
|
# File 'lib/allstak.rb', line 166
def set_user(**kw)
@client&.set_user(**kw)
end
|
.shutdown ⇒ Object
214
215
216
|
# File 'lib/allstak.rb', line 214
def shutdown
@client&.shutdown
end
|
.tracing ⇒ Object
194
195
196
|
# File 'lib/allstak.rb', line 194
def tracing
@client&.tracing
end
|