diff --git a/edx_django_utils/monitoring/tests/test_custom_monitoring.py b/edx_django_utils/monitoring/tests/test_custom_monitoring.py index d0e17139..44594104 100644 --- a/edx_django_utils/monitoring/tests/test_custom_monitoring.py +++ b/edx_django_utils/monitoring/tests/test_custom_monitoring.py @@ -6,7 +6,7 @@ from unittest.mock import Mock, call, patch import ddt -from django.test import TestCase +from django.test import TestCase, override_settings from edx_django_utils.cache import RequestCache from edx_django_utils.monitoring import MonitoringSupportMiddleware, accumulate, get_current_transaction, increment @@ -113,11 +113,20 @@ def test_accumulate_with_illegal_value( # Assert call args to newrelic.agent.add_custom_parameter(). mock_newrelic_agent.add_custom_parameter.assert_has_calls(nr_agent_calls_expected, any_order=True) - @patch('edx_django_utils.monitoring.MonitoringSupportMiddleware._tag_root_span_with_error') - def test_error_tagging(self, mock_tag_error): + @patch('ddtrace.Tracer.current_root_span') + def test_error_tagging(self, mock_get_root_span): # Ensure that we continue to support tagging exceptions in MonitoringSupportMiddleware. - MonitoringSupportMiddleware(self.mock_response).process_exception('fake request', 'fake exception') - mock_tag_error.assert_called_with('fake exception') + # This is only implemented for DatadogBackend at the moment. + fake_exception = Exception() + mock_root_span = Mock() + mock_get_root_span.return_value = mock_root_span + with override_settings(OPENEDX_TELEMETRY=['edx_django_utils.monitoring.DatadogBackend']): + MonitoringSupportMiddleware(self.mock_response).process_exception( + 'fake request', fake_exception + ) + mock_root_span.set_exc_info.assert_called_with( + type(fake_exception), fake_exception, fake_exception.__traceback__ + ) @patch('newrelic.agent') def test_get_current_transaction(self, mock_newrelic_agent):