|
25 | 25 | import weakref
|
26 | 26 | from collections import OrderedDict
|
27 | 27 |
|
| 28 | +from newrelic.api.application import application_instance |
28 | 29 | import newrelic.core.database_node
|
29 | 30 | import newrelic.core.error_node
|
| 31 | +from newrelic.core.log_event_node import LogEventNode |
30 | 32 | import newrelic.core.root_node
|
31 | 33 | import newrelic.core.transaction_node
|
32 | 34 | import newrelic.packages.six as six
|
33 |
| -from newrelic.api.application import application_instance |
34 | 35 | from newrelic.api.time_trace import TimeTrace, get_linking_metadata
|
35 | 36 | from newrelic.common.encoding_utils import (
|
36 | 37 | DistributedTracePayload,
|
|
60 | 61 | DST_NONE,
|
61 | 62 | DST_TRANSACTION_TRACER,
|
62 | 63 | )
|
63 |
| -from newrelic.core.config import CUSTOM_EVENT_RESERVOIR_SIZE, LOG_EVENT_RESERVOIR_SIZE |
| 64 | +from newrelic.core.config import DEFAULT_RESERVOIR_SIZE, LOG_EVENT_RESERVOIR_SIZE |
64 | 65 | from newrelic.core.custom_event import create_custom_event
|
65 |
| -from newrelic.core.log_event_node import LogEventNode |
66 | 66 | from newrelic.core.stack_trace import exception_stack
|
67 | 67 | from newrelic.core.stats_engine import CustomMetrics, SampledDataSet
|
68 | 68 | from newrelic.core.thread_utilization import utilization_tracker
|
@@ -324,14 +324,10 @@ def __init__(self, application, enabled=None, source=None):
|
324 | 324 | self.enabled = True
|
325 | 325 |
|
326 | 326 | if self._settings:
|
327 |
| - self._custom_events = SampledDataSet( |
328 |
| - capacity=self._settings.event_harvest_config.harvest_limits.custom_event_data |
329 |
| - ) |
330 |
| - self._log_events = SampledDataSet( |
331 |
| - capacity=self._settings.event_harvest_config.harvest_limits.log_event_data |
332 |
| - ) |
| 327 | + self._custom_events = SampledDataSet(capacity=self._settings.event_harvest_config.harvest_limits.custom_event_data) |
| 328 | + self._log_events = SampledDataSet(capacity=self._settings.event_harvest_config.harvest_limits.log_event_data) |
333 | 329 | else:
|
334 |
| - self._custom_events = SampledDataSet(capacity=CUSTOM_EVENT_RESERVOIR_SIZE) |
| 330 | + self._custom_events = SampledDataSet(capacity=DEFAULT_RESERVOIR_SIZE) |
335 | 331 | self._log_events = SampledDataSet(capacity=LOG_EVENT_RESERVOIR_SIZE)
|
336 | 332 |
|
337 | 333 | def __del__(self):
|
@@ -1477,35 +1473,31 @@ def set_transaction_name(self, name, group=None, priority=None):
|
1477 | 1473 | self._group = group
|
1478 | 1474 | self._name = name
|
1479 | 1475 |
|
| 1476 | + |
1480 | 1477 | def record_log_event(self, message, level=None, timestamp=None, priority=None):
|
1481 | 1478 | settings = self.settings
|
1482 |
| - if not ( |
1483 |
| - settings |
1484 |
| - and settings.application_logging |
1485 |
| - and settings.application_logging.enabled |
1486 |
| - and settings.application_logging.forwarding |
1487 |
| - and settings.application_logging.forwarding.enabled |
1488 |
| - ): |
| 1479 | + if not (settings and settings.application_logging and settings.application_logging.enabled and settings.application_logging.forwarding and settings.application_logging.forwarding.enabled): |
1489 | 1480 | return
|
1490 |
| - |
| 1481 | + |
1491 | 1482 | timestamp = timestamp if timestamp is not None else time.time()
|
1492 | 1483 | level = str(level) if level is not None else "UNKNOWN"
|
1493 |
| - |
| 1484 | + |
1494 | 1485 | if not message or message.isspace():
|
1495 | 1486 | _logger.debug("record_log_event called where message was missing. No log event will be sent.")
|
1496 | 1487 | return
|
1497 |
| - |
| 1488 | + |
1498 | 1489 | message = truncate(message, MAX_LOG_MESSAGE_LENGTH)
|
1499 | 1490 |
|
1500 | 1491 | event = LogEventNode(
|
1501 | 1492 | timestamp=timestamp,
|
1502 | 1493 | level=level,
|
1503 | 1494 | message=message,
|
1504 |
| - attributes=get_linking_metadata(), |
| 1495 | + attributes=get_linking_metadata(), |
1505 | 1496 | )
|
1506 | 1497 |
|
1507 | 1498 | self._log_events.add(event, priority=priority)
|
1508 | 1499 |
|
| 1500 | + |
1509 | 1501 | def record_exception(self, exc=None, value=None, tb=None, params=None, ignore_errors=None):
|
1510 | 1502 | # Deprecation Warning
|
1511 | 1503 | warnings.warn(
|
@@ -1877,9 +1869,7 @@ def record_log_event(message, level=None, timestamp=None, application=None, prio
|
1877 | 1869 | "record_log_event has been called but no transaction or application was running. As a result, "
|
1878 | 1870 | "the following event has not been recorded. message: %r level: %r timestamp %r. To correct "
|
1879 | 1871 | "this problem, supply an application object as a parameter to this record_log_event call.",
|
1880 |
| - message, |
1881 |
| - level, |
1882 |
| - timestamp, |
| 1872 | + message, level, timestamp, |
1883 | 1873 | )
|
1884 | 1874 | elif application.enabled:
|
1885 | 1875 | application.record_log_event(message, level, timestamp, priority=priority)
|
|
0 commit comments