Created
May 16, 2016 13:43
-
-
Save Geesu/541404c3e86972fc6ac54c2b4999a388 to your computer and use it in GitHub Desktop.
Instrumental wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Instrument | |
class << self | |
attr_reader :instrumental_agent | |
def time(metric, *args, &block) | |
instrumental_agent.time(metric, *args, &block) | |
end | |
def increment(metric, *args) | |
instrumental_agent.increment(metric, *args) | |
end | |
def gauge(metric, *args) | |
instrumental_agent.gauge(metric, *args) | |
end | |
def with_instrumentation(key_prefix, &block) | |
increment("#{key_prefix}.started") | |
begin | |
result = time("#{key_prefix}.duration", &block) | |
increment("#{key_prefix}.success") | |
result | |
rescue RedisMutex::LockError | |
increment("#{key_prefix}.already_running") | |
raise | |
rescue | |
increment("#{key_prefix}.failure") | |
raise | |
end | |
end | |
end | |
@instrumental_agent = Instrumental::Agent.new( | |
Rails.configuration.instrumental.api_key, | |
enabled: Rails.configuration.instrumental.enabled || Rails.env.production?, | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment