Method: NewRelic::Agent::RulesEngine.create_transaction_rules

Defined in:
lib/new_relic/agent/rules_engine.rb

.create_transaction_rules(connect_response) ⇒ Object

[View source]

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/new_relic/agent/rules_engine.rb', line 26

def self.create_transaction_rules(connect_response)
  txn_name_specs = connect_response['transaction_name_rules'] || []
  segment_rule_specs = connect_response['transaction_segment_terms'] || []

  txn_name_rules = txn_name_specs.map { |s| ReplacementRule.new(s) }

  segment_rules = []

  segment_rule_specs.each do |spec|
    if spec[SegmentTermsRule::PREFIX_KEY] && SegmentTermsRule.valid?(spec)
      # Build segment_rules in reverse order from which they're provided,
      # so that when we eliminate duplicates with #uniq!, we retain the last
      # instances of repeated rules.
      segment_rules.unshift(SegmentTermsRule.new(spec))
    end
  end

  reject_rules_with_duplicate_prefixes!(segment_rules)

  segment_rules.reverse! # Reset the rules to their original order.

  self.new(txn_name_rules, segment_rules)
end