class Mmtrix::Agent::AttributeFilter
Constants
- DST_ALL
- DST_BROWSER_MONITORING
- DST_DEVELOPER_MODE
- DST_ERROR_COLLECTOR
- DST_NONE
- DST_TRANSACTION_EVENTS
- DST_TRANSACTION_TRACER
Attributes
rules[R]
Public Class Methods
new(config)
click to toggle source
# File lib/mmtrix/agent/attribute_filter.rb, line 77 def initialize(config) @enabled_destinations = DST_NONE @enabled_destinations |= DST_TRANSACTION_TRACER if config[:'transaction_tracer.attributes.enabled'] @enabled_destinations |= DST_TRANSACTION_EVENTS if config[:'transaction_events.attributes.enabled'] @enabled_destinations |= DST_ERROR_COLLECTOR if config[:'error_collector.attributes.enabled'] @enabled_destinations |= DST_BROWSER_MONITORING if config[:'browser_monitoring.attributes.enabled'] @enabled_destinations = DST_NONE unless config[:'attributes.enabled'] @rules = [] build_rule(config[:'attributes.exclude'], DST_ALL, false) build_rule(config[:'transaction_tracer.attributes.exclude'], DST_TRANSACTION_TRACER, false) build_rule(config[:'transaction_events.attributes.exclude'], DST_TRANSACTION_EVENTS, false) build_rule(config[:'error_collector.attributes.exclude'], DST_ERROR_COLLECTOR, false) build_rule(config[:'browser_monitoring.attributes.exclude'], DST_BROWSER_MONITORING, false) build_rule(['request.parameters.*'], include_destinations_for_capture_params(config[:capture_params]), true) build_rule(['job.resque.args.*'], include_destinations_for_capture_params(config[:'resque.capture_params']), true) build_rule(['job.sidekiq.args.*'], include_destinations_for_capture_params(config[:'sidekiq.capture_params']), true) build_rule(config[:'attributes.include'], DST_ALL, true) build_rule(config[:'transaction_tracer.attributes.include'], DST_TRANSACTION_TRACER, true) build_rule(config[:'transaction_events.attributes.include'], DST_TRANSACTION_EVENTS, true) build_rule(config[:'error_collector.attributes.include'], DST_ERROR_COLLECTOR, true) build_rule(config[:'browser_monitoring.attributes.include'], DST_BROWSER_MONITORING, true) @rules.sort! # We're ok to cache high security for fast lookup because the attribute # filter is re-generated on any significant config change. @high_security = config[:high_security] cache_prefix_blacklist end
Public Instance Methods
allows?(allowed_destinations, requested_destination)
click to toggle source
# File lib/mmtrix/agent/attribute_filter.rb, line 148 def allows?(allowed_destinations, requested_destination) allowed_destinations & requested_destination == requested_destination end
apply(attribute_name, default_destinations)
click to toggle source
# File lib/mmtrix/agent/attribute_filter.rb, line 129 def apply(attribute_name, default_destinations) return DST_NONE if @enabled_destinations == DST_NONE destinations = default_destinations attribute_name = attribute_name.to_s @rules.each do |rule| if rule.match?(attribute_name) if rule.is_include destinations |= rule.destinations else destinations &= rule.destinations end end end destinations & @enabled_destinations end
build_rule(attribute_names, destinations, is_include)
click to toggle source
# File lib/mmtrix/agent/attribute_filter.rb, line 122 def build_rule(attribute_names, destinations, is_include) attribute_names.each do |attribute_name| rule = AttributeFilterRule.new(attribute_name, destinations, is_include) @rules << rule unless rule.empty? end end
cache_prefix_blacklist()
click to toggle source
For attribute prefixes where we know the default destinations will always be DST_NONE
, we can statically determine that any attribute starting with the prefix will not be allowed unless there’s an include rule that might match attributes starting with it.
This allows us to skip significant preprocessing work (hash/array flattening and type coercion) for HTTP request parameters and job arguments for Sidekiq
and Resque
in the common case, since none of these attributes are captured by default.
# File lib/mmtrix/agent/attribute_filter.rb, line 166 def cache_prefix_blacklist @prefix_blacklist = {} @prefix_blacklist[:'request.parameters'] = true unless might_allow_prefix_uncached?(:'request.parameters') @prefix_blacklist[:'job.sidekiq.args'] = true unless might_allow_prefix_uncached?(:'job.sidekiq.args') @prefix_blacklist[:'job.resque.args'] = true unless might_allow_prefix_uncached?(:'job.resque.args') end
high_security?()
click to toggle source
# File lib/mmtrix/agent/attribute_filter.rb, line 152 def high_security? @high_security end
include_destinations_for_capture_params(capturing)
click to toggle source
# File lib/mmtrix/agent/attribute_filter.rb, line 114 def include_destinations_for_capture_params(capturing) if capturing DST_TRANSACTION_TRACER | DST_ERROR_COLLECTOR else DST_NONE end end
might_allow_prefix?(prefix)
click to toggle source
Note that the given prefix must be a Symbol
# File lib/mmtrix/agent/attribute_filter.rb, line 174 def might_allow_prefix?(prefix) !@prefix_blacklist.include?(prefix) end
might_allow_prefix_uncached?(prefix)
click to toggle source
# File lib/mmtrix/agent/attribute_filter.rb, line 178 def might_allow_prefix_uncached?(prefix) prefix = prefix.to_s @rules.any? do |rule| if rule.is_include if rule.wildcard if rule.attribute_name.size > prefix.size rule.attribute_name.start_with?(prefix) else prefix.start_with?(rule.attribute_name) end else rule.attribute_name.start_with?(prefix) end end end end