Class: XRay::LocalSamplingRule

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-xray-sdk/sampling/local/sampling_rule.rb

Overview

One SamplingRule object represents one rule defined from the rules hash definition. It can be either a custom rule or the default rule.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule_definition:, default: false) ⇒ LocalSamplingRule

Returns a new instance of LocalSamplingRule.

Parameters:

  • rule_definition (Hash)

    Hash that defines a single rule.

  • default (defaults to: false)

    A boolean flag indicates if this rule is the default rule.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/aws-xray-sdk/sampling/local/sampling_rule.rb', line 14

def initialize(rule_definition:, default: false)
  @fixed_target = rule_definition[:fixed_target]
  @rate = rule_definition[:rate]

  @host = rule_definition[:host]
  @method = rule_definition[:http_method]
  @path = rule_definition[:url_path]

  @default = default
  validate
  @reservoir = LocalReservoir.new traces_per_sec: @fixed_target
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



9
10
11
# File 'lib/aws-xray-sdk/sampling/local/sampling_rule.rb', line 9

def default
  @default
end

#fixed_targetObject (readonly)

Returns the value of attribute fixed_target.



9
10
11
# File 'lib/aws-xray-sdk/sampling/local/sampling_rule.rb', line 9

def fixed_target
  @fixed_target
end

#hostObject (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/aws-xray-sdk/sampling/local/sampling_rule.rb', line 9

def host
  @host
end

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/aws-xray-sdk/sampling/local/sampling_rule.rb', line 9

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/aws-xray-sdk/sampling/local/sampling_rule.rb', line 9

def path
  @path
end

#rateObject (readonly)

Returns the value of attribute rate.



9
10
11
# File 'lib/aws-xray-sdk/sampling/local/sampling_rule.rb', line 9

def rate
  @rate
end

#reservoirObject (readonly)

Returns the value of attribute reservoir.



9
10
11
# File 'lib/aws-xray-sdk/sampling/local/sampling_rule.rb', line 9

def reservoir
  @reservoir
end

Instance Method Details

#applies?(sampling_req) ⇒ Boolean

Determines whether or not this sampling rule applies to the incoming request based on some of the request’s parameters. Any None parameters provided will be considered an implicit match.

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/aws-xray-sdk/sampling/local/sampling_rule.rb', line 30

def applies?(sampling_req)
  return false if sampling_req.nil? || sampling_req.empty?

  host = sampling_req[:host]
  url_path = sampling_req[:url_path]
  http_method = sampling_req[:http_method]

  host_match = !host || SearchPattern.wildcard_match?(pattern: @host, text: host)
  path_match = !url_path || SearchPattern.wildcard_match?(pattern: @path, text: url_path)
  method_match = !http_method || SearchPattern.wildcard_match?(pattern: @method, text: http_method)
  host_match && path_match && method_match
end