module Datadog::Tracing::Metadata::Tagging
def clear_metric(key)
def clear_metric(key) metrics.delete(key) end
def clear_tag(key)
def clear_tag(key) meta.delete(key) end
def get_metric(key)
def get_metric(key) metrics[key] || meta[key] end
def get_tag(key)
def get_tag(key) meta[key] || metrics[key] end
def has_tag?(tag) # rubocop:disable Naming/PredicateName
-
(Boolean)
- if the tag is present and not nil
Parameters:
-
tag
(String
) -- the tag or metric to check for presence
def has_tag?(tag) # rubocop:disable Naming/PredicateName !get_tag(tag).nil? # nil is considered not present, thus we can't use `Hash#has_key?` end
def meta
def meta @meta ||= {} end
def metrics
def metrics @metrics ||= {} end
def set_metric(key, value)
This method sets a tag with a floating point value for the given key. It acts
def set_metric(key, value) # Keys must be unique between tags and metrics meta.delete(key) # enforce that the value is a floating point number value = Float(value) # Encode strings in UTF-8 to facilitate downstream serialization metrics[Core::Utils.utf8_encode(key)] = value rescue StandardError => e Datadog.logger.debug("Unable to set the metric #{key}, ignoring it. Caused by: #{e}") end
def set_tag(key, value = nil)
must be strings. A valid example is:
Set the given key / value tag pair on the span. Keys and values
def set_tag(key, value = nil) # Keys must be unique between tags and metrics metrics.delete(key) # DEV: This is necessary because the agent looks at `meta[key]`, not `metrics[key]`. value = value.to_s if ENSURE_AGENT_TAGS[key] # NOTE: Adding numeric tags as metrics is stop-gap support # for numeric typed tags. Eventually they will become # tags again. # Any numeric that is not an integer greater than max size is logged as a metric. # Everything else gets logged as a tag. if value.is_a?(Numeric) && !(value.is_a?(Integer) && !NUMERIC_TAG_SIZE_RANGE.cover?(value)) set_metric(key, value) else # Encode strings in UTF-8 to facilitate downstream serialization meta[Core::Utils.utf8_encode(key)] = Core::Utils.utf8_encode(value) end rescue StandardError => e Datadog.logger.debug("Unable to set the tag #{key}, ignoring it. Caused by: #{e}") end
def set_tags(hash)
A valid example is:
of the hash must be strings. Note that nested hashes are not supported.
and associated value from the hash. It is shortcut for `set_tag`. Keys and values
Sets tags from given hash, for each key in hash it sets the tag with that key
def set_tags(hash) hash.each { |k, v| set_tag(k, v) } end
def tags
Returns a copy of all metadata.
def tags meta.merge(metrics) end