Class: Datadog::Statsd::Serialization::TagSerializer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(global_tags = [], env = ENV) ⇒ TagSerializer

Returns a new instance of TagSerializer.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/datadog/statsd/serialization/tag_serializer.rb', line 7

def initialize(global_tags = [], env = ENV)
  # Convert to hash
  global_tags = to_tags_hash(global_tags)

  # Merge with default tags
  global_tags = default_tags(env).merge(global_tags)

  # Convert to tag list and set
  @global_tags = to_tags_list(global_tags)
  if @global_tags.any?
    @global_tags_formatted = @global_tags.join(',')
  else
    @global_tags_formatted = nil
  end
end

Instance Attribute Details

#global_tagsObject (readonly)

Returns the value of attribute global_tags.



37
38
39
# File 'lib/datadog/statsd/serialization/tag_serializer.rb', line 37

def global_tags
  @global_tags
end

Instance Method Details

#format(message_tags) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/datadog/statsd/serialization/tag_serializer.rb', line 23

def format(message_tags)
  if !message_tags || message_tags.empty?
    return @global_tags_formatted
  end

  tags = if @global_tags_formatted
           [@global_tags_formatted, to_tags_list(message_tags)]
         else
           to_tags_list(message_tags)
         end

  tags.join(',')
end