Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get rid of should only propagate #6497

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ def on_request(self, request):
if parent_span is None:
return

only_propagate = settings.tracing_should_only_propagate()
if only_propagate:
self.set_header(request, parent_span)
return

path = urlparse(request.http_request.url).path
if not path:
path = "/"
Expand All @@ -96,8 +91,7 @@ def end_span(self, request, response=None):
# type: (HttpRequest, Optional[HttpResponse]) -> None
"""Ends the span that is tracing the network and updates its status."""
span = tracing_context.current_span.get() # type: AbstractSpan
only_propagate = settings.tracing_should_only_propagate()
if span and not only_propagate:
if span is not None:
span.set_http_attributes(request, response=response)
request_id = request.headers.get(self._request_id)
if request_id is not None:
Expand Down
4 changes: 0 additions & 4 deletions sdk/core/azure-core/azure/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,5 @@ def _config(self, props): # pylint: disable=no-self-use
"tracing_implementation", env_var="AZURE_SDK_TRACING_IMPLEMENTATION", convert=convert_tracing_impl, default=None
)

tracing_should_only_propagate = PrioritizedSetting(
"tracing_should_only_propagate", env_var="AZURE_TRACING_ONLY_PROPAGATE", convert=convert_bool, default=False
)


settings = Settings()
7 changes: 0 additions & 7 deletions sdk/core/azure-core/azure/core/tracing/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,3 @@ def get_parent_span(parent_span):
)

return parent_span


