Skip to content

Commit 4b415e4

Browse files
Swap setting deprecations (#1497)
* Deprecate analytics_events.max_samples_stored * Deprecate transaction_events.max_samples_stored * Deprecate span_events.max_samples_stored * Deprecate event_harvest_config.harvest_limits.error_event_data * Deprecate custom_insights_events.max_samples_stored * Deprecate application_logging.forwarding.max_samples_stored * Add settings to core/config * Megalinter fixes * Revert env var to previous value * Add variable for default value * Use preferred settings in agent * Megalinter fixes * Reviewer changes --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 15b6948 commit 4b415e4

File tree

14 files changed

+128
-66
lines changed

14 files changed

+128
-66
lines changed

newrelic/api/transaction.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,9 @@ def __init__(self, application, enabled=None, source=None):
333333
self.enabled = True
334334

335335
if self._settings:
336-
self._custom_events = SampledDataSet(
337-
capacity=self._settings.event_harvest_config.harvest_limits.custom_event_data
338-
)
336+
self._custom_events = SampledDataSet(capacity=self._settings.custom_insights_events.max_samples_stored)
339337
self._ml_events = SampledDataSet(capacity=self._settings.event_harvest_config.harvest_limits.ml_event_data)
340-
self._log_events = SampledDataSet(
341-
capacity=self._settings.event_harvest_config.harvest_limits.log_event_data
342-
)
338+
self._log_events = SampledDataSet(capacity=self._settings.application_logging.forwarding.max_samples_stored)
343339
else:
344340
self._custom_events = SampledDataSet(capacity=CUSTOM_EVENT_RESERVOIR_SIZE)
345341
self._log_events = SampledDataSet(capacity=LOG_EVENT_RESERVOIR_SIZE)

newrelic/config.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,19 @@ def translate_deprecated_settings(settings, cached_settings):
669669
cached = dict(cached_settings)
670670

671671
deprecated_settings_map = [
672-
("analytics_events.max_samples_stored", "event_harvest_config.harvest_limits.analytic_event_data"),
673-
("transaction_events.max_samples_stored", "event_harvest_config.harvest_limits.analytic_event_data"),
674-
("span_events.max_samples_stored", "event_harvest_config.harvest_limits.span_event_data"),
675-
("error_collector.max_event_samples_stored", "event_harvest_config.harvest_limits.error_event_data"),
676-
("custom_insights_events.max_samples_stored", "event_harvest_config.harvest_limits.custom_event_data"),
677-
("application_logging.forwarding.max_samples_stored", "event_harvest_config.harvest_limits.log_event_data"),
672+
("transaction_tracer.capture_attributes", "transaction_tracer.attributes.enabled"),
673+
("error_collector.capture_attributes", "error_collector.attributes.enabled"),
674+
("browser_monitoring.capture_attributes", "browser_monitoring.attributes.enabled"),
675+
("analytics_events.capture_attributes", "transaction_events.attributes.enabled"),
676+
("analytics_events.enabled", "transaction_events.enabled"),
677+
("analytics_events.max_samples_stored", "transaction_events.max_samples_stored"),
678+
("event_harvest_config.harvest_limits.analytic_event_data", "transaction_events.max_samples_stored"),
679+
("event_harvest_config.harvest_limits.span_event_data", "span_events.max_samples_stored"),
680+
("event_harvest_config.harvest_limits.error_event_data", "error_collector.max_event_samples_stored"),
681+
("event_harvest_config.harvest_limits.custom_event_data", "custom_insights_events.max_samples_stored"),
682+
("event_harvest_config.harvest_limits.log_event_data", "application_logging.forwarding.max_samples_stored"),
683+
("error_collector.ignore_errors", "error_collector.ignore_classes"),
684+
("strip_exception_messages.whitelist", "strip_exception_messages.allowlist"),
678685
]
679686

680687
for old_key, new_key in deprecated_settings_map:

newrelic/core/config.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,17 @@ def default_otlp_host(host):
818818
)
819819

820820
_settings.transaction_events.enabled = True
821+
_settings.transaction_events.max_samples_stored = _environ_as_int(
822+
"NEW_RELIC_ANALYTICS_EVENTS_MAX_SAMPLES_STORED", default=DEFAULT_RESERVOIR_SIZE
823+
)
821824
_settings.transaction_events.attributes.enabled = True
822825
_settings.transaction_events.attributes.exclude = []
823826
_settings.transaction_events.attributes.include = []
824827

