Skip to content

Commit

Permalink
Patch settings and logs for code level metrics (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimPansino authored Apr 27, 2022
1 parent 5890920 commit c7eb2c6
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions newrelic/api/time_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c7eb2c6

Please sign in to comment.