From c7eb2c6c40143741843370c60fdc65a0e144980a Mon Sep 17 00:00:00 2001 From: Timothy Pansino <11214426+TimPansino@users.noreply.github.com> Date: Wed, 27 Apr 2022 16:11:53 -0700 Subject: [PATCH] Patch settings and logs for code level metrics (#525) --- newrelic/api/time_trace.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/newrelic/api/time_trace.py b/newrelic/api/time_trace.py index 2ad622140..cef7ae40a 100644 --- a/newrelic/api/time_trace.py +++ b/newrelic/api/time_trace.py @@ -118,9 +118,6 @@ def __enter__(self): self.activated = True # Extract source code context - settings = ( - self.settings or self.transaction.settings - ) # Some derived classes do not have self.settings immediately if self._source is not None: self.add_code_level_metrics(self._source) @@ -208,14 +205,16 @@ def add_custom_attribute(self, key, value): def add_code_level_metrics(self, source): """Extract source code context from a callable and add appropriate attributes.""" - if source and self.settings and self.settings.code_level_metrics and self.settings.code_level_metrics.enabled: + # Some derived classes do not have self.settings immediately + settings = self.settings or self.transaction.settings + if source and settings and settings.code_level_metrics and settings.code_level_metrics.enabled: try: node = extract_code_from_callable(source) node.add_attrs(self._add_agent_attribute) - except: - _logger.error( - "Failed to extract source code context from callable %s. Report this issue to newrelic support." - % source + except Exception as exc: + _logger.debug( + "Failed to extract source code context from callable %s. Report this issue to newrelic support. Exception: %s" + % (source, exc) ) def _observe_exception(self, exc_info=None, ignore=None, expected=None, status_code=None):