Skip to content

Commit 51c58ba

Browse files
authored
Merge pull request openedx#476 from timmc-edx/timmc/no-direct-nr
fix: Use edx-django-utils API instead of calling newrelic directly
2 parents bf21b0d + b037599 commit 51c58ba

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

notesapi/v1/views/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# pylint:disable=possibly-used-before-assignment
22
import json
33
import logging
4-
import newrelic.agent
4+
55
from django.conf import settings
66
from django.core.exceptions import ValidationError
77
from django.db.models import Q
88
from django.urls import reverse
99
from django.utils.translation import gettext as _
10+
from edx_django_utils.monitoring import set_custom_attribute
1011
from rest_framework import status
1112
from rest_framework.generics import GenericAPIView, ListAPIView
1213
from rest_framework.response import Response
@@ -398,8 +399,7 @@ def post(self, *args, **kwargs):
398399
note = Note.create(self.request.data)
399400
note.full_clean()
400401

401-
# Gather metrics for New Relic so we can slice data in New Relic Insights
402-
newrelic.agent.add_custom_parameter("notes.count", total_notes)
402+
set_custom_attribute("notes.count", total_notes)
403403
except ValidationError as error:
404404
log.debug(error, exc_info=True)
405405
return Response(status=status.HTTP_400_BAD_REQUEST)

notesserver/views.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44
from django.db import connection
55
from django.http import JsonResponse
66
from django.http import HttpResponse
7+
from edx_django_utils.monitoring import ignore_transaction
78
from rest_framework import status
89
from rest_framework.decorators import api_view, permission_classes
910
from rest_framework.permissions import AllowAny
1011
from rest_framework.response import Response
1112

12-
try:
13-
import newrelic.agent
14-
except ImportError: # pragma: no cover
15-
newrelic = None # pylint: disable=invalid-name
16-
1713
from notesapi.v1.views import get_annotation_search_view_class
1814
from notesapi.v1.views import SearchViewRuntimeError
1915

@@ -45,8 +41,7 @@ def heartbeat(request):
4541
"""
4642
ElasticSearch and database are reachable and ready to handle requests.
4743
"""
48-
if newrelic: # pragma: no cover
49-
newrelic.agent.ignore_transaction()
44+
ignore_transaction() # no need to record telemetry for heartbeats
5045
try:
5146
db_status()
5247
except Exception: # pylint: disable=broad-exception-caught

requirements/base.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ PyJWT
1616
gunicorn # MIT
1717
path.py
1818
python-dateutil
19-
newrelic
2019
edx-django-release-util
2120
edx-django-utils
2221
edx-drf-extensions

requirements/base.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ meilisearch==0.34.0
109109
mysqlclient==2.2.7
110110
# via -r requirements/base.in
111111
newrelic==10.7.0
112-
# via
113-
# -r requirements/base.in
114-
# edx-django-utils
112+
# via edx-django-utils
115113
packaging==24.2
116114
# via
117115
# django-nine

0 commit comments

Comments
 (0)