Class: Datadog::Tracing::Configuration::HTTP::HeaderTags
- Inherits:
-
Object
- Object
- Datadog::Tracing::Configuration::HTTP::HeaderTags
- Defined in:
- lib/datadog/tracing/configuration/http.rb
Overview
Datadog tracing supports capturing HTTP request and response headers as span tags.
The provided configuration String for this feature has to be pre-processed to allow for ease of utilization by each HTTP integration.
This class process configuration, stores the result, and provides methods to utilize this configuration.
Instance Method Summary collapse
-
#initialize(header_tags) ⇒ HeaderTags
constructor
A new instance of HeaderTags.
-
#request_tags(headers) ⇒ Object
Receives a case insensitive hash with the request headers and returns a list of tag names and values that can be set in a span.
-
#response_tags(headers) ⇒ Object
Receives a case insensitive hash with the response headers and returns a list of tag names and values that can be set in a span.
-
#to_s ⇒ Object
For easy configuration inspection, print the original configuration setting.
Constructor Details
#initialize(header_tags) ⇒ HeaderTags
Returns a new instance of HeaderTags.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/datadog/tracing/configuration/http.rb', line 16 def initialize() @request_headers = {} @response_headers = {} = .each do |header_tag| header, tag = header_tag.split(':', 2) next unless header # Empty string guard if tag && !tag.empty? # When a custom tag name is provided, use that name for both # request and response tags. normalized_tag = Tracing::Metadata::Ext::HTTP::Headers.to_tag(tag, allow_nested: true) request = response = normalized_tag else # Otherwise, use our internal pattern of # "http.{request|response}.headers.{header}" as tag name. request = Tracing::Metadata::Ext::HTTP::RequestHeaders.to_tag(header) response = Tracing::Metadata::Ext::HTTP::ResponseHeaders.to_tag(header) end @request_headers[header] = request @response_headers[header] = response end end |
Instance Method Details
#request_tags(headers) ⇒ Object
Receives a case insensitive hash with the request headers and returns a list of tag names and values that can be set in a span.
45 46 47 48 49 50 51 52 |
# File 'lib/datadog/tracing/configuration/http.rb', line 45 def (headers) @request_headers.map do |header_name, span_tag| # Case-insensitive search header_value = headers[header_name] [span_tag, header_value] if header_value end.compact end |
#response_tags(headers) ⇒ Object
Receives a case insensitive hash with the response headers and returns a list of tag names and values that can be set in a span.
56 57 58 59 60 61 62 63 |
# File 'lib/datadog/tracing/configuration/http.rb', line 56 def (headers) @response_headers.map do |header_name, span_tag| # Case-insensitive search header_value = headers[header_name] [span_tag, header_value] if header_value end.compact end |
#to_s ⇒ Object
For easy configuration inspection, print the original configuration setting.
67 68 69 |
# File 'lib/datadog/tracing/configuration/http.rb', line 67 def to_s .join(',').to_s end |