diff --git a/edx_arch_experiments/datadog_diagnostics/middleware.py b/edx_arch_experiments/datadog_diagnostics/middleware.py index 3404a0c..56cb3ed 100644 --- a/edx_arch_experiments/datadog_diagnostics/middleware.py +++ b/edx_arch_experiments/datadog_diagnostics/middleware.py @@ -22,6 +22,7 @@ LOG_ROOT_SPAN = WaffleFlag('datadog.diagnostics.log_root_span', module_name=__name__) +# pylint: disable=missing-function-docstring class DatadogDiagnosticMiddleware: """ Middleware to add diagnostic logging for Datadog. @@ -36,19 +37,19 @@ def __init__(self, get_response): self.error = False try: - from ddtrace import tracer + from ddtrace import tracer # pylint: disable=import-outside-toplevel self.dd_tracer = tracer except ImportError: # If import fails, don't even load this middleware. - raise MiddlewareNotUsed + raise MiddlewareNotUsed # pylint: disable=raise-missing-from def __call__(self, request): return self.get_response(request) - def process_view(self, request, view_func, view_args, view_kwargs): + def process_view(self, request, _view_func, _view_args, _view_kwargs): try: self.log_diagnostics(request) - except e: + except BaseException as e: # If there's an error, it will probably hit every request, # so let's just log it once. if not self.error: @@ -59,10 +60,14 @@ def process_view(self, request, view_func, view_args, view_kwargs): ) def log_diagnostics(self, request): + """ + Contains all the actual logging logic. + """ if LOG_ROOT_SPAN.is_enabled(): route_pattern = getattr(request.resolver_match, 'route', None) local_root_span = self.dd_tracer.current_root_span() current_span = self.dd_tracer.current_span() + # pylint: disable=protected-access log.info( f"Datadog span diagnostics: Route = {route_pattern}; " f"local root span = {local_root_span._pprint()}; "