Add newrelic instrumentation to forum views
This commit is contained in:
@@ -6,6 +6,7 @@ from django.contrib.auth.decorators import login_required
|
||||
from django.http import Http404
|
||||
from django.core.context_processors import csrf
|
||||
from django.contrib.auth.models import User
|
||||
import newrelic.agent
|
||||
|
||||
from mitxmako.shortcuts import render_to_response
|
||||
from courseware.courses import get_course_with_access
|
||||
@@ -25,6 +26,7 @@ escapedict = {'"': '"'}
|
||||
log = logging.getLogger("edx.discussions")
|
||||
|
||||
|
||||
@newrelic.agent.function_trace()
|
||||
def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAGE):
|
||||
"""
|
||||
This may raise cc.utils.CommentClientError or
|
||||
@@ -107,6 +109,8 @@ def inline_discussion(request, course_id, discussion_id):
|
||||
"""
|
||||
Renders JSON for DiscussionModules
|
||||
"""
|
||||
nr_transaction = newrelic.agent.current_transaction()
|
||||
|
||||
course = get_course_with_access(request.user, course_id, 'load_forum')
|
||||
|
||||
try:
|
||||
@@ -120,7 +124,8 @@ def inline_discussion(request, course_id, discussion_id):
|
||||
log.error("Error loading inline discussion threads.")
|
||||
raise Http404
|
||||
|
||||
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
|
||||
with newrelic.agent.FunctionTrace(nr_transaction, "get_metadata_for_threads"):
|
||||
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
|
||||
|
||||
allow_anonymous = course.allow_anonymous
|
||||
allow_anonymous_to_peers = course.allow_anonymous_to_peers
|
||||
@@ -167,9 +172,11 @@ def forum_form_discussion(request, course_id):
|
||||
"""
|
||||
Renders the main Discussion page, potentially filtered by a search query
|
||||
"""
|
||||
nr_transaction = newrelic.agent.current_transaction()
|
||||
|
||||
course = get_course_with_access(request.user, course_id, 'load_forum')
|
||||
category_map = utils.get_discussion_category_map(course)
|
||||
with newrelic.agent.FunctionTrace(nr_transaction, "get_discussion_category_map"):
|
||||
category_map = utils.get_discussion_category_map(course)
|
||||
|
||||
try:
|
||||
unsafethreads, query_params = get_threads(request, course_id) # This might process a search query
|
||||
@@ -184,12 +191,15 @@ def forum_form_discussion(request, course_id):
|
||||
user = cc.User.from_django_user(request.user)
|
||||
user_info = user.to_dict()
|
||||
|
||||
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
|
||||
with newrelic.agent.FunctionTrace(nr_transaction, "get_metadata_for_threads"):
|
||||
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
|
||||
|
||||
with newrelic.agent.FunctionTrace(nr_transaction, "add_courseware_context_to_threads"):
|
||||
for thread in threads:
|
||||
courseware_context = get_courseware_context(thread, course)
|
||||
if courseware_context:
|
||||
thread.update(courseware_context)
|
||||
|
||||
for thread in threads:
|
||||
courseware_context = get_courseware_context(thread, course)
|
||||
if courseware_context:
|
||||
thread.update(courseware_context)
|
||||
if request.is_ajax():
|
||||
return utils.JsonResponse({
|
||||
'discussion_data': threads, # TODO: Standardize on 'discussion_data' vs 'threads'
|
||||
@@ -207,10 +217,11 @@ def forum_form_discussion(request, course_id):
|
||||
#trending_tags = cc.search_trending_tags(
|
||||
# course_id,
|
||||
#)
|
||||
cohorts = get_course_cohorts(course_id)
|
||||
cohorted_commentables = get_cohorted_commentables(course_id)
|
||||
with newrelic.agent.FunctionTrace(nr_transaction, "get_cohort_info"):
|
||||
cohorts = get_course_cohorts(course_id)
|
||||
cohorted_commentables = get_cohorted_commentables(course_id)
|
||||
|
||||
user_cohort_id = get_cohort_id(request.user, course_id)
|
||||
user_cohort_id = get_cohort_id(request.user, course_id)
|
||||
|
||||
context = {
|
||||
'csrf': csrf(request)['csrf_token'],
|
||||
@@ -238,6 +249,8 @@ def forum_form_discussion(request, course_id):
|
||||
|
||||
@login_required
|
||||
def single_thread(request, course_id, discussion_id, thread_id):
|
||||
nr_transaction = newrelic.agent.current_transaction()
|
||||
|
||||
course = get_course_with_access(request.user, course_id, 'load_forum')
|
||||
cc_user = cc.User.from_django_user(request.user)
|
||||
user_info = cc_user.to_dict()
|
||||
@@ -249,8 +262,10 @@ def single_thread(request, course_id, discussion_id, thread_id):
|
||||
raise Http404
|
||||
|
||||
if request.is_ajax():
|
||||
courseware_context = get_courseware_context(thread, course)
|
||||
annotated_content_info = utils.get_annotated_content_infos(course_id, thread, request.user, user_info=user_info)
|
||||
with newrelic.agent.FunctionTrace(nr_transaction, "get_courseware_context"):
|
||||
courseware_context = get_courseware_context(thread, course)
|
||||
with newrelic.agent.FunctionTrace(nr_transaction, "get_annotated_content_infos"):
|
||||
annotated_content_info = utils.get_annotated_content_infos(course_id, thread, request.user, user_info=user_info)
|
||||
context = {'thread': thread.to_dict(), 'course_id': course_id}
|
||||
# TODO: Remove completely or switch back to server side rendering
|
||||
# html = render_to_string('discussion/_ajax_single_thread.html', context)
|
||||
@@ -264,7 +279,8 @@ def single_thread(request, course_id, discussion_id, thread_id):
|
||||
})
|
||||
|
||||
else:
|
||||
category_map = utils.get_discussion_category_map(course)
|
||||
with newrelic.agent.FunctionTrace(nr_transaction, "get_discussion_category_map"):
|
||||
category_map = utils.get_discussion_category_map(course)
|
||||
|
||||
try:
|
||||
threads, query_params = get_threads(request, course_id)
|
||||
@@ -275,16 +291,17 @@ def single_thread(request, course_id, discussion_id, thread_id):
|
||||
|
||||
course = get_course_with_access(request.user, course_id, 'load_forum')
|
||||
|
||||
for thread in threads:
|
||||
courseware_context = get_courseware_context(thread, course)
|
||||
if courseware_context:
|
||||
thread.update(courseware_context)
|
||||
if thread.get('group_id') and not thread.get('group_name'):
|
||||
thread['group_name'] = get_cohort_by_id(course_id, thread.get('group_id')).name
|
||||
with newrelic.agent.FunctionTrace(nr_transaction, "add_courseware_context_to_threads"):
|
||||
for thread in threads:
|
||||
courseware_context = get_courseware_context(thread, course)
|
||||
if courseware_context:
|
||||
thread.update(courseware_context)
|
||||
if thread.get('group_id') and not thread.get('group_name'):
|
||||
thread['group_name'] = get_cohort_by_id(course_id, thread.get('group_id')).name
|
||||
|
||||
#patch for backward compatibility with comments service
|
||||
if not "pinned" in thread:
|
||||
thread["pinned"] = False
|
||||
#patch for backward compatibility with comments service
|
||||
if not "pinned" in thread:
|
||||
thread["pinned"] = False
|
||||
|
||||
threads = [utils.safe_content(thread) for thread in threads]
|
||||
|
||||
@@ -298,11 +315,13 @@ def single_thread(request, course_id, discussion_id, thread_id):
|
||||
# course_id,
|
||||
#)
|
||||
|
||||
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
|
||||
with newrelic.agent.FunctionTrace(nr_transaction, "get_metadata_for_threads"):
|
||||
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
|
||||
|
||||
cohorts = get_course_cohorts(course_id)
|
||||
cohorted_commentables = get_cohorted_commentables(course_id)
|
||||
user_cohort = get_cohort_id(request.user, course_id)
|
||||
with newrelic.agent.FunctionTrace(nr_transaction, "get_cohort_info"):
|
||||
cohorts = get_course_cohorts(course_id)
|
||||
cohorted_commentables = get_cohorted_commentables(course_id)
|
||||
user_cohort = get_cohort_id(request.user, course_id)
|
||||
|
||||
context = {
|
||||
'discussion_id': discussion_id,
|
||||
@@ -332,6 +351,8 @@ def single_thread(request, course_id, discussion_id, thread_id):
|
||||
|
||||
@login_required
|
||||
def user_profile(request, course_id, user_id):
|
||||
nr_transaction = newrelic.agent.current_transaction()
|
||||
|
||||
#TODO: Allow sorting?
|
||||
course = get_course_with_access(request.user, course_id, 'load_forum')
|
||||
try:
|
||||
@@ -347,7 +368,8 @@ def user_profile(request, course_id, user_id):
|
||||
query_params['num_pages'] = num_pages
|
||||
user_info = cc.User.from_django_user(request.user).to_dict()
|
||||
|
||||
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
|
||||
with newrelic.agent.FunctionTrace(nr_transaction, "get_metadata_for_threads"):
|
||||
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
|
||||
|
||||
if request.is_ajax():
|
||||
return utils.JsonResponse({
|
||||
@@ -374,6 +396,8 @@ def user_profile(request, course_id, user_id):
|
||||
|
||||
|
||||
def followed_threads(request, course_id, user_id):
|
||||
nr_transaction = newrelic.agent.current_transaction()
|
||||
|
||||
course = get_course_with_access(request.user, course_id, 'load_forum')
|
||||
try:
|
||||
profiled_user = cc.User(id=user_id, course_id=course_id)
|
||||
@@ -390,7 +414,8 @@ def followed_threads(request, course_id, user_id):
|
||||
query_params['num_pages'] = num_pages
|
||||
user_info = cc.User.from_django_user(request.user).to_dict()
|
||||
|
||||
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
|
||||
with newrelic.agent.FunctionTrace(nr_transaction, "get_metadata_for_threads"):
|
||||
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
|
||||
if request.is_ajax():
|
||||
return utils.JsonResponse({
|
||||
'annotated_content_info': annotated_content_info,
|
||||
|
||||
Reference in New Issue
Block a user