1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import threading
from opencensus.trace import Span, execution_context
from opencensus.trace.tracer import Tracer
from opencensus.trace.samplers import AlwaysOnSampler
from azure.core.tracing.ext.opencensus_span import OpenCensusSpan
def test_get_span_from_thread():
result = []
def get_span_from_thread(output):
current_span = OpenCensusSpan.get_current_span()
output.append(current_span)
tracer = Tracer(sampler=AlwaysOnSampler())
with tracer.span(name="TestSpan") as span:
thread = threading.Thread(
target=get_span_from_thread,
args=(result,)
)
thread.start()
thread.join()
assert span is result[0]
execution_context.clear()
|