Skip to content

Commit 537a145

Browse files
author
Rakshith Bhyravabhotla
authored
'DefaultSpan' object has no attribute 'start' (Azure#11728)
* 'DefaultSpan' object has no attribute 'start' * Apply suggestions from code review
1 parent f4aee7e commit 537a145

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
from ._version import VERSION
1616

1717
try:
18-
from typing import TYPE_CHECKING
18+
from typing import TYPE_CHECKING, ContextManager
1919
except ImportError:
2020
TYPE_CHECKING = False
2121

2222
if TYPE_CHECKING:
23-
from typing import Any, Mapping, Dict, Optional, Union, Callable, Sequence
23+
from typing import Any, Mapping, MutableMapping, Dict, Optional, Union, Callable, Sequence
2424

2525
from azure.core.pipeline.transport import HttpRequest, HttpResponse
2626
AttributeValue = Union[
@@ -47,7 +47,7 @@ def _get_headers_from_http_request_headers(headers: "Mapping[str, Any]", key: st
4747
return [headers.get(key, "")]
4848

4949

50-
def _set_headers_from_http_request_headers(headers: "Mapping[str, Any]", key: str, value: str):
50+
def _set_headers_from_http_request_headers(headers: "MutableMapping[str, Any]", key: str, value: str):
5151
"""Set headers in the given headers dict.
5252
5353
Must comply to opentelemetry.context.propagation.httptextformat.Setter:
@@ -80,12 +80,12 @@ def span_instance(self):
8080
return self._span_instance
8181

8282
def span(self, name="span"):
83-
# type: (Optional[str]) -> OpenCensusSpan
83+
# type: (Optional[str]) -> OpenTelemetrySpan
8484
"""
8585
Create a child span for the current span and append it to the child spans list in the span instance.
8686
:param name: Name of the child span
8787
:type name: str
88-
:return: The OpenCensusSpan that is wrapping the child span instance
88+
:return: The OpenTelemetrySpan that is wrapping the child span instance
8989
"""
9090
return self.__class__(name=name)
9191

@@ -123,7 +123,6 @@ def kind(self, value):
123123

124124
def __enter__(self):
125125
"""Start a span."""
126-
self.start()
127126
self._current_ctxt_manager = self.get_current_tracer().use_span(self._span_instance, end_on_exit=True)
128127
self._current_ctxt_manager.__enter__()
129128
return self
@@ -135,9 +134,8 @@ def __exit__(self, exception_type, exception_value, traceback):
135134
self._current_ctxt_manager = None
136135

137136
def start(self):
138-
# type: () -> None
139-
"""Set the start time for a span."""
140-
self.span_instance.start()
137+
# Spans are automatically started at their creation with OpenTelemetry
138+
pass
141139

142140
def finish(self):
143141
# type: () -> None
@@ -167,6 +165,7 @@ def add_attribute(self, key, value):
167165
self.span_instance.set_attribute(key, value)
168166

169167
def get_trace_parent(self):
168+
# type: () -> str
170169
"""Return traceparent string as defined in W3C trace context specification.
171170
172171
Example:

sdk/core/azure-core/azure/core/tracing/_abstract_span.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def span_instance(self):
131131

132132
@classmethod
133133
def link(cls, traceparent, attributes=None):
134-
# type: (Dict[str, str], Attributes) -> None
134+
# type: (str, Attributes) -> None
135135
"""
136136
Given a traceparent, extracts the context and links the context to the current tracer.
137137

0 commit comments

Comments
 (0)