diff --git a/lms/djangoapps/course_api/api.py b/lms/djangoapps/course_api/api.py index 76c42406907f5568c64b27ec1eceda840cedc0f1..37406e2033eaf9b1b4a376b3212164cbfc3acaad 100644 --- a/lms/djangoapps/course_api/api.py +++ b/lms/djangoapps/course_api/api.py @@ -3,6 +3,7 @@ Course API """ import logging +from edx_django_utils.monitoring import function_trace from edx_when.api import get_dates_for_course from django.conf import settings from django.contrib.auth.models import AnonymousUser, User @@ -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): """ Yield all available courses. diff --git a/lms/djangoapps/course_api/views.py b/lms/djangoapps/course_api/views.py index 0cb44022d453df7131d4716bc91b7a8f0a11c9e9..762727dd02986b6244eb328236ea28a357512864 100644 --- a/lms/djangoapps/course_api/views.py +++ b/lms/djangoapps/course_api/views.py @@ -4,6 +4,7 @@ Course API Views from django.core.exceptions import ValidationError +from edx_django_utils.monitoring import set_custom_metric from edx_rest_framework_extensions.paginators import NamespacedPageNumberPagination from rest_framework.generics import ListAPIView, RetrieveAPIView from rest_framework.throttling import UserRateThrottle @@ -245,6 +246,8 @@ class CourseListView(DeveloperErrorViewMixin, ListAPIView): if not form.is_valid(): raise ValidationError(form.errors) + set_custom_metric('query_param_roles', form.cleaned_data['role']) + return list_courses( self.request, form.cleaned_data['username'], diff --git a/lms/djangoapps/courseware/access.py b/lms/djangoapps/courseware/access.py index abd4285f8bd97523cff52e8fed5543bbcd84ecf6..49c45106399d0a3cd4b2c73f718de3c05766ee7e 100644 --- a/lms/djangoapps/courseware/access.py +++ b/lms/djangoapps/courseware/access.py @@ -16,8 +16,9 @@ import logging from datetime import datetime import six -from django.conf import settings +from django.conf import settings # pylint: disable=unused-import from django.contrib.auth.models import AnonymousUser +from edx_django_utils.monitoring import function_trace from opaque_keys.edx.keys import CourseKey, UsageKey from pytz import UTC from six import text_type @@ -100,6 +101,7 @@ def has_ccx_coach_role(user, course_key): return False +@function_trace('has_access') def has_access(user, action, obj, course_key=None): """ 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): ) +@function_trace('_can_load_course_on_mobile') def _can_load_course_on_mobile(user, course): """ Checks if a user can view the given course on a mobile device. @@ -284,6 +287,7 @@ def _can_enroll_courselike(user, courselike): return ACCESS_DENIED +@function_trace('_has_access_course') def _has_access_course(user, action, courselike): """ Check if user has access to a course. @@ -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_about_page' -- user is able to see the course about page. """ + @function_trace('can_load') def can_load(): """ Can this user load this course? @@ -358,12 +363,14 @@ def _has_access_course(user, action, courselike): return ACCESS_GRANTED + @function_trace('can_enroll') def can_enroll(): """ Returns whether the user can enroll in the course. """ return _can_enroll_courselike(user, courselike) + @function_trace('see_exists') def see_exists(): """ 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): """ return ACCESS_GRANTED if (can_load() or can_enroll()) else ACCESS_DENIED + @function_trace('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 @@ -382,6 +390,7 @@ def _has_access_course(user, action, courselike): or _has_staff_access_to_descriptor(user, courselike, courselike.id) ) + @function_trace('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 @@ -771,6 +780,7 @@ def administrative_accesses_to_course_for_user(user, course_key): return global_staff, staff_access, instructor_access +@function_trace('_has_instructor_access_to_descriptor') def _has_instructor_access_to_descriptor(user, descriptor, course_key): """Helper method that checks whether the user has staff access to the course of the location. @@ -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) +@function_trace('_has_staff_access_to_descriptor') def _has_staff_access_to_descriptor(user, descriptor, course_key): """Helper method that checks whether the user has staff access to the course of the location. diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index 44c2ec417fd75c3a5c563c7b8b5ff6e3336979de..a7477fe27986310f5cf8df24d87e8aefb14a00be 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -15,6 +15,7 @@ from django.conf import settings from django.db.models import Prefetch from django.http import Http404, QueryDict from django.urls import reverse +from edx_django_utils.monitoring import function_trace from fs.errors import ResourceNotFound from opaque_keys.edx.keys import UsageKey from path import Path as path @@ -457,6 +458,7 @@ def get_course_syllabus_section(course, section_key): raise KeyError("Invalid about key " + str(section_key)) +@function_trace('get_courses') def get_courses(user, org=None, filter_=None): """ Return a LazySequence of courses available, optionally filtered by org code (case-insensitive). diff --git a/openedx/core/djangoapps/user_api/accounts/api.py b/openedx/core/djangoapps/user_api/accounts/api.py index 53894d67c77eab74badcfcacfb1ad6829f8943ba..71145a8f1017deff66dcaa50401c6022960887e0 100644 --- a/openedx/core/djangoapps/user_api/accounts/api.py +++ b/openedx/core/djangoapps/user_api/accounts/api.py @@ -13,7 +13,6 @@ from django.core.exceptions import ObjectDoesNotExist from django.core.validators import ValidationError, validate_email from django.utils.translation import override as override_language from django.utils.translation import ugettext as _ -from edx_django_utils.monitoring import set_custom_metric from pytz import UTC from six import text_type # pylint: disable=ungrouped-imports