diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index c963e73920..f486989b4b 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -25,12 +25,13 @@ import weakref from collections import OrderedDict +from newrelic.api.application import application_instance import newrelic.core.database_node import newrelic.core.error_node +from newrelic.core.log_event_node import LogEventNode import newrelic.core.root_node import newrelic.core.transaction_node import newrelic.packages.six as six -from newrelic.api.application import application_instance from newrelic.api.time_trace import TimeTrace, get_linking_metadata from newrelic.common.encoding_utils import ( DistributedTracePayload, @@ -60,9 +61,8 @@ DST_NONE, DST_TRANSACTION_TRACER, ) -from newrelic.core.config import CUSTOM_EVENT_RESERVOIR_SIZE, LOG_EVENT_RESERVOIR_SIZE +from newrelic.core.config import DEFAULT_RESERVOIR_SIZE, LOG_EVENT_RESERVOIR_SIZE from newrelic.core.custom_event import create_custom_event -from newrelic.core.log_event_node import LogEventNode from newrelic.core.stack_trace import exception_stack from newrelic.core.stats_engine import CustomMetrics, SampledDataSet from newrelic.core.thread_utilization import utilization_tracker @@ -324,14 +324,10 @@ def __init__(self, application, enabled=None, source=None): self.enabled = True if self._settings: - self._custom_events = SampledDataSet( - capacity=self._settings.event_harvest_config.harvest_limits.custom_event_data - ) - self._log_events = SampledDataSet( - capacity=self._settings.event_harvest_config.harvest_limits.log_event_data - ) + self._custom_events = SampledDataSet(capacity=self._settings.event_harvest_config.harvest_limits.custom_event_data) + self._log_events = SampledDataSet(capacity=self._settings.event_harvest_config.harvest_limits.log_event_data) else: - self._custom_events = SampledDataSet(capacity=CUSTOM_EVENT_RESERVOIR_SIZE) + self._custom_events = SampledDataSet(capacity=DEFAULT_RESERVOIR_SIZE) self._log_events = SampledDataSet(capacity=LOG_EVENT_RESERVOIR_SIZE) def __del__(self): @@ -1477,35 +1473,31 @@ def set_transaction_name(self, name, group=None, priority=None): self._group = group self._name = name + def record_log_event(self, message, level=None, timestamp=None, priority=None): settings = self.settings - if not ( - settings - and settings.application_logging - and settings.application_logging.enabled - and settings.application_logging.forwarding - and settings.application_logging.forwarding.enabled - ): + if not (settings and settings.application_logging and settings.application_logging.enabled and settings.application_logging.forwarding and settings.application_logging.forwarding.enabled): return - + timestamp = timestamp if timestamp is not None else time.time() level = str(level) if level is not None else "UNKNOWN" - + if not message or message.isspace(): _logger.debug("record_log_event called where message was missing. No log event will be sent.") return - + message = truncate(message, MAX_LOG_MESSAGE_LENGTH) event = LogEventNode( timestamp=timestamp, level=level, message=message, - attributes=get_linking_metadata(), + attributes=get_linking_metadata(), ) self._log_events.add(event, priority=priority) + def record_exception(self, exc=None, value=None, tb=None, params=None, ignore_errors=None): # Deprecation Warning warnings.warn( @@ -1877,9 +1869,7 @@ def record_log_event(message, level=None, timestamp=None, application=None, prio "record_log_event has been called but no transaction or application was running. As a result, " "the following event has not been recorded. message: %r level: %r timestamp %r. To correct " "this problem, supply an application object as a parameter to this record_log_event call.", - message, - level, - timestamp, + message, level, timestamp, ) elif application.enabled: application.record_log_event(message, level, timestamp, priority=priority) diff --git a/newrelic/core/config.py b/newrelic/core/config.py index 2e4db97c70..60520c1134 100644 --- a/newrelic/core/config.py +++ b/newrelic/core/config.py @@ -52,7 +52,6 @@ # reservoir. Error Events have a different default size. DEFAULT_RESERVOIR_SIZE = 1200 -CUSTOM_EVENT_RESERVOIR_SIZE = 30000 ERROR_EVENT_RESERVOIR_SIZE = 100 SPAN_EVENT_RESERVOIR_SIZE = 2000 LOG_EVENT_RESERVOIR_SIZE = 10000 @@ -739,7 +738,7 @@ def default_host(license_key): ) _settings.event_harvest_config.harvest_limits.custom_event_data = _environ_as_int( - "NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", CUSTOM_EVENT_RESERVOIR_SIZE + "NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", DEFAULT_RESERVOIR_SIZE ) _settings.event_harvest_config.harvest_limits.span_event_data = _environ_as_int( diff --git a/tests/agent_features/test_configuration.py b/tests/agent_features/test_configuration.py index 0b5203ad85..5846e38080 100644 --- a/tests/agent_features/test_configuration.py +++ b/tests/agent_features/test_configuration.py @@ -438,12 +438,12 @@ def test_delete_setting_parent(): TSetting("event_harvest_config.harvest_limits.error_event_data", 100, 100), ), ( - TSetting("custom_insights_events.max_samples_stored", 30000, 30000), - TSetting("event_harvest_config.harvest_limits.custom_event_data", 9999, 30000), + TSetting("custom_insights_events.max_samples_stored", 1200, 1200), + TSetting("event_harvest_config.harvest_limits.custom_event_data", 9999, 1200), ), ( - TSetting("custom_insights_events.max_samples_stored", 9999, 30000), - TSetting("event_harvest_config.harvest_limits.custom_event_data", 30000, 30000), + TSetting("custom_insights_events.max_samples_stored", 9999, 1200), + TSetting("event_harvest_config.harvest_limits.custom_event_data", 1200, 1200), ), ( TSetting("application_logging.forwarding.max_samples_stored", 10000, 10000),