Skip to content

Commit

Permalink
fixup! Various lint
Browse files Browse the repository at this point in the history
  • Loading branch information
timmc-edx committed Jul 24, 2024
1 parent ad706d4 commit b9b55cb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions edx_arch_experiments/datadog_diagnostics/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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()}; "
Expand Down

0 comments on commit b9b55cb

Please sign in to comment.