Class: AllStak::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/allstak/client.rb

Overview

The AllStak SDK client. Create once via configure.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/allstak/client.rb', line 4

def config
  @config
end

#contextsObject (readonly)

Returns the value of attribute contexts.



4
5
6
# File 'lib/allstak/client.rb', line 4

def contexts
  @contexts
end

#cronObject (readonly)

Returns the value of attribute cron.



4
5
6
# File 'lib/allstak/client.rb', line 4

def cron
  @cron
end

#databaseObject (readonly)

Returns the value of attribute database.



4
5
6
# File 'lib/allstak/client.rb', line 4

def database
  @database
end

#errorsObject (readonly)

Returns the value of attribute errors.



4
5
6
# File 'lib/allstak/client.rb', line 4

def errors
  @errors
end

#httpObject (readonly)

Returns the value of attribute http.



4
5
6
# File 'lib/allstak/client.rb', line 4

def http
  @http
end

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/allstak/client.rb', line 4

def logger
  @logger
end

#logsObject (readonly)

Returns the value of attribute logs.



4
5
6
# File 'lib/allstak/client.rb', line 4

def logs
  @logs
end

#tagsObject (readonly)

Returns the value of attribute tags.



4
5
6
# File 'lib/allstak/client.rb', line 4

def tags
  @tags
end

#tracingObject (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, message, **kw)
  kw = (kw)
  @errors.capture_error(exception_class, message, **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 capture_message(message, level: "info", **kw)
  kw = (kw)
  @errors.capture_error("Message", message.to_s, level: level.to_s, **kw)
end

#clear_userObject



27
28
29
# File 'lib/allstak/client.rb', line 27

def clear_user
  @errors.clear_user
end

#flushObject



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 set_tags(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

#shutdownObject



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