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.
-
#send_error(error) ⇒ Object
Sends 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
60 61 62 63 64 65 66 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 60 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
73 74 75 76 77 78 79 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 73 def gauge(key, value, ) ::Appsignal.set_gauge( key, value, stringify_hash() ) end |
#metadata=(metadata_hash) ⇒ Object
Sets metadata on a current transaction (if any)
45 46 47 48 49 50 51 52 53 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 45 def () return unless transaction? transaction = ::Appsignal::Transaction.current stringify_hash().each do |key, value| transaction.(key, value) end end |
#register_probe(name, probe) ⇒ Object
Registers the probe under a given name
101 102 103 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 101 def register_probe(name, probe) ::Appsignal::Minutely.probes.register(name, probe) end |
#send_error(error) ⇒ Object
Sends the error that occurred to Appsignal
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 84 def send_error(error) # 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 if 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 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 25 def start_transaction(action_name) transaction = ::Appsignal::Transaction.create( SecureRandom.uuid, namespace_name, ::Appsignal::Transaction::GenericRequest.new({}) ) transaction.set_action_if_nil(action_name) end |
#stop_transaction ⇒ Object
Stops the current transaction (if any)
36 37 38 39 40 |
# File 'lib/karafka/instrumentation/vendors/appsignal/client.rb', line 36 def stop_transaction return unless transaction? ::Appsignal::Transaction.complete_current! end |