Module: AllStak

Defined in:
lib/allstak.rb,
lib/allstak/client.rb,
lib/allstak/config.rb,
lib/allstak/version.rb,
lib/allstak/modules/cron.rb,
lib/allstak/modules/logs.rb,
lib/allstak/modules/errors.rb,
lib/allstak/modules/tracing.rb,
lib/allstak/modules/database.rb,
lib/allstak/integrations/rack.rb,
lib/allstak/models/user_context.rb,
lib/allstak/modules/http_monitor.rb,
lib/allstak/integrations/net_http.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

# Rack / Rails: add the middleware
use AllStak::Integrations::Rack::Middleware

# Manual:
AllStak.capture_exception(exc)
AllStak.log.info("hello", metadata: { foo: "bar" })
AllStak.cron.job("daily-report") { generate_report }

Defined Under Namespace

Modules: Integrations, Models, Modules, Transport Classes: Client, Config

Constant Summary collapse

VERSION =
"0.1.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject (readonly)

Returns the value of attribute logger.



44
45
46
# File 'lib/allstak.rb', line 44

def logger
  @logger
end

Class Method Details

.capture_error(exception_class, message, **kw) ⇒ Object



79
80
81
# File 'lib/allstak.rb', line 79

def capture_error(exception_class, message, **kw)
  @client&.capture_error(exception_class, message, **kw)
end

.capture_exception(exc, **kw) ⇒ Object



75
76
77
# File 'lib/allstak.rb', line 75

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.



86
87
88
# File 'lib/allstak.rb', line 86

def capture_message(message, level: "info", **kw)
  @client&.capture_message(message, level: level, **kw)
end

.clear_userObject



94
95
96
# File 'lib/allstak.rb', line 94

def clear_user
  @client&.clear_user
end

.clientObject



71
72
73
# File 'lib/allstak.rb', line 71

def client
  @client or raise "AllStak not configured. Call AllStak.configure { |c| ... } first."
end

.configureObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/allstak.rb', line 46

def configure
  @mutex.synchronize do
    @config ||= Config.new
    yield @config if block_given?
    @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)
      # Auto-wire integrations that are safe to install
      AllStak::Integrations::ActiveRecordIntegration::Subscriber.install!
      AllStak::Integrations::NetHTTP.install!
    else
      @logger.warn("[AllStak] api_key not set — SDK not started")
      @client = nil
    end
    @client
  end
end

.cronObject



130
131
132
# File 'lib/allstak.rb', line 130

def cron
  @client&.cron
end

.databaseObject



126
127
128
# File 'lib/allstak.rb', line 126

def database
  @client&.database
end

.flushObject



134
135
136
# File 'lib/allstak.rb', line 134

def flush
  @client&.flush
end

.httpObject



122
123
124
# File 'lib/allstak.rb', line 122

def http
  @client&.http
end

.initialized?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/allstak.rb', line 67

def initialized?
  !@client.nil?
end

.logObject



114
115
116
# File 'lib/allstak.rb', line 114

def log
  @client&.logs
end

.reset!Object

Test helper.



143
144
145
146
147
148
149
# File 'lib/allstak.rb', line 143

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.



110
111
112
# File 'lib/allstak.rb', line 110

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.



100
101
102
# File 'lib/allstak.rb', line 100

def set_tag(key, value)
  @client&.set_tag(key, value)
end

.set_tags(pairs) ⇒ Object



104
105
106
# File 'lib/allstak.rb', line 104

def set_tags(pairs)
  @client&.set_tags(pairs)
end

.set_user(**kw) ⇒ Object



90
91
92
# File 'lib/allstak.rb', line 90

def set_user(**kw)
  @client&.set_user(**kw)
end

.shutdownObject



138
139
140
# File 'lib/allstak.rb', line 138

def shutdown
  @client&.shutdown
end

.tracingObject



118
119
120
# File 'lib/allstak.rb', line 118

def tracing
  @client&.tracing
end