Skip to content

Commit

Permalink
Update tests for missing create_span
Browse files Browse the repository at this point in the history
  • Loading branch information
c24t committed Nov 23, 2019
1 parent 36d3afb commit 371fa89
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ def _before_flask_request():

tracer = trace.tracer()

span = tracer.create_span(
span_name, parent_span, kind=trace.SpanKind.SERVER
span = tracer.start_span(
span_name,
parent_span,
kind=trace.SpanKind.SERVER,
start_time=environ.get(_ENVIRON_STARTTIME_KEY),
)
span.start(environ.get(_ENVIRON_STARTTIME_KEY))
activation = tracer.use_span(span, end_on_exit=True)
activation.__enter__()
environ[_ENVIRON_ACTIVATION_KEY] = activation
Expand Down
13 changes: 7 additions & 6 deletions ext/opentelemetry-ext-flask/tests/test_flask_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import unittest
from unittest import mock

from flask import Flask
from werkzeug.test import Client
Expand Down Expand Up @@ -52,12 +53,12 @@ def test_simple(self):
self.assertEqual(200, resp.status_code)
self.assertEqual([b"Hello: 123"], list(resp.response))

self.create_span.assert_called_with(
self.start_span.assert_called_with(
"hello_endpoint",
trace_api.INVALID_SPAN_CONTEXT,
kind=trace_api.SpanKind.SERVER,
start_time=mock.ANY,
)
self.assertEqual(1, self.span.start.call_count)

# TODO: Change this test to use the SDK, as mocking becomes painful

Expand All @@ -79,12 +80,12 @@ def test_404(self):
self.assertEqual(404, resp.status_code)
resp.close()

self.create_span.assert_called_with(
self.start_span.assert_called_with(
"/bye",
trace_api.INVALID_SPAN_CONTEXT,
kind=trace_api.SpanKind.SERVER,
start_time=mock.ANY,
)
self.assertEqual(1, self.span.start.call_count)

# Nope, this uses Tracer.use_span(end_on_exit)
# self.assertEqual(1, self.span.end.call_count)
Expand All @@ -107,12 +108,12 @@ def test_internal_error(self):
self.assertEqual(500, resp.status_code)
resp.close()

self.create_span.assert_called_with(
self.start_span.assert_called_with(
"hello_endpoint",
trace_api.INVALID_SPAN_CONTEXT,
kind=trace_api.SpanKind.SERVER,
start_time=mock.ANY,
)
self.assertEqual(1, self.span.start.call_count)

# Nope, this uses Tracer.use_span(end_on_exit)
# self.assertEqual(1, self.span.end.call_count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class WsgiTestBase(unittest.TestCase):
def setUp(self):
tracer = trace_api.tracer()
self.span = mock.create_autospec(trace_api.Span, spec_set=True)
self.create_span_patcher = mock.patch.object(
self.start_span_patcher = mock.patch.object(
tracer,
"create_span",
"start_span",
autospec=True,
spec_set=True,
return_value=self.span,
)
self.create_span = self.create_span_patcher.start()
self.start_span = self.start_span_patcher.start()
self.write_buffer = io.BytesIO()
self.write = self.write_buffer.write

Expand All @@ -29,12 +29,9 @@ def setUp(self):
self.exc_info = None

def tearDown(self):
self.create_span_patcher.stop()
self.start_span_patcher.stop()

def start_response(self, status, response_headers, exc_info=None):
# The span should have started already
self.assertEqual(1, self.span.start.call_count)

self.status = status
self.response_headers = response_headers
self.exc_info = exc_info
Expand Down
1 change: 0 additions & 1 deletion ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def validate_response(self, response, error=None):
self.start_span.assert_called_with(
"/", trace_api.INVALID_SPAN_CONTEXT, kind=trace_api.SpanKind.SERVER
)
self.assertEqual(1, self.span.start.call_count)

def test_basic_wsgi_call(self):
app = otel_wsgi.OpenTelemetryMiddleware(simple_wsgi)
Expand Down

0 comments on commit 371fa89

Please sign in to comment.