66from unittest .mock import Mock , call , patch
77
88import ddt
9- from django .test import TestCase
9+ from django .test import TestCase , override_settings
1010
1111from edx_django_utils .cache import RequestCache
12- from edx_django_utils .monitoring import CachedCustomMonitoringMiddleware , accumulate , get_current_transaction , increment
12+ from edx_django_utils .monitoring import MonitoringSupportMiddleware , accumulate , get_current_transaction , increment
1313
1414from ..middleware import CachedCustomMonitoringMiddleware as DeprecatedCachedCustomMonitoringMiddleware
1515from ..middleware import MonitoringCustomMetricsMiddleware as DeprecatedMonitoringCustomMetricsMiddleware
@@ -31,8 +31,8 @@ def setUp(self):
3131
3232 @patch ('newrelic.agent' )
3333 @ddt .data (
34- (CachedCustomMonitoringMiddleware , False , 'process_response' ),
35- (CachedCustomMonitoringMiddleware , False , 'process_exception' ),
34+ (MonitoringSupportMiddleware , False , 'process_response' ),
35+ (MonitoringSupportMiddleware , False , 'process_exception' ),
3636 (DeprecatedCachedCustomMonitoringMiddleware , True , 'process_response' ),
3737 (DeprecatedMonitoringCustomMetricsMiddleware , True , 'process_response' ),
3838 )
@@ -76,7 +76,7 @@ def test_accumulate_and_increment(
7676
7777 @patch ('newrelic.agent' )
7878 @ddt .data (
79- (CachedCustomMonitoringMiddleware , False ),
79+ (MonitoringSupportMiddleware , False ),
8080 (DeprecatedCachedCustomMonitoringMiddleware , True ),
8181 (DeprecatedMonitoringCustomMetricsMiddleware , True ),
8282 )
@@ -113,6 +113,21 @@ def test_accumulate_with_illegal_value(
113113 # Assert call args to newrelic.agent.add_custom_parameter().
114114 mock_newrelic_agent .add_custom_parameter .assert_has_calls (nr_agent_calls_expected , any_order = True )
115115
116+ @patch ('ddtrace.Tracer.current_root_span' )
117+ def test_error_tagging (self , mock_get_root_span ):
118+ # Ensure that we continue to support tagging exceptions in MonitoringSupportMiddleware.
119+ # This is only implemented for DatadogBackend at the moment.
120+ fake_exception = Exception ()
121+ mock_root_span = Mock ()
122+ mock_get_root_span .return_value = mock_root_span
123+ with override_settings (OPENEDX_TELEMETRY = ['edx_django_utils.monitoring.DatadogBackend' ]):
124+ MonitoringSupportMiddleware (self .mock_response ).process_exception (
125+ 'fake request' , fake_exception
126+ )
127+ mock_root_span .set_exc_info .assert_called_with (
128+ type (fake_exception ), fake_exception , fake_exception .__traceback__
129+ )
130+
116131 @patch ('newrelic.agent' )
117132 def test_get_current_transaction (self , mock_newrelic_agent ):
118133 mock_newrelic_agent .current_transaction ().name = 'fake-transaction'
0 commit comments