From 537a145af8c34cbdfdfc88354e4bbc81e73c1411 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 1 Jun 2020 13:47:43 -0700 Subject: [PATCH] 'DefaultSpan' object has no attribute 'start' (#11728) * 'DefaultSpan' object has no attribute 'start' * Apply suggestions from code review --- .../tracing/ext/opentelemetry_span/__init__.py | 17 ++++++++--------- .../azure/core/tracing/_abstract_span.py | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py b/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py index 151656067053..2ba42245725f 100644 --- a/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py +++ b/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py @@ -15,12 +15,12 @@ from ._version import VERSION try: - from typing import TYPE_CHECKING + from typing import TYPE_CHECKING, ContextManager except ImportError: TYPE_CHECKING = False if TYPE_CHECKING: - from typing import Any, Mapping, Dict, Optional, Union, Callable, Sequence + from typing import Any, Mapping, MutableMapping, Dict, Optional, Union, Callable, Sequence from azure.core.pipeline.transport import HttpRequest, HttpResponse AttributeValue = Union[ @@ -47,7 +47,7 @@ def _get_headers_from_http_request_headers(headers: "Mapping[str, Any]", key: st return [headers.get(key, "")] -def _set_headers_from_http_request_headers(headers: "Mapping[str, Any]", key: str, value: str): +def _set_headers_from_http_request_headers(headers: "MutableMapping[str, Any]", key: str, value: str): """Set headers in the given headers dict. Must comply to opentelemetry.context.propagation.httptextformat.Setter: @@ -80,12 +80,12 @@ def span_instance(self): return self._span_instance def span(self, name="span"): - # type: (Optional[str]) -> OpenCensusSpan + # type: (Optional[str]) -> OpenTelemetrySpan """ Create a child span for the current span and append it to the child spans list in the span instance. :param name: Name of the child span :type name: str - :return: The OpenCensusSpan that is wrapping the child span instance + :return: The OpenTelemetrySpan that is wrapping the child span instance """ return self.__class__(name=name) @@ -123,7 +123,6 @@ def kind(self, value): def __enter__(self): """Start a span.""" - self.start() self._current_ctxt_manager = self.get_current_tracer().use_span(self._span_instance, end_on_exit=True) self._current_ctxt_manager.__enter__() return self @@ -135,9 +134,8 @@ def __exit__(self, exception_type, exception_value, traceback): self._current_ctxt_manager = None def start(self): - # type: () -> None - """Set the start time for a span.""" - self.span_instance.start() + # Spans are automatically started at their creation with OpenTelemetry + pass def finish(self): # type: () -> None @@ -167,6 +165,7 @@ def add_attribute(self, key, value): self.span_instance.set_attribute(key, value) def get_trace_parent(self): + # type: () -> str """Return traceparent string as defined in W3C trace context specification. Example: diff --git a/sdk/core/azure-core/azure/core/tracing/_abstract_span.py b/sdk/core/azure-core/azure/core/tracing/_abstract_span.py index 89ae3ed64f9d..6b4eb068dcc1 100644 --- a/sdk/core/azure-core/azure/core/tracing/_abstract_span.py +++ b/sdk/core/azure-core/azure/core/tracing/_abstract_span.py @@ -131,7 +131,7 @@ def span_instance(self): @classmethod def link(cls, traceparent, attributes=None): - # type: (Dict[str, str], Attributes) -> None + # type: (str, Attributes) -> None """ Given a traceparent, extracts the context and links the context to the current tracer.