Skip to content
59 changes: 1 addition & 58 deletions newrelic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
agent_control_health_instance,
agent_control_healthcheck_loop,
)
from newrelic.core.config import Settings, apply_config_setting, default_host, fetch_config_setting
from newrelic.core.config import Settings, apply_config_setting, default_host

__all__ = ["filter_app_factory", "initialize"]

Expand Down Expand Up @@ -331,7 +331,6 @@ def _process_configuration(section):
_process_setting(section, "port", "getint", None)
_process_setting(section, "otlp_host", "get", None)
_process_setting(section, "otlp_port", "getint", None)
_process_setting(section, "ssl", "getboolean", None)
_process_setting(section, "proxy_scheme", "get", None)
_process_setting(section, "proxy_host", "get", None)
_process_setting(section, "proxy_port", "getint", None)
Expand All @@ -343,7 +342,6 @@ def _process_configuration(section):
_process_setting(section, "developer_mode", "getboolean", None)
_process_setting(section, "high_security", "getboolean", None)
_process_setting(section, "capture_params", "getboolean", None)
_process_setting(section, "ignored_params", "get", _map_split_strings)
_process_setting(section, "capture_environ", "getboolean", None)
_process_setting(section, "include_environ", "get", _map_split_strings)
_process_setting(section, "max_stack_trace_lines", "getint", None)
Expand Down Expand Up @@ -374,7 +372,6 @@ def _process_configuration(section):
_process_setting(section, "error_collector.capture_events", "getboolean", None)
_process_setting(section, "error_collector.max_event_samples_stored", "getint", None)
_process_setting(section, "error_collector.capture_source", "getboolean", None)
_process_setting(section, "error_collector.ignore_errors", "get", _map_split_strings)
_process_setting(section, "error_collector.ignore_classes", "get", _map_split_strings)
_process_setting(section, "error_collector.ignore_status_codes", "get", _merge_ignore_status_codes)
_process_setting(section, "error_collector.expected_classes", "get", _map_split_strings)
Expand Down Expand Up @@ -421,7 +418,6 @@ def _process_configuration(section):
_process_setting(section, "agent_limits.sql_explain_plans", "getint", None)
_process_setting(section, "agent_limits.sql_explain_plans_per_harvest", "getint", None)
_process_setting(section, "agent_limits.slow_sql_data", "getint", None)
_process_setting(section, "agent_limits.merge_stats_maximum", "getint", None)
_process_setting(section, "agent_limits.errors_per_transaction", "getint", None)
_process_setting(section, "agent_limits.errors_per_harvest", "getint", None)
_process_setting(section, "agent_limits.slow_transaction_dry_harvests", "getint", None)
Expand Down Expand Up @@ -668,19 +664,12 @@ def translate_deprecated_settings(settings, cached_settings):
cached = dict(cached_settings)

