Skip to content

Instantly share code, notes, and snippets.

@Geesu
Created May 16, 2016 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Geesu/541404c3e86972fc6ac54c2b4999a388 to your computer and use it in GitHub Desktop.
Save Geesu/541404c3e86972fc6ac54c2b4999a388 to your computer and use it in GitHub Desktop.
Instrumental wrapper
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