Class: NewRelic::Agent::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/attributes.rb

Constant Summary collapse

KEY_LIMIT =
255
VALUE_LIMIT =
255
COUNT_LIMIT =
64

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter) ⇒ Attributes

Returns a new instance of Attributes.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/new_relic/agent/attributes.rb', line 16

def initialize(filter)
  @filter = filter

  @custom_attributes = {}
  @agent_attributes = {}
  @intrinsic_attributes = {}

  @custom_destinations = {}
  @agent_destinations = {}
  @already_warned_count_limit = nil
end

Instance Attribute Details

#custom_attributesObject (readonly)



14
15
16
# File 'lib/new_relic/agent/attributes.rb', line 14

def custom_attributes
  @custom_attributes
end

Instance Method Details

#add_agent_attribute(key, value, default_destinations) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/new_relic/agent/attributes.rb', line 28

def add_agent_attribute(key, value, default_destinations)
  destinations = @filter.apply(key, default_destinations)
  return if destinations == AttributeFilter::DST_NONE

  @agent_destinations[key] = destinations
  add(@agent_attributes, key, value)
end

#add_agent_attribute_with_key_check(key, value, default_destinations) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/new_relic/agent/attributes.rb', line 36

def add_agent_attribute_with_key_check(key, value, default_destinations)
  if exceeds_bytesize_limit?(key, KEY_LIMIT)
    NewRelic::Agent.logger.debug("Agent attribute #{key} was dropped for exceeding key length limit #{KEY_LIMIT}")
    return
  end

  add_agent_attribute(key, value, default_destinations)
end

#add_intrinsic_attribute(key, value) ⇒ Object



45
46
47
# File 'lib/new_relic/agent/attributes.rb', line 45

def add_intrinsic_attribute(key, value)
  add(@intrinsic_attributes, key, value)
end

#agent_attributes_for(destination) ⇒ Object



71
72
73
# File 'lib/new_relic/agent/attributes.rb', line 71

def agent_attributes_for(destination)
  for_destination(@agent_attributes, @agent_destinations, destination)
end

#custom_attributes_for(destination) ⇒ Object



67
68
69
# File 'lib/new_relic/agent/attributes.rb', line 67

def custom_attributes_for(destination)
  for_destination(@custom_attributes, @custom_destinations, destination)
end

#intrinsic_attributes_for(destination) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/new_relic/agent/attributes.rb', line 75

def intrinsic_attributes_for(destination)
  if destination == NewRelic::Agent::AttributeFilter::DST_TRANSACTION_TRACER ||
      destination == NewRelic::Agent::AttributeFilter::DST_ERROR_COLLECTOR
    @intrinsic_attributes
  else
    NewRelic::EMPTY_HASH
  end
end

#merge_custom_attributes(other) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/new_relic/agent/attributes.rb', line 58

def merge_custom_attributes(other)
  return unless Agent.config[:'custom_attributes.enabled']
  return if other.empty?

  AttributeProcessing.flatten_and_coerce(other) do |k, v|
    add_custom_attribute(k, v)
  end
end

#merge_untrusted_agent_attributes(attributes, prefix, default_destinations) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/new_relic/agent/attributes.rb', line 49

def merge_untrusted_agent_attributes(attributes, prefix, default_destinations)
  return if @filter.high_security?
  return if !@filter.might_allow_prefix?(prefix)

  AttributeProcessing.flatten_and_coerce(attributes, prefix) do |k, v|
    add_agent_attribute_with_key_check(k, v, AttributeFilter::DST_NONE)
  end
end