From c00398411d9c5f4f789e097ab68a6d186f8cbba3 Mon Sep 17 00:00:00 2001 From: Gabriel Gravel Date: Fri, 8 Jun 2018 14:43:27 -0400 Subject: [PATCH] Add default to _after_request_fn (#6) --- flask_opentracing/tracer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flask_opentracing/tracer.py b/flask_opentracing/tracer.py index 11fc77b..262e751 100644 --- a/flask_opentracing/tracer.py +++ b/flask_opentracing/tracer.py @@ -92,6 +92,7 @@ def _before_request_fn(self, attributes): def _after_request_fn(self): request = stack.top.request - span = self._current_spans.pop(request) + # the pop call can fail if the request is interrupted by a `before_request` method so we need a default + span = self._current_spans.pop(request, None) if span is not None: span.finish()