Skip to content
Snippets Groups Projects
Unverified Commit a69fce77 authored by Robert Raposa's avatar Robert Raposa Committed by GitHub
Browse files

Merge pull request #22956 from edx/robrap/BOM-897-add-trace-info

BOM-897: add newrelic metrics and trace details
parents 8dc53cc6 26d4cc65
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ Course API ...@@ -3,6 +3,7 @@ Course API
""" """
import logging import logging
from edx_django_utils.monitoring import function_trace
from edx_when.api import get_dates_for_course from edx_when.api import get_dates_for_course
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User from django.contrib.auth.models import AnonymousUser, User
...@@ -118,6 +119,7 @@ def _filter_by_search(course_queryset, search_term): ...@@ -118,6 +119,7 @@ def _filter_by_search(course_queryset, search_term):
) )
@function_trace('list_courses')
def list_courses(request, username, org=None, roles=None, filter_=None, search_term=None): def list_courses(request, username, org=None, roles=None, filter_=None, search_term=None):
""" """
Yield all available courses. Yield all available courses.
......
...@@ -4,6 +4,7 @@ Course API Views ...@@ -4,6 +4,7 @@ Course API Views
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from edx_django_utils.monitoring import set_custom_metric
from edx_rest_framework_extensions.paginators import NamespacedPageNumberPagination from edx_rest_framework_extensions.paginators import NamespacedPageNumberPagination
from rest_framework.generics import ListAPIView, RetrieveAPIView from rest_framework.generics import ListAPIView, RetrieveAPIView
from rest_framework.throttling import UserRateThrottle from rest_framework.throttling import UserRateThrottle
...@@ -245,6 +246,8 @@ class CourseListView(DeveloperErrorViewMixin, ListAPIView): ...@@ -245,6 +246,8 @@ class CourseListView(DeveloperErrorViewMixin, ListAPIView):
if not form.is_valid(): if not form.is_valid():
raise ValidationError(form.errors) raise ValidationError(form.errors)
set_custom_metric('query_param_roles', form.cleaned_data['role'])
return list_courses( return list_courses(
self.request, self.request,
form.cleaned_data['username'], form.cleaned_data['username'],
......
...@@ -16,8 +16,9 @@ import logging ...@@ -16,8 +16,9 @@ import logging
from datetime import datetime from datetime import datetime
import six import six
from django.conf import settings from django.conf import settings # pylint: disable=unused-import
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from edx_django_utils.monitoring import function_trace
from opaque_keys.edx.keys import CourseKey, UsageKey from opaque_keys.edx.keys import CourseKey, UsageKey
from pytz import UTC from pytz import UTC
from six import text_type from six import text_type
...@@ -100,6 +101,7 @@ def has_ccx_coach_role(user, course_key): ...@@ -100,6 +101,7 @@ def has_ccx_coach_role(user, course_key):
return False return False
@function_trace('has_access')
def has_access(user, action, obj, course_key=None): def has_access(user, action, obj, course_key=None):
""" """
Check whether a user has the access to do action on obj. Handles any magic Check whether a user has the access to do action on obj. Handles any magic
...@@ -211,6 +213,7 @@ def _can_view_courseware_with_prerequisites(user, course): ...@@ -211,6 +213,7 @@ def _can_view_courseware_with_prerequisites(user, course):
) )
@function_trace('_can_load_course_on_mobile')
def _can_load_course_on_mobile(user, course): def _can_load_course_on_mobile(user, course):
""" """
Checks if a user can view the given course on a mobile device. Checks if a user can view the given course on a mobile device.
...@@ -284,6 +287,7 @@ def _can_enroll_courselike(user, courselike): ...@@ -284,6 +287,7 @@ def _can_enroll_courselike(user, courselike):
return ACCESS_DENIED return ACCESS_DENIED
@function_trace('_has_access_course')
def _has_access_course(user, action, courselike): def _has_access_course(user, action, courselike):
""" """
Check if user has access to a course. Check if user has access to a course.
...@@ -305,6 +309,7 @@ def _has_access_course(user, action, courselike): ...@@ -305,6 +309,7 @@ def _has_access_course(user, action, courselike):
'see_in_catalog' -- user is able to see the course listed in the course catalog. 'see_in_catalog' -- user is able to see the course listed in the course catalog.
'see_about_page' -- user is able to see the course about page. 'see_about_page' -- user is able to see the course about page.
""" """
@function_trace('can_load')
def can_load(): def can_load():
""" """
Can this user load this course? Can this user load this course?
...@@ -358,12 +363,14 @@ def _has_access_course(user, action, courselike): ...@@ -358,12 +363,14 @@ def _has_access_course(user, action, courselike):
return ACCESS_GRANTED return ACCESS_GRANTED
@function_trace('can_enroll')
def can_enroll(): def can_enroll():
""" """
Returns whether the user can enroll in the course. Returns whether the user can enroll in the course.
""" """
return _can_enroll_courselike(user, courselike) return _can_enroll_courselike(user, courselike)
@function_trace('see_exists')
def see_exists(): def see_exists():
""" """
Can see if can enroll, but also if can load it: if user enrolled in a course and now Can see if can enroll, but also if can load it: if user enrolled in a course and now
...@@ -371,6 +378,7 @@ def _has_access_course(user, action, courselike): ...@@ -371,6 +378,7 @@ def _has_access_course(user, action, courselike):
""" """
return ACCESS_GRANTED if (can_load() or can_enroll()) else ACCESS_DENIED return ACCESS_GRANTED if (can_load() or can_enroll()) else ACCESS_DENIED
@function_trace('can_see_in_catalog')
def can_see_in_catalog(): def can_see_in_catalog():
""" """
Implements the "can see course in catalog" logic if a course should be visible in the main course catalog Implements the "can see course in catalog" logic if a course should be visible in the main course catalog
...@@ -382,6 +390,7 @@ def _has_access_course(user, action, courselike): ...@@ -382,6 +390,7 @@ def _has_access_course(user, action, courselike):
or _has_staff_access_to_descriptor(user, courselike, courselike.id) or _has_staff_access_to_descriptor(user, courselike, courselike.id)
) )
@function_trace('can_see_about_page')
def can_see_about_page(): def can_see_about_page():
""" """
Implements the "can see course about page" logic if a course about page should be visible Implements the "can see course about page" logic if a course about page should be visible
...@@ -771,6 +780,7 @@ def administrative_accesses_to_course_for_user(user, course_key): ...@@ -771,6 +780,7 @@ def administrative_accesses_to_course_for_user(user, course_key):
return global_staff, staff_access, instructor_access return global_staff, staff_access, instructor_access
@function_trace('_has_instructor_access_to_descriptor')
def _has_instructor_access_to_descriptor(user, descriptor, course_key): def _has_instructor_access_to_descriptor(user, descriptor, course_key):
"""Helper method that checks whether the user has staff access to """Helper method that checks whether the user has staff access to
the course of the location. the course of the location.
...@@ -780,6 +790,7 @@ def _has_instructor_access_to_descriptor(user, descriptor, course_key): ...@@ -780,6 +790,7 @@ def _has_instructor_access_to_descriptor(user, descriptor, course_key):
return _has_instructor_access_to_location(user, descriptor.location, course_key) return _has_instructor_access_to_location(user, descriptor.location, course_key)
@function_trace('_has_staff_access_to_descriptor')
def _has_staff_access_to_descriptor(user, descriptor, course_key): def _has_staff_access_to_descriptor(user, descriptor, course_key):
"""Helper method that checks whether the user has staff access to """Helper method that checks whether the user has staff access to
the course of the location. the course of the location.
......
...@@ -15,6 +15,7 @@ from django.conf import settings ...@@ -15,6 +15,7 @@ from django.conf import settings
from django.db.models import Prefetch from django.db.models import Prefetch
from django.http import Http404, QueryDict from django.http import Http404, QueryDict
from django.urls import reverse from django.urls import reverse
from edx_django_utils.monitoring import function_trace
from fs.errors import ResourceNotFound from fs.errors import ResourceNotFound
from opaque_keys.edx.keys import UsageKey from opaque_keys.edx.keys import UsageKey
from path import Path as path from path import Path as path
...@@ -457,6 +458,7 @@ def get_course_syllabus_section(course, section_key): ...@@ -457,6 +458,7 @@ def get_course_syllabus_section(course, section_key):
raise KeyError("Invalid about key " + str(section_key)) raise KeyError("Invalid about key " + str(section_key))
@function_trace('get_courses')
def get_courses(user, org=None, filter_=None): def get_courses(user, org=None, filter_=None):
""" """
Return a LazySequence of courses available, optionally filtered by org code (case-insensitive). Return a LazySequence of courses available, optionally filtered by org code (case-insensitive).
......
...@@ -13,7 +13,6 @@ from django.core.exceptions import ObjectDoesNotExist ...@@ -13,7 +13,6 @@ from django.core.exceptions import ObjectDoesNotExist
from django.core.validators import ValidationError, validate_email from django.core.validators import ValidationError, validate_email
from django.utils.translation import override as override_language from django.utils.translation import override as override_language
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from edx_django_utils.monitoring import set_custom_metric
from pytz import UTC from pytz import UTC
from six import text_type # pylint: disable=ungrouped-imports from six import text_type # pylint: disable=ungrouped-imports
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment