class XRay::DynamicNaming

Decides what name to use on a segment generated from an incoming request. This default naming takes the host name and compares it to a pre-defined pattern. If the host name matches that pattern, it returns the host name, otherwise it returns the fallback name. The host name usually comes from the incoming request's headers.

Public Class Methods

new(fallback:) click to toggle source

@param [String] fallback The fallback name used when there is no match

between host name and specified pattern.
# File lib/aws-xray-sdk/segment_naming/dynamic_naming.rb, line 15
def initialize(fallback:)
  @fallback = fallback
end

Public Instance Methods

provide_name(host:) click to toggle source

@param [String] host The host name fetched from the incoming request's header.

# File lib/aws-xray-sdk/segment_naming/dynamic_naming.rb, line 20
def provide_name(host:)
  # use fallback name when either the pattern or host name is unavailable.
  return fallback unless pattern && !pattern.empty? && host && !host.empty?
  SearchPattern.wildcard_match?(pattern: pattern, text: host) ? host : fallback
end