Module: PlainApm::Helpers

Defined in:
lib/plain_apm/helpers.rb

Instance Method Summary collapse

Instance Method Details

#plain_apm_context(context = {}) ⇒ Object



3
4
5
6
# File 'lib/plain_apm/helpers.rb', line 3

def plain_apm_context(context = {})
  return context unless PlainApm.agent.enabled?
  PlainApm::Extensions::Context.context.merge!(context)
end

#plain_apm_instrument(name, context = {}, &block) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/plain_apm/helpers.rb', line 8

def plain_apm_instrument(name, context = {}, &block)
  if PlainApm.agent.enabled? && defined?(ActiveSupport::Notifications)
    sanitized_name = name.gsub(/\W/, "_").gsub(/(?!^)([A-Z])/) { |m| "_#{m}" }.squeeze("_").downcase
    ActiveSupport::Notifications.instrument("#{sanitized_name}.manual_plain_apm", **context, &block)
  else
    yield if block
  end
end