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, allow_nested: false) ⇒ Object

Normalizes an HTTP header string into a valid tag string.

By default, tags cannot create nested span tag levels: ‘allow_nested` allows you to override this behavior.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/datadog/tracing/metadata/ext.rb', line 100

def to_tag(name, allow_nested: false)
  # 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!('.', '_') unless allow_nested
  tag
end