Module: Datadog::Tracing::Metadata::Ext::HTTP::Headers

Defined in:
lib/datadog/tracing/metadata/ext.rb

Overview

General header functionality

Constant Summary collapse

INVALID_TAG_CHARACTERS =
%r{[^a-z0-9_\-:./]}.freeze

Class Method Summary collapse

Class Method Details

.to_tag(name) ⇒ Object

Normalizes an HTTP header string into a valid tag string.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/datadog/tracing/metadata/ext.rb', line 93

def to_tag(name)
  # Tag normalization based on: https://docs.datadoghq.com/getting_started/tagging/#defining-tags.
  #
  # Only the following characters are accepted.
  #  * Alphanumerics
  #  * Underscores
  #  * Minuses
  #  * Colons
  #  * Periods
  #  * Slashes
  #
  # All other characters are replaced with an underscore.
  tag = name.to_s.strip
  tag.downcase!
  tag.gsub!(INVALID_TAG_CHARACTERS, '_')

  # Additional HTTP header normalization.
  #
  # Periods are replaced with an underscore.
  tag.tr!('.', '_')
  tag
end