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