class Datadog::Statsd::Serialization::StatSerializer
Attributes
prefix[R]
tag_serializer[R]
Public Class Methods
new(prefix, global_tags: [])
click to toggle source
# 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
Public Instance Methods
format(metric_name, delta, type, tags: [], sample_rate: 1)
click to toggle source
# File lib/datadog/statsd/serialization/stat_serializer.rb, line 13 def format(metric_name, delta, type, tags: [], sample_rate: 1) metric_name = formatted_metric_name(metric_name) if sample_rate != 1 if tags_list = tag_serializer.format(tags) "#{@prefix_str}#{metric_name}:#{delta}|#{type}|@#{sample_rate}|##{tags_list}" else "#{@prefix_str}#{metric_name}:#{delta}|#{type}|@#{sample_rate}" end else if tags_list = tag_serializer.format(tags) "#{@prefix_str}#{metric_name}:#{delta}|#{type}|##{tags_list}" else "#{@prefix_str}#{metric_name}:#{delta}|#{type}" end end end
Private Instance Methods
formatted_metric_name(metric_name)
click to toggle source
# File lib/datadog/statsd/serialization/stat_serializer.rb, line 50 def formatted_metric_name(metric_name) formatted = metric_name_to_string(metric_name) if formatted.include?('::') formatted = formatted.gsub('::', '.') formatted.tr!(':|@', '_') formatted elsif formatted.include?(':') || formatted.include?('@') || formatted.include?('|') formatted.tr(':|@', '_') else formatted end end
metric_name_to_string(metric_name)
click to toggle source
# File lib/datadog/statsd/serialization/stat_serializer.rb, line 41 def metric_name_to_string(metric_name) metric_name.to_s end