Пример #1
0
    def _set_code_owner_attribute_from_current_transaction(self, request):
        """
        Uses the current transaction name to set the code owner attribute.

        Side-effects:
            Sets code_owner_transaction_name custom attribute, used to determine code_owner

        Returns:
            (str, str): (code_owner, error_message), where at least one of these should be None

        """
        if not is_code_owner_mappings_configured():
            return None, None

        try:
            # Example: openedx.core.djangoapps.contentserver.middleware:StaticContentServer
            transaction_name = get_current_transaction().name
            if not transaction_name:
                return None, 'No current transaction name found.'
            set_custom_attribute('code_owner_transaction_name',
                                 transaction_name)
            module_name = transaction_name.split(':')[0]
            code_owner = get_code_owner_from_module(module_name)
            return code_owner, None
        except Exception as e:  # pylint: disable=broad-except
            return None, str(e)
Пример #2
0
 def test_get_current_transaction_without_newrelic(self):
     current_transaction = get_current_transaction()
     self.assertEqual(current_transaction.name, None)
Пример #3
0
 def test_get_current_transaction(self, mock_newrelic_agent):
     mock_newrelic_agent.current_transaction().name = 'fake-transaction'
     current_transaction = get_current_transaction()
     self.assertEqual(current_transaction.name, 'fake-transaction')