diff --git a/ecommerce/extensions/basket/middleware.py b/ecommerce/extensions/basket/middleware.py index e8c8959d359..bc8aad8e442 100644 --- a/ecommerce/extensions/basket/middleware.py +++ b/ecommerce/extensions/basket/middleware.py @@ -1,6 +1,5 @@ -import newrelic.agent from edx_django_utils import monitoring as monitoring_utils from oscar.apps.basket.middleware import BasketMiddleware as OscarBasketMiddleware from oscar.core.loading import get_model @@ -81,6 +80,6 @@ def get_basket(self, request): return basket - @newrelic.agent.function_trace() + @monitoring_utils.function_trace('apply_offers_to_basket') def apply_offers_to_basket(self, request, basket): apply_offers_on_basket(request, basket) diff --git a/ecommerce/extensions/basket/utils.py b/ecommerce/extensions/basket/utils.py index cd7669e05e1..9c1df4a9704 100644 --- a/ecommerce/extensions/basket/utils.py +++ b/ecommerce/extensions/basket/utils.py @@ -5,13 +5,13 @@ import logging from urllib.parse import unquote, urlencode -import newrelic.agent import pytz import waffle from django.conf import settings from django.contrib import messages from django.db import transaction from django.utils.translation import ugettext_lazy as _ +from edx_django_utils import monitoring as monitoring_utils from oscar.apps.basket.signals import voucher_addition from oscar.core.loading import get_class, get_model @@ -100,7 +100,7 @@ def _use_payment_microfrontend(request): ) -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('add_utm_params_to_url') def add_utm_params_to_url(url, params): # utm_params is [(u'utm_content', u'course-v1:IDBx IDB20.1x 1T2017'),... utm_params = [item for item in params if 'utm_' in item[0]] @@ -113,7 +113,7 @@ def add_utm_params_to_url(url, params): return url -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('add_invalid_code_message_to_url') def add_invalid_code_message_to_url(url, code): if code: message = 'error_message=Code {code} is invalid.'.format(code=str(code)) @@ -121,7 +121,7 @@ def add_invalid_code_message_to_url(url, code): return url -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('prepare_basket') def prepare_basket(request, products, voucher=None): """ Create or get the basket, add products, apply a voucher, and record referral data. @@ -223,7 +223,7 @@ def prepare_basket(request, products, voucher=None): return basket -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('get_basket_switch_data') def get_basket_switch_data(product): """ Given a seat or enrollment product, find the SKU of the related product of @@ -251,7 +251,7 @@ def get_basket_switch_data(product): return switch_link_text, partner_sku -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('_find_seat_enrollment_toggle_sku') def _find_seat_enrollment_toggle_sku(product, target_structure): """ Given a seat or enrollment code product, find the SKU of the related product of @@ -290,7 +290,7 @@ def _find_seat_enrollment_toggle_sku(product, target_structure): return None -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('attribute_cookie_data') def attribute_cookie_data(basket, request): try: with transaction.atomic(): @@ -314,7 +314,7 @@ def attribute_cookie_data(basket, request): logger.exception('Error while attributing cookies to basket.') -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('_referral_from_basket_site') def _referral_from_basket_site(basket, site): try: # There should be only 1 referral instance for one basket. @@ -325,7 +325,7 @@ def _referral_from_basket_site(basket, site): return referral -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('_record_affiliate_basket_attribution') def _record_affiliate_basket_attribution(referral, request): """ Attribute this user's basket to the referring affiliate, if applicable. @@ -339,7 +339,7 @@ def _record_affiliate_basket_attribution(referral, request): referral.affiliate_id = affiliate_id -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('_record_utm_basket_attribution') def _record_utm_basket_attribution(referral, request): """ Attribute this user's basket to UTM data, if applicable. @@ -363,7 +363,7 @@ def _record_utm_basket_attribution(referral, request): referral.utm_created_at = created_at_datetime -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('basket_add_organization_attribute') def basket_add_organization_attribute(basket, request_data): """ Adds the organization, and purchased_on_behalf attribute on basket, if organization value is provided @@ -395,7 +395,7 @@ def basket_add_organization_attribute(basket, request_data): ) -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('basket_add_dynamic_payment_methods_enabled') def basket_add_dynamic_payment_methods_enabled(basket, payment_intent): """ Adds a boolean value which is True if there is more than @@ -413,7 +413,7 @@ def basket_add_dynamic_payment_methods_enabled(basket, payment_intent): basket_attribute.save() -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('basket_add_payment_intent_id_attribute') def basket_add_payment_intent_id_attribute(basket, payment_intent_id): """ Adds the Stripe payment_intent_id attribute on basket. @@ -435,7 +435,7 @@ def basket_add_payment_intent_id_attribute(basket, payment_intent_id): basket_attribute.save() -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('basket_add_enterprise_catalog_attribute') def basket_add_enterprise_catalog_attribute(basket, request_data): """ Add enterprise catalog UUID attribute on basket, if the catalog UUID value @@ -465,7 +465,7 @@ def basket_add_enterprise_catalog_attribute(basket, request_data): BasketAttribute.objects.filter(basket=basket, attribute_type=enterprise_catalog_attribute).delete() -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('_set_basket_bundle_status') def _set_basket_bundle_status(bundle, basket): """ Sets the basket's bundle status @@ -494,7 +494,7 @@ def _set_basket_bundle_status(bundle, basket): BasketAttribute.objects.filter(basket=basket, attribute_type__name=BUNDLE).delete() -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('validate_voucher') def validate_voucher(voucher, user, basket, request_site): """ Validates if a voucher code can be used for user and basket. @@ -566,7 +566,7 @@ def apply_offers_on_basket(request, basket): Applicator().apply(basket, request.user, request) -@newrelic.agent.function_trace() +@monitoring_utils.function_trace('apply_voucher_on_basket_and_check_discount') def apply_voucher_on_basket_and_check_discount(voucher, request, basket): """ Applies voucher on a product. diff --git a/ecommerce/extensions/basket/views.py b/ecommerce/extensions/basket/views.py index 1bd33ab52fe..dbfec7e75fc 100644 --- a/ecommerce/extensions/basket/views.py +++ b/ecommerce/extensions/basket/views.py @@ -9,13 +9,13 @@ from decimal import Decimal import dateutil.parser -import newrelic.agent import waffle from django.http import HttpResponseBadRequest, HttpResponseRedirect from django.shortcuts import render from django.urls import reverse from django.utils.html import escape from django.utils.translation import ugettext as _ +from edx_django_utils import monitoring as monitoring_utils from edx_rest_framework_extensions.permissions import LoginRedirectIfUnauthenticated from opaque_keys.edx.keys import CourseKey from oscar.apps.basket.signals import voucher_removal @@ -98,7 +98,7 @@ class BasketLogicMixin: Business logic for determining basket contents and checkout/payment options. """ - @newrelic.agent.function_trace() + @monitoring_utils.function_trace('process_basket_lines') def process_basket_lines(self, lines): """ Processes the basket lines and extracts information for the view's context. @@ -244,7 +244,7 @@ def _redirect_for_enterprise_data_sharing_consent(self, basket): response=HttpResponseRedirect(redirect_url) ) - @newrelic.agent.function_trace() + @monitoring_utils.function_trace('_get_course_data') def _get_course_data(self, product): """ Return course data. @@ -294,7 +294,7 @@ def _get_course_data(self, product): return course_data, course - @newrelic.agent.function_trace() + @monitoring_utils.function_trace('_get_order_details_message') def _get_order_details_message(self, product): if product.is_course_entitlement_product: return _( @@ -347,7 +347,7 @@ def _get_order_details_message(self, product): else: return None - @newrelic.agent.function_trace() + @monitoring_utils.function_trace('_set_single_enrollment_code_warning_if_needed') def _set_single_enrollment_code_warning_if_needed(self, product, course): assert product.is_enrollment_code_product @@ -377,7 +377,7 @@ def _set_single_enrollment_code_warning_if_needed(self, product, course): ) message_utils.add_message_data(message_code, 'course_about_url', course_about_url) - @newrelic.agent.function_trace() + @monitoring_utils.function_trace('_get_benefit_value') def _get_benefit_value(self, line): if line.has_discount: applied_offer_values = list(self.request.basket.applied_offers().values()) @@ -386,7 +386,7 @@ def _get_benefit_value(self, line): return format_benefit_value(benefit) return None - @newrelic.agent.function_trace() + @monitoring_utils.function_trace('_get_certificate_type') def _get_certificate_type(self, product): if product.is_seat_product or product.is_course_entitlement_product: return product.attr.certificate_type @@ -394,14 +394,14 @@ def _get_certificate_type(self, product): return product.attr.seat_type return None - @newrelic.agent.function_trace() + @monitoring_utils.function_trace('_get_certificate_type_display_value') def _get_certificate_type_display_value(self, product): certificate_type = self._get_certificate_type(product) if certificate_type: return get_certificate_type_display_value(certificate_type) return None - @newrelic.agent.function_trace() + @monitoring_utils.function_trace('_deserialize_date') def _deserialize_date(self, date_string): try: return dateutil.parser.parse(date_string) @@ -507,12 +507,12 @@ def _redirect_response_to_basket_or_payment(self, request, invalid_code=None): class BasketSummaryView(BasketLogicMixin, BasketView): - @newrelic.agent.function_trace() + @monitoring_utils.function_trace('get_context_data') def get_context_data(self, **kwargs): context = super(BasketSummaryView, self).get_context_data(**kwargs) return self._add_to_context_data(context) - @newrelic.agent.function_trace() + @monitoring_utils.function_trace('get') def get(self, request, *args, **kwargs): basket = request.basket @@ -540,7 +540,7 @@ def _redirect_to_payment_microfrontend_if_configured(self, request): redirect_response = HttpResponseRedirect(microfrontend_url) raise RedirectException(response=redirect_response) - @newrelic.agent.function_trace() + @monitoring_utils.function_trace('_add_to_context_data') def _add_to_context_data(self, context): formset = context.get('formset', []) lines = context.get('line_list', []) @@ -577,7 +577,7 @@ def _add_to_context_data(self, context): }) return context - @newrelic.agent.function_trace() + @monitoring_utils.function_trace('_get_payment_processors_data') def _get_payment_processors_data(self, payment_processors): """Retrieve information about payment processors for the client side checkout basket.