Module: Datadog::Tracing::Sampling::Span::RuleParser
- Defined in:
- lib/datadog/tracing/sampling/span/rule_parser.rb
Overview
Converts user configuration into Rule objects, handling any parsing errors.
Class Method Summary collapse
-
.parse_json(rules) ⇒ Array<Datadog::Tracing::Sampling::Span::Rule>?
Parses the provided JSON string containing the Single Span Sampling configuration list.
-
.parse_list(rules) ⇒ Array<Datadog::Tracing::Sampling::Span::Rule>?
Parses a list of Hashes containing the parsed JSON information for Single Span Sampling configuration.
Class Method Details
.parse_json(rules) ⇒ Array<Datadog::Tracing::Sampling::Span::Rule>?
Parses the provided JSON string containing the Single Span Sampling configuration list. In case of parsing errors, ‘nil` is returned.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/datadog/tracing/sampling/span/rule_parser.rb', line 24 def parse_json(rules) return nil unless rules begin list = JSON.parse(rules) rescue => e Datadog.logger.warn( "Error parsing Span Sampling Rules `#{rules.inspect}`: "\ "#{e.class.name} #{e.} at #{Array(e.backtrace).first}" ) return nil end parse_list(list) end |
.parse_list(rules) ⇒ Array<Datadog::Tracing::Sampling::Span::Rule>?
Parses a list of Hashes containing the parsed JSON information for Single Span Sampling configuration. In case of parsing errors, ‘nil` is returned.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/datadog/tracing/sampling/span/rule_parser.rb', line 47 def parse_list(rules) unless rules.is_a?(Array) Datadog.logger.warn("Span Sampling Rules are not an array: #{rules.inspect}") return nil end parsed = rules.map do |hash| unless hash.is_a?(Hash) Datadog.logger.warn("Span Sampling Rule is not a key-value object: #{hash.inspect}") return nil end begin parse_rule(hash) rescue => e Datadog.logger.warn( "Cannot parse Span Sampling Rule #{hash.inspect}: " \ "#{e.class.name} #{e} at #{Array(e.backtrace).first}" ) return nil end end parsed.compact! parsed end |