|
| 1 | +# ------------------------------------ |
| 2 | +# Copyright (c) Microsoft Corporation. |
| 3 | +# Licensed under the MIT License. |
| 4 | +# ------------------------------------ |
| 5 | +import pytest |
| 6 | + |
| 7 | +from azure.storage.blob import BlobServiceClient |
| 8 | +from opentelemetry.trace import SpanKind |
| 9 | +from opentelemetry.sdk.trace import ReadableSpan |
| 10 | + |
| 11 | + |
| 12 | +class TestStorageTracing: |
| 13 | + @pytest.mark.live_test_only |
| 14 | + def test_blob_service_client_tracing(self, config, exporter, tracer): |
| 15 | + connection_string = config["storage_connection_string"] |
| 16 | + client = BlobServiceClient.from_connection_string(connection_string) |
| 17 | + |
| 18 | + with tracer.start_as_current_span(name="root") as parent: |
| 19 | + client.get_service_properties() |
| 20 | + |
| 21 | + spans = exporter.get_finished_spans() |
| 22 | + |
| 23 | + # We expect 3 spans, one for the root span, one for the method call, and one for the HTTP request. |
| 24 | + assert len(spans) == 3 |
| 25 | + span_names_list = [span.name for span in spans] |
| 26 | + assert span_names_list == ["/", "BlobServiceClient.get_service_properties", "root"] |
| 27 | + |
| 28 | + http_span: ReadableSpan = spans[0] |
| 29 | + assert http_span.kind == SpanKind.CLIENT |
| 30 | + assert http_span.parent.span_id == spans[1].context.span_id |
| 31 | + |
| 32 | + method_span: ReadableSpan = spans[1] |
| 33 | + assert method_span.kind == SpanKind.INTERNAL |
| 34 | + assert method_span.parent.span_id == spans[2].context.span_id |
0 commit comments