Skip to content

Commit cd8f4f9

Browse files
fix(wsgi): handle no root span (#2659) (#2669)
* fix(wsgi): handle no root span It is possible for tracer.current_root_span() to return None which was not handled here. * Explicit none check Co-authored-by: Julien Danjou <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Julien Danjou <[email protected]> (cherry picked from commit 6f6da91) Co-authored-by: Kyle Verhoog <[email protected]>
1 parent c83e1c4 commit cd8f4f9

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

ddtrace/contrib/wsgi/wsgi.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ def __init__(self, application, tracer=None, span_modifier=default_wsgi_span_mod
9797
def __call__(self, environ, start_response):
9898
def intercept_start_response(status, response_headers, exc_info=None):
9999
span = self.tracer.current_root_span()
100-
status_code, status_msg = status.split(" ", 1)
101-
span.set_tag("http.status_msg", status_msg)
102-
trace_utils.set_http_meta(span, config.wsgi, status_code=status_code, response_headers=response_headers)
100+
if span is not None:
101+
status_code, status_msg = status.split(" ", 1)
102+
span.set_tag("http.status_msg", status_msg)
103+
trace_utils.set_http_meta(span, config.wsgi, status_code=status_code, response_headers=response_headers)
103104
with self.tracer.trace(
104105
"wsgi.start_response",
105106
service=trace_utils.int_service(None, config.wsgi),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Fix a possible NoneType error in the WSGI middleware start_response method.

0 commit comments

Comments
 (0)