Class: Karafka::Instrumentation::Vendors::Appsignal::Client
- Inherits:
-
Object
- Object
- Karafka::Instrumentation::Vendors::Appsignal::Client
- Defined in:
- lib/karafka/instrumentation/vendors/appsignal/client.rb
Overview
This client is abstract, it has no notion of Karafka whatsoever
Appsignal client wrapper We wrap the native client so we can inject our own stub in specs when needed
It also abstracts away the notion of transactions and their management
Instance Method Summary collapse
-
#count(key, value, tags) ⇒ Object
Increments counter with the given value and tags.
-
#gauge(key, value, tags) ⇒ Object
Sets gauge with the given value and tags.
-
#initialize(namespace_name: nil) ⇒ Client
constructor
A new instance of Client.
-
#metadata=(metadata_hash) ⇒ Object
Sets metadata on a current transaction (if any).
-
#register_probe(name, probe) ⇒ Object
Registers the probe under a given name.
-
#report_error(error) ⇒ Object
Report the error that occurred to Appsignal.
-
#start_transaction(action_name) ⇒ Object
Starts an appsignal transaction with a given action name.
-
#stop_transaction ⇒ Object
Stops the current transaction (if any).
Constructor Details
#initialize(namespace_name: nil) ⇒ Client
Returns a new instance of Client.
17 18 19 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 17 def initialize(namespace_name: nil) @namespace_name = namespace_name end |
Instance Method Details
#count(key, value, tags) ⇒ Object
Increments counter with the given value and tags
65 66 67 68 69 70 71 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 65 def count(key, value, ) ::Appsignal.increment_counter( key, value, stringify_hash() ) end |
#gauge(key, value, tags) ⇒ Object
Sets gauge with the given value and tags
78 79 80 81 82 83 84 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 78 def gauge(key, value, ) ::Appsignal.set_gauge( key, value, stringify_hash() ) end |
#metadata=(metadata_hash) ⇒ Object
Sets metadata on a current transaction (if any)
50 51 52 53 54 55 56 57 58 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 50 def () return unless transaction? current_transaction = transaction stringify_hash().each do |key, value| current_transaction.(key, value) end end |
#register_probe(name, probe) ⇒ Object
Registers the probe under a given name
111 112 113 114 115 116 117 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 111 def register_probe(name, probe) if ::Appsignal::Probes.respond_to?(:register) ::Appsignal::Probes.register(name, probe) else ::Appsignal::Minutely.probes.register(name, probe) end end |
#report_error(error) ⇒ Object
Report the error that occurred to Appsignal
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 89 def report_error(error) if ::Appsignal.respond_to?(:report_error) # This helper will always report the error ::Appsignal.report_error(error) do |transaction| transaction.set_namespace(namespace_name) end # If we have an active transaction we should use it instead of creating a generic one # That way proper namespace and other data may be transferred # # In case there is no transaction, a new generic background job one will be used elsif transaction? transaction.set_error(error) else ::Appsignal.send_error(error) do |transaction| transaction.set_namespace(namespace_name) end end end |
#start_transaction(action_name) ⇒ Object
Starts an appsignal transaction with a given action name
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 25 def start_transaction(action_name) transaction = if version_4_or_newer? ::Appsignal::Transaction.create(namespace_name) else ::Appsignal::Transaction.create( SecureRandom.uuid, namespace_name, ::Appsignal::Transaction::GenericRequest.new({}) ) end transaction.set_action_if_nil(action_name) end |
#stop_transaction ⇒ Object
Stops the current transaction (if any)
41 42 43 44 45 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 41 def stop_transaction return unless transaction? ::Appsignal::Transaction.complete_current! end |