Module: OpenTelemetry::Sampler::XRay::Utils
- Defined in:
- lib/opentelemetry/sampler/xray/utils.rb
Overview
Utils contains utilities for X-Ray Sampling Rule matching logic
Constant Summary collapse
- CLOUD_PLATFORM_MAPPING =
{ 'aws_lambda' => 'AWS::Lambda::Function', 'aws_elastic_beanstalk' => 'AWS::ElasticBeanstalk::Environment', 'aws_ec2' => 'AWS::EC2::Instance', 'aws_ecs' => 'AWS::ECS::Container', 'aws_eks' => 'AWS::EKS::Container' }.freeze
Class Method Summary collapse
- .attribute_match?(attributes = nil, rule_attributes = nil) ⇒ Boolean
- .convert_pattern_to_regexp(pattern) ⇒ Object
- .escape_regexp(regexp_pattern) ⇒ Object
- .wildcard_match(pattern = nil, text = nil) ⇒ Object
Class Method Details
.attribute_match?(attributes = nil, rule_attributes = nil) ⇒ Boolean
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/opentelemetry/sampler/xray/utils.rb', line 48 def attribute_match?(attributes = nil, rule_attributes = nil) return true if rule_attributes.nil? || rule_attributes.empty? return false if attributes.nil? || attributes.empty? || rule_attributes.length > attributes.length matched_count = 0 attributes.each do |key, value| found_key = rule_attributes.keys.find { |rule_key| rule_key == key } next if found_key.nil? matched_count += 1 if wildcard_match(rule_attributes[found_key], value) end matched_count == rule_attributes.length end |
.convert_pattern_to_regexp(pattern) ⇒ Object
27 28 29 |
# File 'lib/opentelemetry/sampler/xray/utils.rb', line 27 def convert_pattern_to_regexp(pattern) escape_regexp(pattern).gsub('*', '.*').tr('?', '.') end |
.escape_regexp(regexp_pattern) ⇒ Object
22 23 24 25 |
# File 'lib/opentelemetry/sampler/xray/utils.rb', line 22 def escape_regexp(regexp_pattern) # Escapes special characters except * and ? to maintain wildcard functionality regexp_pattern.gsub(/[.+^${}()|\[\]\\]/) { |match| "\\#{match}" } end |
.wildcard_match(pattern = nil, text = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/opentelemetry/sampler/xray/utils.rb', line 31 def wildcard_match(pattern = nil, text = nil) return true if pattern == '*' return false if pattern.nil? || !text.is_a?(String) return text.empty? if pattern.empty? regexp = "^#{convert_pattern_to_regexp(pattern.downcase)}$" match = text.downcase.match?(regexp) unless match OpenTelemetry.logger.debug( "WildcardMatch: no match found for #{text} against pattern #{pattern}" ) end match end |