deprecated_settings_map = [
("transaction_tracer.capture_attributes", "transaction_tracer.attributes.enabled"),
("error_collector.capture_attributes", "error_collector.attributes.enabled"),
("browser_monitoring.capture_attributes", "browser_monitoring.attributes.enabled"),
("analytics_events.capture_attributes", "transaction_events.attributes.enabled"),
("analytics_events.enabled", "transaction_events.enabled"),
("analytics_events.max_samples_stored", "event_harvest_config.harvest_limits.analytic_event_data"),
("transaction_events.max_samples_stored", "event_harvest_config.harvest_limits.analytic_event_data"),
("span_events.max_samples_stored", "event_harvest_config.harvest_limits.span_event_data"),
("error_collector.max_event_samples_stored", "event_harvest_config.harvest_limits.error_event_data"),
("custom_insights_events.max_samples_stored", "event_harvest_config.harvest_limits.custom_event_data"),
("application_logging.forwarding.max_samples_stored", "event_harvest_config.harvest_limits.log_event_data"),
("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 All @@ -695,41 +684,6 @@ def translate_deprecated_settings(settings, cached_settings):

delete_setting(settings, old_key)

# The 'ignored_params' setting is more complicated than the above
# deprecated settings, so it gets handled separately.

if "ignored_params" in cached:
_logger.info(
"Deprecated setting found: ignored_params. Please use "
"new setting: attributes.exclude. For the new setting, an "
"ignored parameter should be prefaced with "
'"request.parameters.". For example, ignoring a parameter '
'named "foo" should be added added to attributes.exclude as '
'"request.parameters.foo."'
)

# Don't merge 'ignored_params' settings. If user set
# 'attributes.exclude' setting, only use those values,
# and ignore 'ignored_params' settings.

if "attributes.exclude" in cached:
_logger.info("Ignoring deprecated setting: ignored_params. Using new setting: attributes.exclude.")

else:
ignored_params = fetch_config_setting(settings, "ignored_params")

for p in ignored_params:
attr_value = f"request.parameters.{p}"
excluded_attrs = fetch_config_setting(settings, "attributes.exclude")

if attr_value not in excluded_attrs:
settings.attributes.exclude.append(attr_value)
_logger.info(
"Applying value of deprecated setting ignored_params to attributes.exclude: %r.", attr_value
)

delete_setting(settings, "ignored_params")

# The 'capture_params' setting is deprecated, but since it affects
# attribute filter default destinations, it is not translated here. We
# log a message, but keep the capture_params setting.
Expand All @@ -754,17 +708,6 @@ def translate_deprecated_settings(settings, cached_settings):
"https://docs.newrelic.com/docs/distributed-tracing/concepts/distributed-tracing-planning-guide/#changes."
)

if not settings.ssl:
settings.ssl = True
_logger.info("Ignoring deprecated setting: ssl. Enabling ssl is now mandatory. Setting ssl=true.")

if settings.agent_limits.merge_stats_maximum is not None:
_logger.info(
"Ignoring deprecated setting: "
"agent_limits.merge_stats_maximum. The agent will now respect "
"server-side commands."
)

return settings


Expand Down
11 changes: 0 additions & 11 deletions newrelic/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,6 @@ def default_otlp_host(host):
_settings.license_key = os.environ.get("NEW_RELIC_LICENSE_KEY", None)
_settings.api_key = os.environ.get("NEW_RELIC_API_KEY", None)

_settings.ssl = _environ_as_bool("NEW_RELIC_SSL", True)

_settings.host = os.environ.get("NEW_RELIC_HOST")
_settings.otlp_host = os.environ.get("NEW_RELIC_OTLP_HOST")
_settings.port = int(os.environ.get("NEW_RELIC_PORT", "0"))
Expand Down Expand Up @@ -756,7 +754,6 @@ def default_otlp_host(host):
_settings.web_transactions_apdex = {}

_settings.capture_params = None
_settings.ignored_params = []

_settings.capture_environ = True
_settings.include_environ = [
Expand Down Expand Up @@ -889,7 +886,6 @@ def default_otlp_host(host):
_settings.agent_limits.sql_explain_plans = 30
_settings.agent_limits.sql_explain_plans_per_harvest = 60
_settings.agent_limits.slow_sql_data = 10
_settings.agent_limits.merge_stats_maximum = None
_settings.agent_limits.errors_per_transaction = 5
_settings.agent_limits.errors_per_harvest = 20
_settings.agent_limits.slow_transaction_dry_harvests = 5
Expand Down Expand Up @@ -1279,13 +1275,6 @@ def apply_server_side_settings(server_side_config=None, settings=_settings):
if value == "apdex_f":
agent_config["transaction_tracer.transaction_threshold"] = None

# If ignore_errors exists, and either ignore_classes is not set or it is empty
if "error_collector.ignore_errors" in agent_config and (
"error_collector.ignore_classes" not in agent_config or not agent_config["error_collector.ignore_classes"]
):
# Remap to newer config key
agent_config["error_collector.ignore_classes"] = agent_config.pop("error_collector.ignore_errors")

# Overlay with agent server side configuration settings.

for name, value in agent_config.items():
Expand Down
120 changes: 18 additions & 102 deletions tests/agent_features/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,21 +363,27 @@ def test_strip_proxy_details(settings):
assert proxy_host == expected_proxy_host


def test_delete_setting():
d = {"transaction_tracer.capture_attributes": True}
settings = apply_server_side_settings(d)
assert "capture_attributes" in settings.transaction_tracer
# TODO: Reenable once newly deprecated settings have been
# been put into the `deprecated_settings_map`
# def test_delete_setting():
# """This test applies to a deprecated setting
# """
# d = {"transaction_tracer.explain_enabled": True}
# settings = apply_server_side_settings(d)
# assert "explain_enabled" in settings.transaction_tracer

delete_setting(settings, "transaction_tracer.capture_attributes")
assert "capture_attributes" not in settings.transaction_tracer
# delete_setting(settings, "transaction_tracer.explain_enabled")
# assert "explain_enabled" not in settings.transaction_tracer


def test_delete_setting_absent():
settings = apply_server_side_settings()
assert "capture_attributes" not in settings.transaction_tracer
# def test_delete_setting_absent():
# """This test applies to a deprecated setting
# """
# settings = apply_server_side_settings()
# assert "explain_enabled" not in settings.transaction_tracer

delete_setting(settings, "transaction_tracer.capture_attributes")
assert "capture_attributes" not in settings.transaction_tracer
# delete_setting(settings, "transaction_tracer.explain_enabled")
# assert "explain_enabled" not in settings.transaction_tracer


def test_delete_setting_parent():
Expand All @@ -399,48 +405,6 @@ def test_delete_setting_parent():
TSetting = collections.namedtuple("TSetting", ["name", "value", "default"])

translate_settings_tests = [
(
TSetting("strip_exception_messages.whitelist", [], []),
TSetting("strip_exception_messages.allowlist", ["non-default-value"], []),
),
(
TSetting("strip_exception_messages.whitelist", ["non-default-value"], []),
TSetting("strip_exception_messages.allowlist", [], []),
),
(
TSetting("transaction_tracer.capture_attributes", True, True),
TSetting("transaction_tracer.attributes.enabled", False, True),
),
(
TSetting("transaction_tracer.capture_attributes", False, True),
TSetting("transaction_tracer.attributes.enabled", True, True),
),
(
TSetting("error_collector.capture_attributes", True, True),
TSetting("error_collector.attributes.enabled", False, True),
),
(
TSetting("error_collector.capture_attributes", False, True),
TSetting("error_collector.attributes.enabled", True, True),
),
(
TSetting("browser_monitoring.capture_attributes", False, False),
TSetting("browser_monitoring.attributes.enabled", True, False),
),
(
TSetting("browser_monitoring.capture_attributes", True, False),
TSetting("browser_monitoring.attributes.enabled", False, False),
),
(
TSetting("analytics_events.capture_attributes", True, True),
TSetting("transaction_events.attributes.enabled", False, True),
),
(
TSetting("analytics_events.capture_attributes", False, True),
TSetting("transaction_events.attributes.enabled", True, True),
),
(TSetting("analytics_events.enabled", True, True), TSetting("transaction_events.enabled", False, True)),
(TSetting("analytics_events.enabled", False, True), TSetting("transaction_events.enabled", True, True)),
(
TSetting("analytics_events.max_samples_stored", 1200, 1200),
TSetting("event_harvest_config.harvest_limits.analytic_event_data", 9999, 1200),
Expand Down Expand Up @@ -489,14 +453,6 @@ def test_delete_setting_parent():
TSetting("application_logging.forwarding.max_samples_stored", 99999, 10000),
TSetting("event_harvest_config.harvest_limits.log_event_data", 10000, 10000),
),
(
TSetting("error_collector.ignore_errors", [], []),
TSetting("error_collector.ignore_classes", callable_name(ValueError), []),
),
(
TSetting("error_collector.ignore_errors", callable_name(ValueError), []),
TSetting("error_collector.ignore_classes", [], []),
),
]


Expand Down Expand Up @@ -567,46 +523,6 @@ def test_translate_deprecated_setting_without_old_setting(old, new):
assert fetch_config_setting(result, new.name) == new.value


def test_translate_deprecated_ignored_params_without_new_setting():
ignored_params = ["foo", "bar"]
settings = apply_server_side_settings()
apply_config_setting(settings, "ignored_params", ignored_params)

assert "foo" in settings.ignored_params
assert "bar" in settings.ignored_params
assert len(settings.attributes.exclude) == 0

cached = [("ignored_params", ignored_params)]
result = translate_deprecated_settings(settings, cached)

assert result is settings
assert "request.parameters.foo" in result.attributes.exclude
assert "request.parameters.bar" in result.attributes.exclude
assert "ignored_params" not in result


def test_translate_deprecated_ignored_params_with_new_setting():
ignored_params = ["foo", "bar"]
attr_exclude = ["request.parameters.foo"]
settings = apply_server_side_settings()
apply_config_setting(settings, "ignored_params", ignored_params)
apply_config_setting(settings, "attributes.exclude", attr_exclude)

assert "foo" in settings.ignored_params
assert "bar" in settings.ignored_params
assert "request.parameters.foo" in settings.attributes.exclude

cached = [("ignored_params", ignored_params), ("attributes.exclude", attr_exclude)]
result = translate_deprecated_settings(settings, cached)

# ignored_params are not merged!

assert result is settings
assert "request.parameters.foo" in result.attributes.exclude
assert "request.parameters.bar" not in result.attributes.exclude
assert "ignored_params" not in result


@pytest.mark.parametrize(
"name,expected_value",
(
Expand Down Expand Up @@ -1002,7 +918,7 @@ def test_map_aws_account_id(account_id, expected_account_id, logger):

[tool.newrelic.error_collector]
enabled = true
ignore_errors = ["module:name1", "module:name"]
ignore_classes = ["module:name1", "module:name"]

[tool.newrelic.transaction_tracer]
enabled = true
Expand Down
16 changes: 0 additions & 16 deletions tests/agent_unittests/test_harvest_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,22 +858,6 @@ def test_default_events_harvested(allowlist_event):
assert app._stats_engine.metrics_count() == 4


@failing_endpoint("analytic_event_data")
@override_generic_settings(settings, {"developer_mode": True, "agent_limits.merge_stats_maximum": 0})
def test_infinite_merges():
app = Application("Python Agent Test (Harvest Loop)")
app.connect_to_data_collector(None)

app._stats_engine.transaction_events.add("transaction event")

assert app._stats_engine.transaction_events.num_seen == 1

app.harvest()

# the agent_limits.merge_stats_maximum is not respected
assert app._stats_engine.transaction_events.num_seen == 1


@failing_endpoint("analytic_event_data")
@override_generic_settings(settings, {"developer_mode": True})
def test_flexible_harvest_rollback():
Expand Down