Class: XRay::DynamicNaming

Inherits:
Object
  • Object
show all
Includes:
SegmentNaming
Defined in:
lib/aws-xray-sdk/segment_naming/dynamic_naming.rb

Overview

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.

Instance Attribute Summary

Attributes included from SegmentNaming

#fallback, #pattern

Instance Method Summary collapse

Constructor Details

#initialize(fallback:) ⇒ DynamicNaming

Returns a new instance of DynamicNaming.

Parameters:

  • fallback (String)

    The fallback name used when there is no match between host name and specified pattern.



15
16
17
# File 'lib/aws-xray-sdk/segment_naming/dynamic_naming.rb', line 15

def initialize(fallback:)
  @fallback = fallback
end

Instance Method Details

#provide_name(host:) ⇒ Object

Parameters:

  • host (String)

    The host name fetched from the incoming request’s header.



20
21
22
23
24
# 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