Skip to content

Commit

Permalink
Replace instances of whitelist/blacklist to allowlist/denylist (#516)
Browse files Browse the repository at this point in the history
* Replace instances of whitelist/blacklist to allowlist/denylist

* Fix Flake8 errors

* [Mega-Linter] Apply linters fixes

* Add strip_exception_messages.whitelist to list of deprecated config settings

* [Mega-Linter] Apply linters fixes

* Change default value for strip_exception_messages.allowlist in translate_settings_test to none

* [Mega-Linter] Apply linters fixes

* Add non-default-values to translate_settings_tests

* [Mega-Linter] Apply linters fixes

* Put non-default-value into list in translate_settings_tests

Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
  • Loading branch information
lrafeei and lrafeei authored Apr 19, 2022
1 parent ad65494 commit e152949
Show file tree
Hide file tree
Showing 12 changed files with 937 additions and 916 deletions.
15 changes: 9 additions & 6 deletions newrelic/api/time_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import inspect
import logging
import random
import sys
Expand All @@ -23,11 +22,11 @@
from newrelic.api.settings import STRIP_EXCEPTION_MESSAGE
from newrelic.common.object_names import parse_exc_info
from newrelic.core.attribute import MAX_NUM_USER_ATTRIBUTES, process_user_attribute
from newrelic.core.config import is_expected_error, should_ignore_error
from newrelic.core.code_level_metrics import (
extract_code_from_callable,
extract_code_from_traceback,
)
from newrelic.core.config import is_expected_error, should_ignore_error
from newrelic.core.trace_cache import trace_cache

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -119,7 +118,9 @@ def __enter__(self):
self.activated = True

# Extract source code context
settings = self.settings or self.transaction.settings # Some derived classes do not have self.settings immediately
settings = (
self.settings or self.transaction.settings
) # Some derived classes do not have self.settings immediately
if self._source is not None:
self.add_code_level_metrics(self._source)

Expand Down Expand Up @@ -212,7 +213,10 @@ def add_code_level_metrics(self, source):
node = extract_code_from_callable(source)
node.add_attrs(self._add_agent_attribute)
except:
_logger.error("Failed to extract source code context from callable %s. Report this issue to newrelic support." % source)
_logger.error(
"Failed to extract source code context from callable %s. Report this issue to newrelic support."
% source
)

def _observe_exception(self, exc_info=None, ignore=None, expected=None, status_code=None):
# Bail out if the transaction is not active or
Expand Down Expand Up @@ -256,7 +260,7 @@ def _observe_exception(self, exc_info=None, ignore=None, expected=None, status_c

# Check to see if we need to strip the message before recording it.

if settings.strip_exception_messages.enabled and fullname not in settings.strip_exception_messages.whitelist:
if settings.strip_exception_messages.enabled and fullname not in settings.strip_exception_messages.allowlist:
message = STRIP_EXCEPTION_MESSAGE

# Where expected or ignore are a callable they should return a
Expand Down Expand Up @@ -384,7 +388,6 @@ def notice_error(self, error=None, attributes=None, expected=None, ignore=None,
)
custom_params = {}


if settings and settings.code_level_metrics and settings.code_level_metrics.enabled:
source = extract_code_from_traceback(tb)
else:
Expand Down
2 changes: 1 addition & 1 deletion newrelic/api/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ def _freeze_path(self):

self.ignore_transaction = self.ignore_transaction or ignore

# Apply segment whitelist rule to the segments on the full
# Apply segment allowlist rule to the segments on the full
# transaction name. The path is frozen at this point and cannot be
# further changed.

Expand Down
10 changes: 7 additions & 3 deletions newrelic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def _map_browser_monitoring_content_type(s):
return s.split()


def _map_strip_exception_messages_whitelist(s):
def _map_strip_exception_messages_allowlist(s):
return [expand_builtin_exception_name(item) for item in s.split()]


Expand Down Expand Up @@ -506,9 +506,9 @@ def _process_configuration(section):
_process_setting(section, "strip_exception_messages.enabled", "getboolean", None)
_process_setting(
section,
"strip_exception_messages.whitelist",
"strip_exception_messages.allowlist",
"get",
_map_strip_exception_messages_whitelist,
_map_strip_exception_messages_allowlist,
)
_process_setting(section, "datastore_tracer.instance_reporting.enabled", "getboolean", None)
_process_setting(section, "datastore_tracer.database_name_reporting.enabled", "getboolean", None)
Expand Down Expand Up @@ -711,6 +711,10 @@ def translate_deprecated_settings(settings, cached_settings):
"error_collector.ignore_errors",
"error_collector.ignore_classes",
),
(
"strip_exception_messages.whitelist",
"strip_exception_messages.allowlist",
),
]

for (old_key, new_key) in deprecated_settings_map:
Expand Down
2 changes: 1 addition & 1 deletion newrelic/core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def dump(self, file):
print("URL Normalization Rules: %r" % (self._rules_engine["url"].rules), file=file)
print("Metric Normalization Rules: %r" % (self._rules_engine["metric"].rules), file=file)
print("Transaction Normalization Rules: %r" % (self._rules_engine["transaction"].rules), file=file)
print("Transaction Segment Whitelist Rules: %r" % (self._rules_engine["segment"].rules), file=file)
print("Transaction Segment Allowlist Rules: %r" % (self._rules_engine["segment"].rules), file=file)
print("Harvest Period Start: %s" % (time.asctime(time.localtime(self._period_start))), file=file)
print("Transaction Count: %d" % (self._transaction_count), file=file)
print("Last Transaction: %s" % (time.asctime(time.localtime(self._last_transaction))), file=file)
Expand Down
4 changes: 2 additions & 2 deletions newrelic/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ def default_host(license_key):
_settings.utilization.billing_hostname = os.environ.get("NEW_RELIC_UTILIZATION_BILLING_HOSTNAME")

_settings.strip_exception_messages.enabled = False
_settings.strip_exception_messages.whitelist = []
_settings.strip_exception_messages.allowlist = []

_settings.datastore_tracer.instance_reporting.enabled = True
_settings.datastore_tracer.database_name_reporting.enabled = True
Expand Down Expand Up @@ -1037,7 +1037,7 @@ def apply_server_side_settings(server_side_config=None, settings=_settings):

event_harvest_config = server_side_config.get("event_harvest_config", {})
harvest_limits = event_harvest_config.get("harvest_limits", ())
apply_config_setting(settings_snapshot, "event_harvest_config.whitelist", frozenset(harvest_limits))
apply_config_setting(settings_snapshot, "event_harvest_config.allowlist", frozenset(harvest_limits))

# Override span event harvest config
span_event_harvest_config = server_side_config.get("span_event_harvest_config", {})
Expand Down
Loading

0 comments on commit e152949

Please sign in to comment.