Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

fix: Replace newrelic ignore_transaction with edx_django_utils monitoring #4174

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ecommerce/core/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def test_all_services_available(self):
"""Test that the endpoint reports when all services are healthy."""
self._assert_health(status.HTTP_200_OK, Status.OK, Status.OK)

@mock.patch('newrelic.agent')
def test_health_check_is_ignored_by_new_relic(self, mock_newrelic_agent):
"""Test that the health endpoint is ignored by NewRelic"""
@mock.patch('ecommerce.core.views.ignore_transaction')
def test_health_check_is_ignored(self, mock_ignore_transaction):
"""Test that the health endpoint is ignored in performance monitoring"""
self._assert_health(status.HTTP_200_OK, Status.OK, Status.OK)
self.assertTrue(mock_newrelic_agent.ignore_transaction.called)
self.assertTrue(mock_ignore_transaction.called)

@mock.patch('django.contrib.sites.middleware.get_current_site', mock.Mock(return_value=None))
@mock.patch('django.db.backends.base.base.BaseDatabaseWrapper.cursor', mock.Mock(side_effect=DatabaseError))
Expand Down
10 changes: 3 additions & 7 deletions ecommerce/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
from django.shortcuts import redirect
from django.utils.decorators import method_decorator
from django.views.generic import View
from edx_django_utils.monitoring import ignore_transaction

from ecommerce.core.constants import Status

try:
import newrelic.agent
except ImportError: # pragma: no cover
newrelic = None # pylint: disable=invalid-name

logger = logging.getLogger(__name__)
User = get_user_model()

Expand All @@ -44,8 +40,8 @@ def health(_):
>>> response.content
'{"overall_status": "OK", "detailed_status": {"database_status": "OK"}}'
"""
if newrelic: # pragma: no cover
newrelic.agent.ignore_transaction()
# Ignores health check in performance monitoring so as to not artifically inflate our response time metrics
ignore_transaction()

overall_status = database_status = Status.UNAVAILABLE

Expand Down
Loading