Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions sdk/core/azure-core/azure/core/tracing/ext/opencensus_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
TYPE_CHECKING = False

if TYPE_CHECKING:
from typing import Dict, Optional, Union, TypeVar
from typing import Dict, Optional, Union

from azure.core.pipeline.transport import HttpRequest, HttpResponse

Expand Down Expand Up @@ -83,7 +83,10 @@ def to_header(self):
temp_headers = {}
if tracer_from_context is not None:
ctx = tracer_from_context.span_context
temp_headers = tracer_from_context.propagator.to_headers(ctx)
try:
temp_headers = tracer_from_context.propagator.to_headers(ctx)
except AttributeError:
pass
return temp_headers

def add_attribute(self, key, value):
Expand Down
1 change: 1 addition & 0 deletions sdk/core/azure-core/tests/test_tracing_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, environ={}, tracer_to_use=None):

def __enter__(self):
self.orig_sdk_context_span = tracing_context.current_span.get()
tracing_context.current_span.clear()
settings.tracing_implementation.set_value(self.tracer_to_use)
self.os_env.start()
return self
Expand Down
8 changes: 4 additions & 4 deletions sdk/core/azure-core/tests/tracing_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from opencensus.trace.samplers import AlwaysOnSampler
from opencensus.trace.base_exporter import Exporter
from collections import defaultdict
from opencensus.trace import execution_context

try:
from unittest import mock
Expand All @@ -39,6 +40,8 @@ def __enter__(self):
self.orig_tracer = OpenCensusSpan.get_current_tracer()
self.orig_current_span = OpenCensusSpan.get_current_span()
self.orig_sdk_context_span = tracing_context.current_span.get()
execution_context.clear()
tracing_context.current_span.clear()
if self.tracer_to_use is not None:
settings.tracing_implementation.set_value(self.tracer_to_use)
if self.should_only_propagate is not None:
Expand Down Expand Up @@ -81,7 +84,4 @@ def export(self, span_datas):
def build_tree(self):
for node in self._all_nodes:
if node.span_data.span_id in self.parent_dict:
node.children = sorted(
self.parent_dict[node.span_data.span_id],
key=lambda x: x.span_data.start_time,
)
node.children = sorted(self.parent_dict[node.span_data.span_id], key=lambda x: x.span_data.start_time)