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
# File 'lib/datadog/statsd/serialization/stat_serializer.rb', line 7

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

Instance Method Details

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/datadog/statsd/serialization/stat_serializer.rb', line 12

def format(name, delta, type, tags: [], sample_rate: 1)
  String.new.tap do |stat|
    stat << prefix if prefix

    # stat value
    stat << formated_name(name)
    stat << ':'
    stat << delta.to_s

    # stat type
    stat << '|'
    stat << type

    # sample_rate
    if sample_rate != 1
      stat << '|'
      stat << '@'
      stat << sample_rate.to_s
    end

    # tags
    if tags_list = tag_serializer.format(tags)
      stat << '|'
      stat << '#'
      stat << tags_list
    end
  end
end

#global_tagsObject



41
42
43
# File 'lib/datadog/statsd/serialization/stat_serializer.rb', line 41

def global_tags
  tag_serializer.global_tags
end