From 371fa89ced8df439f2f9cc378102e727f6640932 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Fri, 22 Nov 2019 17:28:42 -0800 Subject: [PATCH] Update tests for missing create_span --- .../src/opentelemetry/ext/flask/__init__.py | 8 +++++--- .../tests/test_flask_integration.py | 13 +++++++------ .../src/opentelemetry/ext/testutil/wsgitestutil.py | 11 ++++------- .../tests/test_wsgi_middleware.py | 1 - 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py index eedc8d5998..662cea752a 100644 --- a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py +++ b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py @@ -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 diff --git a/ext/opentelemetry-ext-flask/tests/test_flask_integration.py b/ext/opentelemetry-ext-flask/tests/test_flask_integration.py index dfb9dee885..d03e7604a8 100644 --- a/ext/opentelemetry-ext-flask/tests/test_flask_integration.py +++ b/ext/opentelemetry-ext-flask/tests/test_flask_integration.py @@ -13,6 +13,7 @@ # limitations under the License. import unittest +from unittest import mock from flask import Flask from werkzeug.test import Client @@ -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 @@ -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) @@ -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) diff --git a/ext/opentelemetry-ext-testutil/src/opentelemetry/ext/testutil/wsgitestutil.py b/ext/opentelemetry-ext-testutil/src/opentelemetry/ext/testutil/wsgitestutil.py index d9cc9ff6a9..fba6a8cda2 100644 --- a/ext/opentelemetry-ext-testutil/src/opentelemetry/ext/testutil/wsgitestutil.py +++ b/ext/opentelemetry-ext-testutil/src/opentelemetry/ext/testutil/wsgitestutil.py @@ -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 @@ -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 diff --git a/ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py b/ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py index 344844a8ac..97c93880e4 100644 --- a/ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py +++ b/ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py @@ -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)