Skip to content

Commit

Permalink
'DefaultSpan' object has no attribute 'start' (#11728)
Browse files Browse the repository at this point in the history
* 'DefaultSpan' object has no attribute 'start'

* Apply suggestions from code review
  • Loading branch information
rakshith91 committed Jun 1, 2020
1 parent f4aee7e commit 537a145
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/azure/core/tracing/_abstract_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 537a145

Please sign in to comment.