Skip to content

Commit b037599

Browse files
committed
fix: Use edx-django-utils API instead of calling newrelic directly
These changes will cause telemetry to start being reported when annotations are created. (No change for whether notesserver heartbeat calls emit telemetry, as that is currently only supported for New Relic anyhow.) This also removes the newrelic dependency, though it is still pulled in by edx-django-utils indirectly, for now.
1 parent 37f06bb commit b037599

4 files changed

Lines changed: 6 additions & 19 deletions

File tree

notesapi/v1/views/common.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
# pylint:disable=possibly-used-before-assignment
22
import json
33
import logging
4+
45
from django.conf import settings
56
from django.core.exceptions import ValidationError
67
from django.db.models import Q
78
from django.urls import reverse
89
from django.utils.translation import gettext as _
10+
from edx_django_utils.monitoring import set_custom_attribute
911
from rest_framework import status
1012
from rest_framework.generics import GenericAPIView, ListAPIView
1113
from rest_framework.response import Response
1214
from rest_framework.views import APIView
1315

14-
try:
15-
import newrelic.agent
16-
except ImportError: # pragma: no cover
17-
newrelic = None # pylint: disable=invalid-name
18-
1916
from notesapi.v1.models import Note
2017
from notesapi.v1.serializers import NoteSerializer
2118

@@ -402,9 +399,7 @@ def post(self, *args, **kwargs):
402399
note = Note.create(self.request.data)
403400
note.full_clean()
404401

405-
# Gather metrics for New Relic so we can slice data in New Relic Insights
406-
if newrelic: # pragma: no cover
407-
newrelic.agent.add_custom_parameter("notes.count", total_notes)
402+
set_custom_attribute("notes.count", total_notes)
408403
except ValidationError as error:
409404
log.debug(error, exc_info=True)
410405
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)