15
15
from ._version import VERSION
16
16
17
17
try :
18
- from typing import TYPE_CHECKING
18
+ from typing import TYPE_CHECKING , ContextManager
19
19
except ImportError :
20
20
TYPE_CHECKING = False
21
21
22
22
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
24
24
25
25
from azure .core .pipeline .transport import HttpRequest , HttpResponse
26
26
AttributeValue = Union [
@@ -47,7 +47,7 @@ def _get_headers_from_http_request_headers(headers: "Mapping[str, Any]", key: st
47
47
return [headers .get (key , "" )]
48
48
49
49
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 ):
51
51
"""Set headers in the given headers dict.
52
52
53
53
Must comply to opentelemetry.context.propagation.httptextformat.Setter:
@@ -80,12 +80,12 @@ def span_instance(self):
80
80
return self ._span_instance
81
81
82
82
def span (self , name = "span" ):
83
- # type: (Optional[str]) -> OpenCensusSpan
83
+ # type: (Optional[str]) -> OpenTelemetrySpan
84
84
"""
85
85
Create a child span for the current span and append it to the child spans list in the span instance.
86
86
:param name: Name of the child span
87
87
: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
89
89
"""
90
90
return self .__class__ (name = name )
91
91
@@ -123,7 +123,6 @@ def kind(self, value):
123
123
124
124
def __enter__ (self ):
125
125
"""Start a span."""
126
- self .start ()
127
126
self ._current_ctxt_manager = self .get_current_tracer ().use_span (self ._span_instance , end_on_exit = True )
128
127
self ._current_ctxt_manager .__enter__ ()
129
128
return self
@@ -135,9 +134,8 @@ def __exit__(self, exception_type, exception_value, traceback):
135
134
self ._current_ctxt_manager = None
136
135
137
136
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
141
139
142
140
def finish (self ):
143
141
# type: () -> None
@@ -167,6 +165,7 @@ def add_attribute(self, key, value):
167
165
self .span_instance .set_attribute (key , value )
168
166
169
167
def get_trace_parent (self ):
168
+ # type: () -> str
170
169
"""Return traceparent string as defined in W3C trace context specification.
171
170
172
171
Example:
0 commit comments