Skip to content

Commit

Permalink
use .get() for extracting info from middleware requests to avoid erro…
Browse files Browse the repository at this point in the history
…rs (#44)
  • Loading branch information
asdvalenzuela authored Dec 20, 2018
1 parent 1ffe66e commit 47cd48c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
20 changes: 12 additions & 8 deletions beeline/middleware/bottle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ def __init__(self, app):
self.app = app

def __call__(self, environ, start_response):
trace_name = "bottle_http_%s" % environ['REQUEST_METHOD'].lower()
request_method = environ.get('REQUEST_METHOD')
if request_method:
trace_name = "bottle_http_%s" % request_method.lower()
else:
trace_name = "bottle_http"
trace = beeline.start_trace(context={
"name": trace_name,
"type": "http_server",
"request.host": environ['HTTP_HOST'],
"request.method": environ['REQUEST_METHOD'],
"request.path": environ['PATH_INFO'],
"request.remote_addr": environ['REMOTE_ADDR'],
"request.host": environ.get('HTTP_HOST'),
"request.method": request_method,
"request.path": environ.get('PATH_INFO'),
"request.remote_addr": environ.get('REMOTE_ADDR'),
"request.content_length": environ.get('CONTENT_LENGTH', 0),
"request.user_agent": environ['HTTP_USER_AGENT'],
"request.scheme": environ['wsgi.url_scheme'],
"request.query": environ['QUERY_STRING']
"request.user_agent": environ.get('HTTP_USER_AGENT'),
"request.scheme": environ.get('wsgi.url_scheme'),
"request.query": environ.get('QUERY_STRING')
})

def _start_response(status, headers, *args):
Expand Down
8 changes: 4 additions & 4 deletions beeline/middleware/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ def create_http_event(self, request):
# the view (and later middleware) are called.

trace_id, parent_id, context = _get_trace_context(request)

trace_name = "django_http_%s" % request.method.lower()

trace = beeline.start_trace(context={
"name": trace_name,
"type": "http_server",
"request.host": request.get_host(),
"request.method": request.method,
"request.path": request.path,
"request.remote_addr": request.META['REMOTE_ADDR'],
"request.content_length": request.META['CONTENT_LENGTH'],
"request.user_agent": request.META['HTTP_USER_AGENT'],
"request.remote_addr": request.META.get('REMOTE_ADDR'),
"request.content_length": request.META.get('CONTENT_LENGTH', 0),
"request.user_agent": request.META.get('HTTP_USER_AGENT'),
"request.scheme": request.scheme,
"request.secure": request.is_secure(),
"request.query": request.GET.dict(),
Expand Down
22 changes: 12 additions & 10 deletions beeline/middleware/flask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,25 @@ def __init__(self, app):
self.app = app

def __call__(self, environ, start_response):
trace_name = "flask_http_%s" % environ.get('REQUEST_METHOD', None)
if trace_name is not None:
trace_name = trace_name.lower()
request_method = environ.get('REQUEST_METHOD')
if request_method:
trace_name = "flask_http_%s" % request_method.lower()
else:
trace_name = "flask_http"

trace_id, parent_id, context = _get_trace_context(environ)

root_span = beeline.start_trace(context={
"type": "http_server",
"name": trace_name,
"request.host": environ.get('HTTP_HOST', None),
"request.method": environ.get('REQUEST_METHOD', None),
"request.path": environ.get('PATH_INFO', None),
"request.remote_addr": environ.get('REMOTE_ADDR', None),
"request.host": environ.get('HTTP_HOST'),
"request.method": request_method,
"request.path": environ.get('PATH_INFO'),
"request.remote_addr": environ.get('REMOTE_ADDR'),
"request.content_length": environ.get('CONTENT_LENGTH', 0),
"request.user_agent": environ.get('HTTP_USER_AGENT', None),
"request.scheme": environ.get('wsgi.url_scheme', None),
"request.query": environ.get('QUERY_STRING', None)
"request.user_agent": environ.get('HTTP_USER_AGENT'),
"request.scheme": environ.get('wsgi.url_scheme'),
"request.query": environ.get('QUERY_STRING')
}, trace_id=trace_id, parent_span_id=parent_id)

# populate any propagated custom context
Expand Down
2 changes: 1 addition & 1 deletion beeline/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '2.3.0'
VERSION = '2.3.1'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
setup(
python_requires='>=2.7',
name='honeycomb-beeline',
version='2.3.0',
version='2.3.1',
description='Honeycomb library for easy instrumentation',
url='https://github.com/honeycombio/beeline-python',
author='Honeycomb.io',
Expand Down

0 comments on commit 47cd48c

Please sign in to comment.