Class: XRay::SamplingRule

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-xray-sdk/sampling/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) ⇒ SamplingRule

Returns a new instance of SamplingRule.

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/sampling_rule.rb', line 14

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

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

  @default = default
  validate
  @reservoir = Reservoir.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/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/sampling_rule.rb', line 9

def fixed_target
  @fixed_target
end

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/aws-xray-sdk/sampling/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/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/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/sampling_rule.rb', line 9

def reservoir
  @reservoir
end

#service_nameObject (readonly)

Returns the value of attribute service_name.



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

def service_name
  @service_name
end

Instance Method Details

#applies?(target_name:, target_path:, target_method:) ⇒ 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
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 30

def applies?(target_name:, target_path:, target_method:)
  name_match   = !target_name   || SearchPattern.wildcard_match?(pattern: @service_name, text: target_name)
  path_match   = !target_path   || SearchPattern.wildcard_match?(pattern: @path, text: target_path)
  method_match = !target_method || SearchPattern.wildcard_match?(pattern: @method, text: target_method)
  name_match && path_match && method_match
end