Skip to content

Commit

Permalink
tried linting
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSulistio committed Jun 1, 2021
1 parent 2757171 commit 34e7013
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def get_default_span_name():
span_name = otel_wsgi.get_default_span_name(flask.request.environ)
return span_name


def _rewrapped_app(wsgi_app, response_hook=None):
def _wrapped_app(wrapped_app_environ, start_response):
# We want to measure the time for route matching, etc.
Expand Down Expand Up @@ -113,7 +114,7 @@ def _start_response(status, response_headers, *args, **kwargs):
status,
)
if response_hook:
response_hook(span, status, response_headers)
response_hook(span, status, response_headers)
return start_response(status, response_headers, *args, **kwargs)

return wsgi_app(wrapped_app_environ, _start_response)
Expand All @@ -122,11 +123,9 @@ def _start_response(status, response_headers, *args, **kwargs):


def _wrapped_before_request(request_hook=None, tracer=None):

def _before_request():
if _excluded_urls.url_disabled(flask.request.url):
return

flask_request_environ = flask.request.environ
span_name = get_default_span_name()
token = context.attach(
Expand Down Expand Up @@ -159,8 +158,7 @@ def _before_request():
flask_request_environ[_ENVIRON_ACTIVATION_KEY] = activation
flask_request_environ[_ENVIRON_SPAN_KEY] = span
flask_request_environ[_ENVIRON_TOKEN] = token



return _before_request


Expand Down Expand Up @@ -190,20 +188,23 @@ class _InstrumentedFlask(flask.Flask):
_tracer_provider = None
_request_hook = None
_response_hook = None

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self._original_wsgi_ = self.wsgi_app

self.wsgi_app = _rewrapped_app(self.wsgi_app, _InstrumentedFlask._response_hook)

self.wsgi_app = _rewrapped_app(
self.wsgi_app, _InstrumentedFlask._response_hook
)

tracer = trace.get_tracer(
__name__, __version__, _InstrumentedFlask._tracer_provider
)

_before_request = _wrapped_before_request(
_InstrumentedFlask._request_hook, tracer,
_InstrumentedFlask._request_hook,
tracer,
)
self._before_request = _before_request
self.before_request(_before_request)
Expand All @@ -216,6 +217,7 @@ class FlaskInstrumentor(BaseInstrumentor):
See `BaseInstrumentor`
"""

def _instrument(self, **kwargs):
self._original_flask = flask.Flask
request_hook = kwargs.get("request_hook")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def test_404(self):
self.assertEqual(span_list[0].name, "HTTP POST")
self.assertEqual(span_list[0].kind, trace.SpanKind.SERVER)
self.assertEqual(span_list[0].attributes, expected_attrs)

def test_internal_error(self):
expected_attrs = expected_attributes(
{
Expand Down

0 comments on commit 34e7013

Please sign in to comment.