Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make plugin compatible with Django < 2.2 #52

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions skywalking/plugins/sw_django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ def install():
_get_response = BaseHandler.get_response
_handle_uncaught_exception = exception.handle_uncaught_exception

def _sw_get_response(this: BaseHandler, request):
def _sw_get_response(this, request):
if request is None:
resp = _get_response(this, request)
return resp

context = get_context()
carrier = Carrier()
for item in carrier:
if item.key.capitalize() in request.headers:
item.val = request.headers[item.key.capitalize()]
# Any HTTP headers in the request are converted to META keys by converting all characters to uppercase,
# replacing any hyphens with underscores and adding an HTTP_ prefix to the name.
# https://docs.djangoproject.com/en/3.0/ref/request-response/#django.http.HttpRequest.META
sw_http_header_key = 'HTTP_%s' % item.key.upper().replace('-', '_')
if sw_http_header_key in request.META:
item.val = request.META[sw_http_header_key]

with context.new_entry_span(op=request.path, carrier=carrier) as span:
span.layer = Layer.Http
Expand All @@ -61,7 +65,6 @@ def _sw_get_response(this: BaseHandler, request):
span.tag(Tag(key=tags.HttpStatus, val=resp.status_code))
if resp.status_code >= 400:
span.error_occurred = True

return resp

def _sw_handle_uncaught_exception(request, resolver, exc_info):
Expand Down