edx_django_utils.monitoring.internal.code_owner package#
Submodules#
edx_django_utils.monitoring.internal.code_owner.middleware module#
Middleware for code_owner custom attribute
- class edx_django_utils.monitoring.internal.code_owner.middleware.CodeOwnerMonitoringMiddleware(get_response)#
Bases:
object
Django middleware object to set custom attributes for the owner of each view.
For instructions on usage, see: openedx/edx-django-utils
Custom attributes set: - code_owner: The owning team mapped to the current view. - code_owner_module: The module found from the request or current transaction. - code_owner_path_error: The error mapping by path, if code_owner isn’t found in other ways. - code_owner_transaction_error: The error mapping by transaction, if code_owner isn’t found in other ways. - code_owner_transaction_name: The current transaction name used to try to map to code_owner.
This can be used to find missing mappings.
- process_exception(request, exception)#
edx_django_utils.monitoring.internal.code_owner.utils module#
Utilities for monitoring code_owner
- edx_django_utils.monitoring.internal.code_owner.utils.clear_cached_mappings()#
Clears the cached code owner mappings. Useful for testing.
- edx_django_utils.monitoring.internal.code_owner.utils.get_code_owner_from_module(module)#
Attempts lookup of code_owner based on a code module, finding the most specific match. If no match, returns None.
For example, if the module were ‘openedx.features.discounts.views’, this lookup would match on ‘openedx.features.discounts’ before ‘openedx.features’, because the former is more specific.
See how to: openedx/edx-django-utils
- edx_django_utils.monitoring.internal.code_owner.utils.get_code_owner_mappings()#
Returns the contents of the CODE_OWNER_MAPPINGS Django Setting, processed for efficient lookup by path.
- Returns
- dict mapping modules to code owners, or None if there are no
configured mappings, or an empty dict if there is an error processing the setting.
- Return type
(dict)
Example return value:
{ 'xblock_django': 'team-red', 'openedx.core.djangoapps.xblock': 'team-red', 'badges': 'team-blue', }
- edx_django_utils.monitoring.internal.code_owner.utils.get_code_owner_theme_squad_mappings()#
Returns the contents of the CODE_OWNER_THEMES Django Setting, processed for efficient lookup by path.
- Returns
- dict mapping code owners to a dict containing the squad and theme, or
an empty dict if there are no configured mappings.
- Return type
(dict)
Example return value:
{ 'theme-x-team-red': { 'theme': 'theme-x', 'squad': 'team-red', }, 'theme-x-team-blue': { 'theme': 'theme-x', 'squad': 'team-blue', }, }
- edx_django_utils.monitoring.internal.code_owner.utils.is_code_owner_mappings_configured()#
Returns True if code owner mappings were configured, and False otherwise.
- edx_django_utils.monitoring.internal.code_owner.utils.set_code_owner_attribute(wrapped_function)#
Decorator to set the code_owner and code_owner_module custom attributes.
- Celery tasks or other non-web functions do not use middleware, so we need
an alternative way to set the code_owner custom attribute.
Usage:
@task() @set_code_owner_attribute def example_task(): ...
- Note: If the decorator can’t be used for some reason, call
set_code_owner_attribute_from_module
directly.- An untested potential alternative is documented in the ADR covering this decision:
docs/decisions/0003-code-owner-for-celery-tasks.rst
- edx_django_utils.monitoring.internal.code_owner.utils.set_code_owner_attribute_from_module(module)#
Updates the code_owner and code_owner_module custom attributes.
- Celery tasks or other non-web functions do not use middleware, so we need
an alternative way to set the code_owner custom attribute.
- Note: These settings will be overridden by the CodeOwnerMonitoringMiddleware.
This method can’t be used to override web functions at this time.
Usage:
set_code_owner_attribute_from_module(__name__)
- edx_django_utils.monitoring.internal.code_owner.utils.set_code_owner_custom_attributes(code_owner)#
Sets custom metrics for code_owner, code_owner_theme, and code_owner_squad
Module contents#
This directory should only be used internally.
Its public API is exposed in the top-level monitoring __init__.py. See its README.rst for details.