From 780c0cacb83763151f2e88329f437578ec5016de Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 14 Nov 2019 11:05:45 -0800 Subject: [PATCH 1/7] removing create_span from the api Signed-off-by: Alex Boten --- .../src/opentelemetry/ext/wsgi/__init__.py | 4 +- .../tests/test_wsgi_middleware.py | 12 ++--- .../src/opentelemetry/trace/__init__.py | 47 +------------------ opentelemetry-api/tests/trace/test_tracer.py | 4 -- .../src/opentelemetry/sdk/trace/__init__.py | 13 ++++- 5 files changed, 21 insertions(+), 59 deletions(-) diff --git a/ext/opentelemetry-ext-wsgi/src/opentelemetry/ext/wsgi/__init__.py b/ext/opentelemetry-ext-wsgi/src/opentelemetry/ext/wsgi/__init__.py index 5e619eb7c6a..cf74599c498 100644 --- a/ext/opentelemetry-ext-wsgi/src/opentelemetry/ext/wsgi/__init__.py +++ b/ext/opentelemetry-ext-wsgi/src/opentelemetry/ext/wsgi/__init__.py @@ -109,10 +109,10 @@ def __call__(self, environ, start_response): path_info = environ["PATH_INFO"] or "/" parent_span = propagators.extract(_get_header_from_environ, environ) - span = tracer.create_span( + span = tracer.start_span( path_info, parent_span, kind=trace.SpanKind.SERVER ) - span.start() + try: with tracer.use_span(span): self._add_request_attributes(span, environ) diff --git a/ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py b/ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py index e5dc9654fd2..66f27461839 100644 --- a/ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py +++ b/ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py @@ -77,14 +77,14 @@ class TestWsgiApplication(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 @@ -97,11 +97,10 @@ 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.span.start.assert_called_once_with() self.status = status self.response_headers = response_headers @@ -130,10 +129,9 @@ def validate_response(self, response, error=None): self.assertIsNone(self.exc_info) # Verify that start_span has been called - self.create_span.assert_called_with( + self.start_span.assert_called_with( "/", trace_api.INVALID_SPAN_CONTEXT, kind=trace_api.SpanKind.SERVER ) - self.span.start.assert_called_with() def test_basic_wsgi_call(self): app = OpenTelemetryMiddleware(simple_wsgi) diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index 412a106229d..0d24c05bedb 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -46,14 +46,12 @@ from opentelemetry.api.trace import tracer # Explicit parent span assignment - span = tracer.create_span("child", parent=parent) as child: + child = tracer.start_span("child", parent=parent) - # The caller is responsible for starting and ending the span - span.start() try: do_work(span=child) finally: - span.end() + child.end() Applications should generally use a single global tracer, and use either implicit or explicit context propagation consistently throughout. @@ -500,47 +498,6 @@ def start_as_current_span( # pylint: disable=unused-argument,no-self-use yield INVALID_SPAN - def create_span( - self, - name: str, - parent: ParentSpan = CURRENT_SPAN, - kind: SpanKind = SpanKind.INTERNAL, - ) -> "Span": - """Creates a span. - - Creating the span does not start it, and should not affect the tracer's - context. To start the span and update the tracer's context to make it - the currently active span, see :meth:`use_span`. - - By default the current span will be used as parent, but an explicit - parent can also be specified, either a Span or a SpanContext. - If the specified value is `None`, the created span will be a root - span. - - Applications that need to create spans detached from the tracer's - context should use this method. - - with tracer.start_as_current_span(name) as span: - do_work() - - This is equivalent to:: - - span = tracer.create_span(name) - with tracer.use_span(span): - do_work() - - Args: - name: The name of the span to be created. - parent: The span's parent. Defaults to the current span. - kind: The span's kind (relationship to parent). Note that is - meaningful even if there is no parent. - - Returns: - The newly-created span. - """ - # pylint: disable=unused-argument,no-self-use - return INVALID_SPAN - @contextmanager # type: ignore def use_span( self, span: "Span", end_on_exit: bool = False diff --git a/opentelemetry-api/tests/trace/test_tracer.py b/opentelemetry-api/tests/trace/test_tracer.py index 79ff76afc15..b57f2ff6d2b 100644 --- a/opentelemetry-api/tests/trace/test_tracer.py +++ b/opentelemetry-api/tests/trace/test_tracer.py @@ -33,10 +33,6 @@ def test_start_as_current_span(self): with self.tracer.start_as_current_span("") as span: self.assertIsInstance(span, trace.Span) - def test_create_span(self): - span = self.tracer.create_span("") - self.assertIsInstance(span, trace.Span) - def test_use_span(self): span = trace.Span() with self.tracer.use_span(span): diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index d06d34d93bc..8dd30cb1a89 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -367,7 +367,18 @@ def create_span( parent: trace_api.ParentSpan = trace_api.Tracer.CURRENT_SPAN, kind: trace_api.SpanKind = trace_api.SpanKind.INTERNAL, ) -> "trace_api.Span": - """See `opentelemetry.trace.Tracer.create_span`. + """ + Creating the span does not start it, and should not affect the tracer's + context. To start the span and update the tracer's context to make it + the currently active span, see :meth:`use_span`. + + By default the current span will be used as parent, but an explicit + parent can also be specified, either a Span or a SpanContext. + If the specified value is `None`, the created span will be a root + span. + + Applications that need to create spans detached from the tracer's + context should use this method. If `parent` is null the new span will be created as a root span, i.e. a span with no parent context. By default, the new span will be created From 4774f2de7816ab7471823d25a2d4f3d44fccb2fd Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 14 Nov 2019 11:13:02 -0800 Subject: [PATCH 2/7] fix documentation Signed-off-by: Alex Boten --- opentelemetry-api/src/opentelemetry/trace/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index 0d24c05bedb..c41dc554f86 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -30,10 +30,10 @@ created as children of the currently active span, and the newly-created span can optionally become the new active span:: - from opentelemetry.trace import tracer + from opentelemetry import trace # Create a new root span, set it as the current span in context - with tracer.start_as_current_span("parent"): + with trace.tracer().start_as_current_span("parent"): # Attach a new child and update the current span with tracer.start_as_current_span("child"): do_work(): @@ -43,10 +43,10 @@ When creating a span that's "detached" from the context the active span doesn't change, and the caller is responsible for managing the span's lifetime:: - from opentelemetry.api.trace import tracer + from opentelemetry import trace # Explicit parent span assignment - child = tracer.start_span("child", parent=parent) + child = trace.tracer().start_span("child", parent=parent) try: do_work(span=child) From 9c80a83a25384109764c160a22e49d05adf7e435 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 14 Nov 2019 11:24:32 -0800 Subject: [PATCH 3/7] fixing docs Signed-off-by: Alex Boten --- opentelemetry-api/src/opentelemetry/trace/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index c41dc554f86..042c92369b2 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -216,8 +216,7 @@ def add_lazy_link(self, link: "Link") -> None: def update_name(self, name: str) -> None: """Updates the `Span` name. - This will override the name provided via :func:`Tracer.create_span` - or :func:`Tracer.start_span`. + This will override the name provided via :func:`Tracer.start_span`. Upon this update, any sampling behavior based on Span name will depend on the implementation. From 87a4b97f6631ac78ca9c11259d7c5e200076b057 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Tue, 19 Nov 2019 09:19:16 -0800 Subject: [PATCH 4/7] Add start_time parameter to start_span This preserves the ability to set the `start_time` of a span that is currently available through calling `.start` Signed-off-by: Alex Boten --- .../ext/opentracing_shim/__init__.py | 16 +++++++--------- .../src/opentelemetry/trace/__init__.py | 12 ++---------- .../src/opentelemetry/sdk/trace/__init__.py | 3 ++- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/ext/opentelemetry-ext-opentracing-shim/src/opentelemetry/ext/opentracing_shim/__init__.py b/ext/opentelemetry-ext-opentracing-shim/src/opentelemetry/ext/opentracing_shim/__init__.py index eefb85466ae..78db0c96c7d 100644 --- a/ext/opentelemetry-ext-opentracing-shim/src/opentelemetry/ext/opentracing_shim/__init__.py +++ b/ext/opentelemetry-ext-opentracing-shim/src/opentelemetry/ext/opentracing_shim/__init__.py @@ -238,14 +238,6 @@ def start_span( for ref in references: links.append(trace_api.Link(ref.referenced_context.unwrap())) - span = self._otel_tracer.create_span( - operation_name, parent, links=links - ) - - if tags: - for key, value in tags.items(): - span.set_attribute(key, value) - # The OpenTracing API expects time values to be `float` values which # represent the number of seconds since the epoch. OpenTelemetry # represents time values as nanoseconds since the epoch. @@ -253,7 +245,13 @@ def start_span( if start_time_ns is not None: start_time_ns = util.time_seconds_to_ns(start_time) - span.start(start_time=start_time_ns) + span = self._otel_tracer.start_span( + operation_name, parent, + links=links, + attributes=tags, + start_time=start_time_ns, + ) + context = SpanContextShim(span.get_context()) return SpanShim(self, context, span) diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index 3e3b01b024b..f2abf8ff9b7 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -145,16 +145,6 @@ class SpanKind(enum.Enum): class Span: """A span represents a single operation within a trace.""" - def start(self, start_time: typing.Optional[int] = None) -> None: - """Sets the current time as the span's start time. - - Each span represents a single operation. The span's start time is the - wall time at which the operation started. - - Only the first call to `start` should modify the span, and - implementations are free to ignore or raise on further calls. - """ - def end(self, end_time: int = None) -> None: """Sets the current time as the span's end time. @@ -401,6 +391,7 @@ def start_span( kind: SpanKind = SpanKind.INTERNAL, attributes: typing.Optional[types.Attributes] = None, links: typing.Sequence[Link] = (), + start_time: typing.Optional[int] = None, ) -> "Span": """Starts a span. @@ -431,6 +422,7 @@ def start_span( meaningful even if there is no parent. attributes: The span's attributes. links: Links span to other spans + start_time: Sets the start time of a span Returns: The newly-created span. diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index b2dea9168c3..74a4eea1b94 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -321,11 +321,12 @@ def start_span( kind: trace_api.SpanKind = trace_api.SpanKind.INTERNAL, attributes: Optional[types.Attributes] = None, links: Sequence[trace_api.Link] = (), + start_time: Optional[int] = None, ) -> "Span": """See `opentelemetry.trace.Tracer.start_span`.""" span = self.create_span(name, parent, kind, attributes, links) - span.start() + span.start(start_time=start_time) return span def start_as_current_span( From f95d5974ccaf4fe4930fa3099873f3b3dfd24a8e Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Tue, 19 Nov 2019 10:30:47 -0800 Subject: [PATCH 5/7] Remove create_span from the sdk Signed-off-by: Alex Boten --- .../ext/opentracing_shim/__init__.py | 5 +- .../src/opentelemetry/sdk/trace/__init__.py | 50 ++++--------------- opentelemetry-sdk/tests/trace/test_trace.py | 10 ++-- 3 files changed, 18 insertions(+), 47 deletions(-) diff --git a/ext/opentelemetry-ext-opentracing-shim/src/opentelemetry/ext/opentracing_shim/__init__.py b/ext/opentelemetry-ext-opentracing-shim/src/opentelemetry/ext/opentracing_shim/__init__.py index 78db0c96c7d..338674eec42 100644 --- a/ext/opentelemetry-ext-opentracing-shim/src/opentelemetry/ext/opentracing_shim/__init__.py +++ b/ext/opentelemetry-ext-opentracing-shim/src/opentelemetry/ext/opentracing_shim/__init__.py @@ -246,12 +246,13 @@ def start_span( start_time_ns = util.time_seconds_to_ns(start_time) span = self._otel_tracer.start_span( - operation_name, parent, + operation_name, + parent, links=links, attributes=tags, start_time=start_time_ns, ) - + context = SpanContextShim(span.get_context()) return SpanShim(self, context, span) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 74a4eea1b94..9b55c39567f 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -314,21 +314,6 @@ def get_current_span(self): """See `opentelemetry.trace.Tracer.get_current_span`.""" return self._current_span_slot.get() - def start_span( - self, - name: str, - parent: trace_api.ParentSpan = trace_api.Tracer.CURRENT_SPAN, - kind: trace_api.SpanKind = trace_api.SpanKind.INTERNAL, - attributes: Optional[types.Attributes] = None, - links: Sequence[trace_api.Link] = (), - start_time: Optional[int] = None, - ) -> "Span": - """See `opentelemetry.trace.Tracer.start_span`.""" - - span = self.create_span(name, parent, kind, attributes, links) - span.start(start_time=start_time) - return span - def start_as_current_span( self, name: str, @@ -342,33 +327,16 @@ def start_as_current_span( span = self.start_span(name, parent, kind, attributes, links) return self.use_span(span, end_on_exit=True) - def create_span( + def start_span( self, name: str, parent: trace_api.ParentSpan = trace_api.Tracer.CURRENT_SPAN, kind: trace_api.SpanKind = trace_api.SpanKind.INTERNAL, attributes: Optional[types.Attributes] = None, links: Sequence[trace_api.Link] = (), - ) -> "trace_api.Span": - """ - Creating the span does not start it, and should not affect the tracer's - context. To start the span and update the tracer's context to make it - the currently active span, see :meth:`use_span`. - - By default the current span will be used as parent, but an explicit - parent can also be specified, either a Span or a SpanContext. - If the specified value is `None`, the created span will be a root - span. - - Applications that need to create spans detached from the tracer's - context should use this method. - - If `parent` is null the new span will be created as a root span, i.e. a - span with no parent context. By default, the new span will be created - as a child of the current span in this tracer's context, or as a root - span if no current span exists. - """ - span_id = generate_span_id() + start_time: Optional[int] = None, + ) -> "Span": + """See `opentelemetry.trace.Tracer.start_span`.""" if parent is Tracer.CURRENT_SPAN: parent = self.get_current_span() @@ -393,7 +361,7 @@ def create_span( trace_state = parent_context.trace_state context = trace_api.SpanContext( - trace_id, span_id, trace_options, trace_state + trace_id, generate_span_id(), trace_options, trace_state ) # The sampler decides whether to create a real or no-op span at the @@ -417,7 +385,7 @@ def create_span( # apply sampling decision attributes after initial attributes span_attributes = attributes.copy() span_attributes.update(sampling_decision.attributes) - return Span( + span = Span( name=name, context=context, parent=parent, @@ -427,8 +395,10 @@ def create_span( kind=kind, links=links, ) - - return trace_api.DefaultSpan(context=context) + span.start(start_time=start_time) + else: + span = trace_api.DefaultSpan(context=context) + return span @contextmanager def use_span( diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 0d36c003e0f..9a5abd40d21 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -33,9 +33,9 @@ def test_default_sampler(self): # Check that the default tracer creates real spans via the default # sampler - root_span = tracer.create_span(name="root span", parent=None) + root_span = tracer.start_span(name="root span", parent=None) self.assertIsInstance(root_span, trace.Span) - child_span = tracer.create_span(name="child span", parent=root_span) + child_span = tracer.start_span(name="child span", parent=root_span) self.assertIsInstance(child_span, trace.Span) def test_sampler_no_sampling(self): @@ -44,9 +44,9 @@ def test_sampler_no_sampling(self): # Check that the default tracer creates no-op spans if the sampler # decides not to sampler - root_span = tracer.create_span(name="root span", parent=None) + root_span = tracer.start_span(name="root span", parent=None) self.assertIsInstance(root_span, trace_api.DefaultSpan) - child_span = tracer.create_span(name="child span", parent=root_span) + child_span = tracer.start_span(name="child span", parent=root_span) self.assertIsInstance(child_span, trace_api.DefaultSpan) @@ -59,7 +59,7 @@ def test_create_span_invalid_spancontext(self): eliminates redundant error handling logic in exporters. """ tracer = trace.Tracer("test_create_span_invalid_spancontext") - new_span = tracer.create_span( + new_span = tracer.start_span( "root", parent=trace_api.INVALID_SPAN_CONTEXT ) self.assertTrue(new_span.context.is_valid()) From e38f5d6adf71d73bb671881f718f58d504191055 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Tue, 19 Nov 2019 10:31:49 -0800 Subject: [PATCH 6/7] rename test Signed-off-by: Alex Boten --- opentelemetry-sdk/tests/trace/test_trace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 9a5abd40d21..e797b1c8908 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -51,14 +51,14 @@ def test_sampler_no_sampling(self): class TestSpanCreation(unittest.TestCase): - def test_create_span_invalid_spancontext(self): + def test_start_span_invalid_spancontext(self): """If an invalid span context is passed as the parent, the created span should use a new span id. Invalid span contexts should also not be added as a parent. This eliminates redundant error handling logic in exporters. """ - tracer = trace.Tracer("test_create_span_invalid_spancontext") + tracer = trace.Tracer("test_start_span_invalid_spancontext") new_span = tracer.start_span( "root", parent=trace_api.INVALID_SPAN_CONTEXT ) From 371fa89ced8df439f2f9cc378102e727f6640932 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Fri, 22 Nov 2019 17:28:42 -0800 Subject: [PATCH 7/7] 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 eedc8d59988..662cea752a8 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 dfb9dee885c..d03e7604a81 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 d9cc9ff6a92..fba6a8cda2d 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 344844a8aca..97c93880e47 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)