File: test_threading.py

package info (click to toggle)
python-azure 20230112%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 749,544 kB
  • sloc: python: 6,815,827; javascript: 287; makefile: 195; xml: 109; sh: 105
file content (26 lines) | stat: -rw-r--r-- 731 bytes parent folder | download | duplicates (2)
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
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import threading

from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan


def test_get_span_from_thread(tracer):

    result = []
    def get_span_from_thread(output):
        current_span = OpenTelemetrySpan.get_current_span()
        output.append(current_span)

    with tracer.start_as_current_span(name="TestSpan") as span:

        thread = threading.Thread(
            target=OpenTelemetrySpan.with_current_context(get_span_from_thread),
            args=(result,)
        )
        thread.start()
        thread.join()

        assert span is result[0]