825828
_settings.custom_insights_events.enabled = True
829+
_settings.custom_insights_events.max_samples_stored = _environ_as_int(
830+
"NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", default=CUSTOM_EVENT_RESERVOIR_SIZE
831+
)
826832
_settings.custom_insights_events.max_attribute_value = _environ_as_int(
827833
"NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_ATTRIBUTE_VALUE", default=MAX_ATTRIBUTE_LENGTH
828834
)
@@ -838,6 +844,9 @@ def default_otlp_host(host):
838844
)
839845
_settings.distributed_tracing.exclude_newrelic_header = False
840846
_settings.span_events.enabled = _environ_as_bool("NEW_RELIC_SPAN_EVENTS_ENABLED", default=True)
847+
_settings.span_events.max_samples_stored = _environ_as_int(
848+
"NEW_RELIC_SPAN_EVENTS_MAX_SAMPLES_STORED", default=SPAN_EVENT_RESERVOIR_SIZE
849+
)
841850
_settings.span_events.attributes.enabled = True
842851
_settings.span_events.attributes.exclude = []
843852
_settings.span_events.attributes.include = []
@@ -865,6 +874,9 @@ def default_otlp_host(host):
865874
_settings.error_collector.ignore_classes = []
866875
_settings.error_collector.ignore_status_codes = _parse_status_codes("100-102 200-208 226 300-308 404", set())
867876
_settings.error_collector.expected_classes = []
877+
_settings.error_collector.max_event_samples_stored = _environ_as_int(
878+
"NEW_RELIC_ERROR_COLLECTOR_MAX_EVENT_SAMPLES_STORED", default=ERROR_EVENT_RESERVOIR_SIZE
879+
)
868880
_settings.error_collector.expected_status_codes = set()
869881
_settings.error_collector._error_group_callback = None
870882
_settings.error_collector.attributes.enabled = True
@@ -1021,6 +1033,9 @@ def default_otlp_host(host):
10211033
_settings.application_logging.forwarding.custom_attributes = _environ_as_mapping(
10221034
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CUSTOM_ATTRIBUTES", default=""
10231035
)
1036+
_settings.application_logging.forwarding.max_samples_stored = _environ_as_int(
1037+
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_MAX_SAMPLES_STORED", default=LOG_EVENT_RESERVOIR_SIZE
1038+
)
10241039

