Class: Datadog::Statsd::Serialization::StatSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/statsd/serialization/stat_serializer.rb

Instance Method Summary collapse

Constructor Details

#initialize(prefix, global_tags: []) ⇒ StatSerializer

Returns a new instance of StatSerializer.



7
8
9
10
11
# File 'lib/datadog/statsd/serialization/stat_serializer.rb', line 7

def initialize(prefix, global_tags: [])
  @prefix = prefix
  @prefix_str = prefix.to_s
  @tag_serializer = TagSerializer.new(global_tags)
end

Instance Method Details

#format(name, delta, type, tags: [], sample_rate: 1) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/datadog/statsd/serialization/stat_serializer.rb', line 13

def format(name, delta, type, tags: [], sample_rate: 1)
  name = formated_name(name)

  if sample_rate != 1
    if tags_list = tag_serializer.format(tags)
      "#{@prefix_str}#{name}:#{delta}|#{type}|@#{sample_rate}|##{tags_list}"
    else
      "#{@prefix_str}#{name}:#{delta}|#{type}|@#{sample_rate}"
    end
  else
    if tags_list = tag_serializer.format(tags)
      "#{@prefix_str}#{name}:#{delta}|#{type}|##{tags_list}"
    else
      "#{@prefix_str}#{name}:#{delta}|#{type}"
    end
  end
end

#global_tagsObject



31
32
33
# File 'lib/datadog/statsd/serialization/stat_serializer.rb', line 31

def global_tags
  tag_serializer.global_tags
end