Skip to content

Commit c7eb2c6

Browse files
authored
Patch settings and logs for code level metrics (#525)
1 parent 5890920 commit c7eb2c6

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

newrelic/api/time_trace.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ def __enter__(self):
118118
self.activated = True
119119

120120
# Extract source code context
121-
settings = (
122-
self.settings or self.transaction.settings
123-
) # Some derived classes do not have self.settings immediately
124121
if self._source is not None:
125122
self.add_code_level_metrics(self._source)
126123

@@ -208,14 +205,16 @@ def add_custom_attribute(self, key, value):
208205

209206
def add_code_level_metrics(self, source):
210207
"""Extract source code context from a callable and add appropriate attributes."""
211-
if source and self.settings and self.settings.code_level_metrics and self.settings.code_level_metrics.enabled:
208+
# Some derived classes do not have self.settings immediately
209+
settings = self.settings or self.transaction.settings
210+
if source and settings and settings.code_level_metrics and settings.code_level_metrics.enabled:
212211
try:
213212
node = extract_code_from_callable(source)
214213
node.add_attrs(self._add_agent_attribute)
215-
except:
216-
_logger.error(
217-
"Failed to extract source code context from callable %s. Report this issue to newrelic support."
218-
% source
214+
except Exception as exc:
215+
_logger.debug(
216+
"Failed to extract source code context from callable %s. Report this issue to newrelic support. Exception: %s"
217+
% (source, exc)
219218
)
220219

221220
def _observe_exception(self, exc_info=None, ignore=None, expected=None, status_code=None):

0 commit comments

Comments
 (0)