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

ext/wsgi: use current span when extracting fails #226

Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def __call__(self, environ, start_response):
tracer = trace.tracer()
path_info = environ["PATH_INFO"] or "/"
parent_span = propagators.extract(_get_header_from_environ, environ)
# if extracing fails then use current span as parent
if parent_span is trace.INVALID_SPAN_CONTEXT:
parent_span = tracer.CURRENT_SPAN

span = tracer.create_span(
path_info, parent_span, kind=trace.SpanKind.SERVER
Expand Down
6 changes: 3 additions & 3 deletions ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def error_wsgi(environ, start_response):

class TestWsgiApplication(unittest.TestCase):
def setUp(self):
tracer = trace_api.tracer()
self.tracer = trace_api.tracer()
self.span = mock.create_autospec(trace_api.Span, spec_set=True)
self.create_span_patcher = mock.patch.object(
tracer,
self.tracer,
"create_span",
autospec=True,
spec_set=True,
Expand Down Expand Up @@ -131,7 +131,7 @@ def validate_response(self, response, error=None):

# Verify that start_span has been called
self.create_span.assert_called_with(
"/", trace_api.INVALID_SPAN_CONTEXT, kind=trace_api.SpanKind.SERVER
"/", self.tracer.CURRENT_SPAN, kind=trace_api.SpanKind.SERVER
)
self.span.start.assert_called_with()

Expand Down