10251040
_settings.application_logging.forwarding.labels.enabled = _environ_as_bool(
10261041
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_LABELS_ENABLED", default=False
@@ -1306,9 +1321,7 @@ def apply_server_side_settings(server_side_config=None, settings=_settings):
13061321
span_event_harvest_config = server_side_config.get("span_event_harvest_config", {})
13071322
span_event_harvest_limit = span_event_harvest_config.get("harvest_limit", None)
13081323
if span_event_harvest_limit is not None:
1309-
apply_config_setting(
1310-
settings_snapshot, "event_harvest_config.harvest_limits.span_event_data", span_event_harvest_limit
1311-
)
1324+
apply_config_setting(settings_snapshot, "span_events.max_samples_stored", span_event_harvest_limit)
13121325

13131326
# Check to see if collect_ai appears in the connect response to handle account-level AIM toggling
13141327
collect_ai = server_side_config.get("collect_ai", None)

newrelic/core/stats_engine.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,21 +1704,19 @@ def reset_transaction_events(self):
17041704
"""
17051705

17061706
if self.__settings is not None:
1707-
self._transaction_events = SampledDataSet(
1708-
self.__settings.event_harvest_config.harvest_limits.analytic_event_data
1709-
)
1707+
self._transaction_events = SampledDataSet(self.__settings.transaction_events.max_samples_stored)
17101708
else:
17111709
self._transaction_events = SampledDataSet()
17121710

17131711
def reset_error_events(self):
17141712
if self.__settings is not None:
1715-
self._error_events = SampledDataSet(self.__settings.event_harvest_config.harvest_limits.error_event_data)
1713+
self._error_events = SampledDataSet(self.__settings.error_collector.max_event_samples_stored)
17161714
else:
17171715
self._error_events = SampledDataSet()
17181716

17191717
def reset_custom_events(self):
17201718
if self.__settings is not None:
1721-
self._custom_events = SampledDataSet(self.__settings.event_harvest_config.harvest_limits.custom_event_data)
1719+
self._custom_events = SampledDataSet(self.__settings.custom_insights_events.max_samples_stored)
17221720
else:
17231721
self._custom_events = SampledDataSet()
17241722

@@ -1730,13 +1728,13 @@ def reset_ml_events(self):
17301728

17311729
def reset_span_events(self):
17321730
if self.__settings is not None:
1733-
self._span_events = SampledDataSet(self.__settings.event_harvest_config.harvest_limits.span_event_data)
1731+
self._span_events = SampledDataSet(self.__settings.span_events.max_samples_stored)
17341732
else:
17351733
self._span_events = SampledDataSet()
17361734

17371735
def reset_log_events(self):
17381736
if self.__settings is not None:
1739-
self._log_events = SampledDataSet(self.__settings.event_harvest_config.harvest_limits.log_event_data)
1737+
self._log_events = SampledDataSet(self.__settings.application_logging.forwarding.max_samples_stored)
17401738
else:
17411739
self._log_events = SampledDataSet()
17421740

tests/agent_features/test_configuration.py

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -406,52 +406,94 @@ def test_delete_setting_parent():
406406

407407
translate_settings_tests = [
408408
(
409-
TSetting("analytics_events.max_samples_stored", 1200, 1200),
410-
TSetting("event_harvest_config.harvest_limits.analytic_event_data", 9999, 1200),
409+
TSetting("strip_exception_messages.whitelist", [], []),
410+
TSetting("strip_exception_messages.allowlist", ["non-default-value"], []),
411411
),
412412
(
413-
TSetting("analytics_events.max_samples_stored", 9999, 1200),
414-
TSetting("event_harvest_config.harvest_limits.analytic_event_data", 1200, 1200),
413+
TSetting("strip_exception_messages.whitelist", ["non-default-value"], []),
414+
TSetting("strip_exception_messages.allowlist", [], []),
415415
),
416416
(
417-
TSetting("transaction_events.max_samples_stored", 1200, 1200),
418-
TSetting("event_harvest_config.harvest_limits.analytic_event_data", 9999, 1200),
417+
TSetting("transaction_tracer.capture_attributes", True, True),
418+
TSetting("transaction_tracer.attributes.enabled", False, True),
419+
),
420+
(
421+
TSetting("transaction_tracer.capture_attributes", False, True),
422+
TSetting("transaction_tracer.attributes.enabled", True, True),
423+
),
424+
(
425+
TSetting("error_collector.capture_attributes", True, True),
426+
TSetting("error_collector.attributes.enabled", False, True),
427+
),
428+
(
429+
TSetting("error_collector.capture_attributes", False, True),
430+
TSetting("error_collector.attributes.enabled", True, True),
431+
),
432+
(
433+
TSetting("browser_monitoring.capture_attributes", False, False),
434+
TSetting("browser_monitoring.attributes.enabled", True, False),
419435
),
420436
(
437+
TSetting("browser_monitoring.capture_attributes", True, False),
438+
TSetting("browser_monitoring.attributes.enabled", False, False),
439+
),
440+
(
441+
TSetting("analytics_events.capture_attributes", True, True),
442+
TSetting("transaction_events.attributes.enabled", False, True),
443+
),
444+
(
445+
TSetting("analytics_events.capture_attributes", False, True),
446+
TSetting("transaction_events.attributes.enabled", True, True),
447+
),
448+
(TSetting("analytics_events.enabled", True, True), TSetting("transaction_events.enabled", False, True)),
449+
(TSetting("analytics_events.enabled", False, True), TSetting("transaction_events.enabled", True, True)),
450+
(
451+
TSetting("analytics_events.max_samples_stored", 1200, 1200),
421452
TSetting("transaction_events.max_samples_stored", 9999, 1200),
453+
),
454+
(
455+
TSetting("analytics_events.max_samples_stored", 9999, 1200),
456+
TSetting("transaction_events.max_samples_stored", 1200, 1200),
457+
),
458+
(
422459
TSetting("event_harvest_config.harvest_limits.analytic_event_data", 1200, 1200),
460+
TSetting("transaction_events.max_samples_stored", 9999, 1200),
423461
),
424462
(
425-
TSetting("span_events.max_samples_stored", 1000, 2000),
426-
TSetting("event_harvest_config.harvest_limits.span_event_data", 9999, 2000),
463+
TSetting("event_harvest_config.harvest_limits.analytic_event_data", 9999, 1200),
464+
TSetting("transaction_events.max_samples_stored", 1200, 1200),
427465
),
428466
(
429-
TSetting("span_events.max_samples_stored", 9999, 2000),
430467
TSetting("event_harvest_config.harvest_limits.span_event_data", 1000, 2000),
468+
TSetting("span_events.max_samples_stored", 9999, 2000),
431469
),
432470
(
433-
TSetting("error_collector.max_event_samples_stored", 100, 100),
434-
TSetting("event_harvest_config.harvest_limits.error_event_data", 9999, 100),
471+
TSetting("event_harvest_config.harvest_limits.span_event_data", 9999, 2000),
472+
TSetting("span_events.max_samples_stored", 1000, 2000),
435473
),
436474
(
437-
TSetting("error_collector.max_event_samples_stored", 9999, 100),
438475
TSetting("event_harvest_config.harvest_limits.error_event_data", 100, 100),
476+
TSetting("error_collector.max_event_samples_stored", 9999, 100),
439477
),
440478
(
441-
TSetting("custom_insights_events.max_samples_stored", 3600, 3600),
442-
TSetting("event_harvest_config.harvest_limits.custom_event_data", 9999, 3600),
479+
TSetting("event_harvest_config.harvest_limits.error_event_data", 9999, 100),
480+
TSetting("error_collector.max_event_samples_stored", 100, 100),
443481
),
444482
(
445-
TSetting("custom_insights_events.max_samples_stored", 9999, 3600),
446483
TSetting("event_harvest_config.harvest_limits.custom_event_data", 3600, 3600),
484+
TSetting("custom_insights_events.max_samples_stored", 9999, 3600),
447485
),
448486
(
449-
TSetting("application_logging.forwarding.max_samples_stored", 10000, 10000),
450-
TSetting("event_harvest_config.harvest_limits.log_event_data", 99999, 10000),
487+
TSetting("event_harvest_config.harvest_limits.custom_event_data", 9999, 3600),
488+
TSetting("custom_insights_events.max_samples_stored", 3600, 3600),
451489
),
452490
(
453-
TSetting("application_logging.forwarding.max_samples_stored", 99999, 10000),
454491
TSetting("event_harvest_config.harvest_limits.log_event_data", 10000, 10000),
492+
TSetting("application_logging.forwarding.max_samples_stored", 99999, 10000),
493+
),
494+
(
495+
TSetting("event_harvest_config.harvest_limits.log_event_data", 99999, 10000),
496+
TSetting("application_logging.forwarding.max_samples_stored", 10000, 10000),
455497
),
456498
]
457499

tests/agent_features/test_notice_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def test_transaction_error_event_limit():
411411
@override_application_settings(
412412
{
413413
"agent_limits.errors_per_harvest": _errors_per_harvest_limit,
414-
"event_harvest_config.harvest_limits.error_event_data": _error_event_limit,
414+
"error_collector.max_event_samples_stored": _error_event_limit,
415415
}
416416
)
417417
@reset_core_stats_engine()

tests/agent_features/test_priority_sampling.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from newrelic.api.background_task import BackgroundTask
2525

2626

27-
@override_application_settings({"event_harvest_config.harvest_limits.analytic_event_data": 1})
27+
@override_application_settings({"transaction_events.max_samples_stored": 1})
2828
@pytest.mark.parametrize("first_transaction_saved", [True, False])
2929
def test_priority_used_in_transaction_events(first_transaction_saved):
3030
first_priority = 1 if first_transaction_saved else 0
@@ -57,7 +57,7 @@ def _test():
5757
_test()
5858

5959

60-
@override_application_settings({"event_harvest_config.harvest_limits.error_event_data": 1})
60+
@override_application_settings({"error_collector.max_event_samples_stored": 1})
6161
@pytest.mark.parametrize("first_transaction_saved", [True, False])
6262
def test_priority_used_in_transaction_error_events(first_transaction_saved):
6363
first_priority = 1 if first_transaction_saved else 0
@@ -97,7 +97,7 @@ def _test():
9797
_test()
9898

9999

100-
@override_application_settings({"event_harvest_config.harvest_limits.custom_event_data": 1})
100+
@override_application_settings({"custom_insights_events.max_samples_stored": 1})
101101
@pytest.mark.parametrize("first_transaction_saved", [True, False])
102102
def test_priority_used_in_transaction_custom_events(first_transaction_saved):
103103
first_priority = 1 if first_transaction_saved else 0

tests/agent_unittests/test_connect_response_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_span_event_harvest_config(connect_response_fields):
140140
from newrelic.core.config import SPAN_EVENT_RESERVOIR_SIZE
141141

142142
expected = SPAN_EVENT_RESERVOIR_SIZE
143-
assert protocol.configuration.event_harvest_config.harvest_limits.span_event_data == expected
143+
assert protocol.configuration.span_events.max_samples_stored == expected
144144

145145

146146
@override_generic_settings(global_settings(), {"developer_mode": True})

tests/agent_unittests/test_harvest_loop.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def test_application_harvest_with_spans(distributed_tracing_enabled, span_events
349349
"license_key": "**NOT A LICENSE KEY**",
350350
"distributed_tracing.enabled": distributed_tracing_enabled,
351351
"span_events.enabled": span_events_enabled,
352-
"event_harvest_config.harvest_limits.span_event_data": max_samples_stored,
352+
"span_events.max_samples_stored": max_samples_stored,
353353
},
354354
)
355355
def _test():
@@ -514,10 +514,10 @@ def test_adaptive_sampling(transaction_node, monkeypatch):
514514
"feature_flag": set(),
515515
"distributed_tracing.enabled": True,
516516
"application_logging.forwarding.enabled": True,
517-
"event_harvest_config.harvest_limits.error_event_data": 1000,
518-
"event_harvest_config.harvest_limits.span_event_data": 1000,
519-
"event_harvest_config.harvest_limits.custom_event_data": 1000,
520-
"event_harvest_config.harvest_limits.log_event_data": 1000,
517+
"error_collector.max_event_samples_stored": 1000,
518+
"span_events.max_samples_stored": 1000,
519+
"custom_insights_events.max_samples_stored": 1000,
520+
"application_logging.forwarding.max_samples_stored": 1000,
521521
},
522522
)
523523
def test_reservoir_sizes(transaction_node):
@@ -537,13 +537,13 @@ def test_reservoir_sizes(transaction_node):
537537

538538

539539
@pytest.mark.parametrize(
540-
"harvest_name, event_name",
540+
"harvest_setting,event_name",
541541
[
542-
("analytic_event_data", "transaction_events"),
543-
("error_event_data", "error_events"),
544-
("custom_event_data", "custom_events"),
545-
("log_event_data", "log_events"),
546-
("span_event_data", "span_events"),
542+
("transaction_events.max_samples_stored", "transaction_events"),
543+
("error_collector.max_event_samples_stored", "error_events"),
544+
("custom_insights_events.max_samples_stored", "custom_events"),
545+
("application_logging.forwarding.max_samples_stored", "log_events"),
546+
("span_events.max_samples_stored", "span_events"),
547547
],
548548
)
549549
@override_generic_settings(
@@ -555,11 +555,18 @@ def test_reservoir_sizes(transaction_node):
555555
"distributed_tracing.enabled": True,
556556
},
557557
)
558-
def test_reservoir_size_zeros(harvest_name, event_name):
558+
def test_reservoir_size_zeros(harvest_setting, event_name):
559559
app = Application("Python Agent Test (Harvest Loop)")
560560
app.connect_to_data_collector(None)
561561

562-
setattr(settings.event_harvest_config.harvest_limits, harvest_name, 0)
562+
# Walk down the settings tree until the 2nd to last setting name is reached to get the
563+
# settings container, then set the final setting on that container to 0
564+
harvest_setting = list(harvest_setting.split("."))
565+
_settings = settings
566+
for setting_attr in harvest_setting[:-1]:
567+
_settings = getattr(_settings, setting_attr)
568+
setattr(_settings, harvest_setting[-1], 0)
569+
563570
settings.event_harvest_config.allowlist = frozenset(())
564571
app._stats_engine.reset_stats(settings)
565572

@@ -607,7 +614,7 @@ def test_error_event_sampling_info(events_seen):
607614
{
608615
"developer_mode": True,
609616
"license_key": "**NOT A LICENSE KEY**",
610-
"event_harvest_config.harvest_limits.error_event_data": reservoir_size,
617+
"error_collector.max_event_samples_stored": reservoir_size,
611618
},
612619
)
613620
def _test():
@@ -676,7 +683,7 @@ def transactions_validator(payload):
676683
settings,
677684
{
678685
"developer_mode": True,
679-
"event_harvest_config.harvest_limits.analytic_event_data": transactions_limit,
686+
"transaction_events.max_samples_stored": transactions_limit,
680687
"agent_limits.synthetics_events": synthetics_limit,
681688
},
682689
)

tests/logger_logging/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"application_logging.forwarding.context_data.enabled": True,
3232
"application_logging.metrics.enabled": True,
3333
"application_logging.local_decorating.enabled": True,
34-
"event_harvest_config.harvest_limits.log_event_data": 100000,
34+
"application_logging.forwarding.max_samples_stored": 100000,
3535
}
3636

3737
collector_agent_registration = collector_agent_registration_fixture(

0 commit comments

Comments
 (0)