Class: D13n::Metric::Instrumentation::ControllerInstrumentation::StreamNamer

Inherits:
Object
  • Object
show all
Defined in:
lib/d13n/metric/instrumentation/controller_instrumentation.rb

Class Method Summary collapse

Class Method Details

.kls_name(trace_obj, options = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/d13n/metric/instrumentation/controller_instrumentation.rb', line 78

def self.kls_name(trace_obj, options={})
  return options[:class_name] if options[:class_name]

  if (trace_obj.is_a?(Class) || trace_obj.is_a?(Module))
    return nil if trace_obj.name.nil?
    trace_obj.name.underscore
  else
    return nil if trace_obj.class.name.nil?
    trace_obj.class.name.underscore
  end
end

.name_for(stream, trace_obj, category, options = {}) ⇒ Object



48
49
50
# File 'lib/d13n/metric/instrumentation/controller_instrumentation.rb', line 48

def self.name_for(stream, trace_obj, category, options={})
  "#{prefix_for_category(stream, category)}.#{namespace(trace_obj, options)}"
end

.namespace(traced_obj, options = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/d13n/metric/instrumentation/controller_instrumentation.rb', line 61

def self.namespace(traced_obj, options={})
  return options[:namespace] if options[:namespace]

  kls_name = kls_name(traced_obj, options)
  if options[:name]
    if kls_name
      "#{kls_name}.#{options[:name]}"
    else
      options[:name]
    end
  elsif traced_obj.respond_to?(:d13n_metric_namespace)
    traced_obj.d13n_metric_namespace
  else
    kls_name
  end
end

.prefix_for_category(stream, category = nil) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/d13n/metric/instrumentation/controller_instrumentation.rb', line 52

def self.prefix_for_category(stream, category = nil)
  category ||= (stream && stream.category)
  case category
  when :sinatra  then ::D13n::Metric::Stream::SINATRA_PREFIX
  when :middleware then ::D13n::Metric::Stream::MIDDLEWARE_PREFIX
  else "#{category.to_s}"
  end
end