Addressing feedback about a potential issue around a timestamp for the

supportability metric.
This commit is contained in:
Josh Bonczkowski 2026-03-13 15:41:56 -04:00
parent 8aeaaa3808
commit ad00671fbb
2 changed files with 10 additions and 6 deletions

View file

@ -186,12 +186,13 @@ class NewRelicLogger(CustomLogger):
# Record metric with value of 1 (will be aggregated by New Relic)
app = newrelic.agent.application()
# Always update the timestamp so the 27-hour back-off applies
# regardless of whether the app is ready, preventing lock contention
# on every request when the agent is slow to register or never starts.
_last_metric_emission_time = time.time()
if app and app.enabled:
app.record_custom_metric(metric_name, 1)
# Update last emission time
_last_metric_emission_time = time.time()
verbose_logger.info(
f"Emitted New Relic supportability metric: {metric_name}"
)

View file

@ -607,12 +607,15 @@ class TestEmitSupportabilityMetric:
with patch("newrelic.agent.application", return_value=mock_app):
self.logger._emit_supportability_metric()
mock_app.record_custom_metric.assert_not_called()
assert nr_module._last_metric_emission_time == 0.0
# Timestamp is still updated to back off lock contention during registration.
assert nr_module._last_metric_emission_time != 0.0
def test_skips_when_no_app(self):
with patch("newrelic.agent.application", return_value=None):
self.logger._emit_supportability_metric()
assert nr_module._last_metric_emission_time == 0.0
# Timestamp is updated even when app is None to back off lock contention
# if the agent never starts or is slow to initialise.
assert nr_module._last_metric_emission_time != 0.0
# ---------------------------------------------------------------------------