def should_use_trace(parent_span):
# type: (AbstractSpan) -> bool
"""Given Parent Span Returns whether the function should be traced"""
only_propagate = settings.tracing_should_only_propagate()
return bool(parent_span and not only_propagate)
2 changes: 1 addition & 1 deletion sdk/core/azure-core/azure/core/tracing/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def wrapper_use_tracer(self, *args, **kwargs):
original_span_instance = wrapper_class.get_current_span()
parent_span = common.get_parent_span(passed_in_parent)
ans = None
if common.should_use_trace(parent_span):
if parent_span is not None:
common.set_span_contexts(parent_span)
name = name_of_span or self.__class__.__name__ + "." + func.__name__
child = parent_span.span(name=name)
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/azure/core/tracing/decorator_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def wrapper_use_tracer(self, *args, **kwargs):
original_span_instance = wrapper_class.get_current_span()
parent_span = common.get_parent_span(passed_in_parent)
ans = None
if common.should_use_trace(parent_span):
if parent_span is not None:
common.set_span_contexts(parent_span)
name = name_of_span or self.__class__.__name__ + "." + func.__name__
child = parent_span.span(name=name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,3 @@ async def test_span_with_opencensus_complicated(value):
assert parent.children[3].children[1].span_data.name == "MockClient.make_request"
children = parent.children[1].children
assert len(children) == 2


@pytest.mark.asyncio
async def test_should_only_propagate():
with ContextHelper(should_only_propagate=True):
exporter = MockExporter()
trace = tracer_module.Tracer(sampler=AlwaysOnSampler(), exporter=exporter)
with trace.start_span(name="OverAll") as parent:
client = MockClient()
await client.make_request(2)
with trace.span("child") as child:
await client.make_request(2, parent_span=parent)
assert OpenCensusSpan.get_current_span() == child
await client.make_request(2)
trace.finish()
exporter.build_tree()
parent = exporter.root
assert len(parent.children) == 1
assert parent.children[0].span_data.name == "child"
assert not parent.children[0].children
6 changes: 2 additions & 4 deletions sdk/core/azure-core/tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,18 @@ def test_defaults(self):
val = m.settings.defaults
# assert isinstance(val, tuple)
defaults = m.settings.config(
log_level=20, tracing_enabled=False, tracing_implementation=None, tracing_should_only_propagate=False
log_level=20, tracing_enabled=False, tracing_implementation=None
)
assert val.log_level == defaults.log_level
assert val.tracing_enabled == defaults.tracing_enabled
assert val.tracing_implementation == defaults.tracing_implementation
assert val.tracing_should_only_propagate == defaults.tracing_should_only_propagate
os.environ["AZURE_LOG_LEVEL"] = "debug"
defaults = m.settings.config(
log_level=20, tracing_enabled=False, tracing_implementation=None, tracing_should_only_propagate=False
log_level=20, tracing_enabled=False, tracing_implementation=None
)
assert val.log_level == defaults.log_level
assert val.tracing_enabled == defaults.tracing_enabled
assert val.tracing_implementation == defaults.tracing_implementation
assert val.tracing_should_only_propagate == defaults.tracing_should_only_propagate
del os.environ["AZURE_LOG_LEVEL"]

def test_current(self):
Expand Down
27 changes: 0 additions & 27 deletions sdk/core/azure-core/tests/test_tracing_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,6 @@ def test_get_parent_span(self):
should_be_old_parent = common.get_parent_span(parent.span_instance)
assert should_be_old_parent.span_instance == parent.span_instance

def test_should_use_trace(self):
with ContextHelper(environ={"AZURE_TRACING_ONLY_PROPAGATE": "yes"}):
parent_span = OpenCensusSpan()
assert not common.should_use_trace(parent_span)
assert not common.should_use_trace(None)
parent_span = OpenCensusSpan()
assert common.should_use_trace(parent_span)
assert not common.should_use_trace(None)


class TestDecorator(object):
def test_decorator_has_different_name(self):
Expand Down Expand Up @@ -190,21 +181,3 @@ def test_span_with_opencensus_complicated(self, value):
assert parent.children[3].children[1].span_data.name == "MockClient.make_request"
children = parent.children[1].children
assert len(children) == 2

def test_should_only_propagate(self):
with ContextHelper(should_only_propagate=True):
exporter = MockExporter()
trace = tracer_module.Tracer(sampler=AlwaysOnSampler(), exporter=exporter)
with trace.start_span(name="OverAll") as parent:
client = MockClient()
client.make_request(2)
with trace.span("child") as child:
client.make_request(2, parent_span=parent)
assert OpenCensusSpan.get_current_span() == child
client.make_request(2)
trace.finish()
exporter.build_tree()
parent = exporter.root
assert len(parent.children) == 1
assert parent.children[0].span_data.name == "child"
assert not parent.children[0].children
6 changes: 4 additions & 2 deletions sdk/core/azure-core/tests/test_tracing_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ def test_distributed_tracing_policy_solo(should_set_sdk_context):
assert network_span.span_data.attributes.get("http.status_code") == 504


def test_distributed_tracing_policy_with_user_agent():
@pytest.mark.parametrize("should_set_sdk_context", [True, False])
def test_distributed_tracing_policy_with_user_agent(should_set_sdk_context):
"""Test policy working with user agent."""
with ContextHelper(environ={"AZURE_HTTP_USER_AGENT": "mytools"}):
exporter = MockExporter()
trace = tracer_module.Tracer(sampler=AlwaysOnSampler(), exporter=exporter)
with trace.span("parent"):
tracing_context.current_span.set(OpenCensusSpan(trace.current_span()))
if should_set_sdk_context:
tracing_context.current_span.set(OpenCensusSpan(trace.current_span()))
policy = DistributedTracingPolicy()

request = HttpRequest("GET", "http://127.0.0.1")
Expand Down
6 changes: 1 addition & 5 deletions sdk/core/azure-core/tests/tracing_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@


class ContextHelper(object):
def __init__(self, environ={}, tracer_to_use=None, should_only_propagate=None):
def __init__(self, environ={}, tracer_to_use=None):
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()
self.os_env = mock.patch.dict(os.environ, environ)
self.tracer_to_use = tracer_to_use
self.should_only_propagate = should_only_propagate

def __enter__(self):
self.orig_tracer = OpenCensusSpan.get_current_tracer()
Expand All @@ -38,8 +37,6 @@ def __enter__(self):
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:
settings.tracing_should_only_propagate.set_value(self.should_only_propagate)
self.os_env.start()
execution_context.clear()
tracing_context.current_span.clear()
Expand All @@ -50,7 +47,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):
OpenCensusSpan.set_current_span(self.orig_current_span)
tracing_context.current_span.set(self.orig_sdk_context_span)
settings.tracing_implementation.unset_value()
settings.tracing_should_only_propagate.unset_value()
self.os_env.stop()


Expand Down