Module: Yabeda::DSL::ClassMethods

Defined in:
lib/yabeda/dsl/class_methods.rb

Overview

rubocop: disable Style/Documentation

Instance Method Summary collapse

Instance Method Details

#collect(&block) ⇒ Object

Define the actions that should be performed



24
25
26
# File 'lib/yabeda/dsl/class_methods.rb', line 24

def collect(&block)
  ::Yabeda.collectors.push(block)
end

#configure(&block) ⇒ Object

Block for grouping and simplifying configuration of related metrics



17
18
19
20
21
# File 'lib/yabeda/dsl/class_methods.rb', line 17

def configure(&block)
  Yabeda.configurators.push([@group, block])
  class_exec(&block) if Yabeda.configured?
  @group = nil
end

#counter(*args, **kwargs, &block) ⇒ Object

Register a growing-only counter



42
43
44
45
# File 'lib/yabeda/dsl/class_methods.rb', line 42

def counter(*args, **kwargs, &block)
  metric = MetricBuilder.new(Counter).build(args, kwargs, @group, &block)
  register_metric(metric)
end

#default_tag(name, value, group: @group) ⇒ Object

Add default tag for all metric

Parameters:

  • name (Symbol)

    Name of default tag

  • value (String)

    Value of default tag



63
64
65
66
67
68
69
70
# File 'lib/yabeda/dsl/class_methods.rb', line 63

def default_tag(name, value, group: @group)
  if group
    Yabeda.groups[group] ||= Yabeda::Group.new(group)
    Yabeda.groups[group].default_tag(name, value)
  else
    Yabeda.default_tags[name] = value
  end
end

#gauge(*args, **kwargs, &block) ⇒ Object

Register a gauge



48
49
50
51
# File 'lib/yabeda/dsl/class_methods.rb', line 48

def gauge(*args, **kwargs, &block)
  metric = MetricBuilder.new(Gauge).build(args, kwargs, @group, &block)
  register_metric(metric)
end

#group(group_name) ⇒ Object

Specify metric category or group for all consecutive metrics in this configure block. On most adapters it is only adds prefix to the metric name but on some (like NewRelic) it is treated individually and has a special meaning.



32
33
34
35
36
37
38
39
# File 'lib/yabeda/dsl/class_methods.rb', line 32

def group(group_name)
  @group = group_name
  Yabeda.groups[@group] ||= Yabeda::Group.new(@group)
  return unless block_given?

  yield
  @group = nil
end

#histogram(*args, **kwargs, &block) ⇒ Object

Register a histogram



54
55
56
57
# File 'lib/yabeda/dsl/class_methods.rb', line 54

def histogram(*args, **kwargs, &block)
  metric = MetricBuilder.new(Histogram).build(args, kwargs, @group, &block)
  register_metric(metric)
end

#temporary_tagsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get tags set by with_tags

Returns:

  • Hash



85
86
87
# File 'lib/yabeda/dsl/class_methods.rb', line 85

def temporary_tags
  Thread.current[:yabeda_temporary_tags] ||= {}
end

#with_tags(**tags) ⇒ Object

Redefine default tags for a limited amount of time

Parameters:

  • tags

    HashSymbol=>#to_s



74
75
76
77
78
79
80
# File 'lib/yabeda/dsl/class_methods.rb', line 74

def with_tags(**tags)
  previous_temp_tags = temporary_tags
  Thread.current[:yabeda_temporary_tags] = Thread.current[:yabeda_temporary_tags].merge(tags)
  yield
ensure
  Thread.current[:yabeda_temporary_tags] = previous_temp_tags
end