Class: ScoutApm::MetricMeta

Inherits:
Object
  • Object
show all
Includes:
BucketNameSplitter
Defined in:
lib/scout_apm/metric_meta.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BucketNameSplitter

#bucket_name, #bucket_type, #key

Constructor Details

#initialize(metric_name, options = {}) ⇒ MetricMeta

Returns a new instance of MetricMeta.



6
7
8
9
10
11
12
# File 'lib/scout_apm/metric_meta.rb', line 6

def initialize(metric_name, options = {})
  @metric_name = metric_name
  @metric_id = nil
  @scope = options[:scope]
  @desc = options[:desc]
  @extra = {}
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



15
16
17
# File 'lib/scout_apm/metric_meta.rb', line 15

def client_id
  @client_id
end

#descObject

Returns the value of attribute desc.



16
17
18
# File 'lib/scout_apm/metric_meta.rb', line 16

def desc
  @desc
end

#extraObject

Returns the value of attribute extra.



16
17
18
# File 'lib/scout_apm/metric_meta.rb', line 16

def extra
  @extra
end

#metric_idObject

Returns the value of attribute metric_id.



13
14
15
# File 'lib/scout_apm/metric_meta.rb', line 13

def metric_id
  @metric_id
end

#metric_nameObject

Returns the value of attribute metric_name.



13
14
15
# File 'lib/scout_apm/metric_meta.rb', line 13

def metric_name
  @metric_name
end

#scopeObject

Returns the value of attribute scope.



14
15
16
# File 'lib/scout_apm/metric_meta.rb', line 14

def scope
  @scope
end

Class Method Details

.key_metric?(metric_name) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/scout_apm/metric_meta.rb', line 32

def self.key_metric?(metric_name)
  !!(metric_name =~ /\A(Controller|Job)\//)
end

Instance Method Details

#==(o) ⇒ Object



41
42
43
# File 'lib/scout_apm/metric_meta.rb', line 41

def ==(o)
  self.eql?(o)
end

#as_jsonObject



69
70
71
72
73
# File 'lib/scout_apm/metric_meta.rb', line 69

def as_json
  json_attributes = [:bucket, :name, :desc, :extra, [:scope, :scope_hash]]
  # query, stack_trace
  ScoutApm::AttributeArranger.call(self, json_attributes)
end

#backtraceObject



50
51
52
# File 'lib/scout_apm/metric_meta.rb', line 50

def backtrace
  extra[:backtrace]
end

#backtrace=(bt) ⇒ Object

This should be abstracted to a true accessor … earned it.



46
47
48
# File 'lib/scout_apm/metric_meta.rb', line 46

def backtrace=(bt)
  extra[:backtrace] = bt
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
# File 'lib/scout_apm/metric_meta.rb', line 61

def eql?(o)
 self.class             == o.class                &&
   metric_name.downcase == o.metric_name.downcase &&
   scope                == o.scope                &&
   client_id            == o.client_id            &&
   desc                 == o.desc
end

#hashObject



54
55
56
57
58
59
# File 'lib/scout_apm/metric_meta.rb', line 54

def hash
  h = metric_name.downcase.hash
  h ^= scope.downcase.hash unless scope.nil?
  h ^= desc.downcase.hash unless desc.nil?
  h
end

#key_metric?Boolean

A key metric is the “core” of a request - either the Rails controller reached, or the background Job executed

Returns:

  • (Boolean)


28
29
30
# File 'lib/scout_apm/metric_meta.rb', line 28

def key_metric?
  self.class.key_metric?(metric_name)
end

#nameObject



23
24
25
# File 'lib/scout_apm/metric_meta.rb', line 23

def name
  bucket_name
end

#to_json(*a) ⇒ Object

To avoid conflicts with different JSON libaries



37
38
39
# File 'lib/scout_apm/metric_meta.rb', line 37

def to_json(*a)
   %Q[{"metric_id":#{metric_id || 'null'},"metric_name":#{metric_name.to_json},"scope":#{scope.to_json || 'null'}}]
end

#typeObject

Unsure if type or bucket is a better name.



19
20
21
# File 'lib/scout_apm/metric_meta.rb', line 19

def type
  bucket_type
end