Skip to content

Commit 95ad7b2

Browse files
authored
[Otel Plugin][CI] Add preliminary live test files. (#34115)
This adds a tests.yml file and a test-resources.bicep file which can be used in a soon to be setup live test pipeline. Signed-off-by: Paul Van Eck <[email protected]>
1 parent 8360566 commit 95ad7b2

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

sdk/core/azure-core-tracing-opentelemetry/dev_requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
opentelemetry-sdk<2.0.0,>=1.12.0
55
opentelemetry-instrumentation-requests>=0.32b0
66
requests
7+
azure-storage-blob
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@description('The base resource name.')
2+
param baseName string = resourceGroup().name
3+
4+
@description('Which Azure Region to deploy the resource to. Defaults to the resource group location.')
5+
param location string = resourceGroup().location
6+
7+
@description('The client OID to grant access to test resources.')
8+
param testApplicationOid string
9+
10+
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
11+
name: '${baseName}storage'
12+
location: location
13+
kind: 'StorageV2'
14+
sku: {
15+
name: 'Standard_LRS'
16+
}
17+
properties: {
18+
accessTier: 'Hot'
19+
}
20+
}
21+
22+
var name = storageAccount.name
23+
var key = storageAccount.listKeys().keys[0].value
24+
var connectionString = 'DefaultEndpointsProtocol=https;AccountName=${name};AccountKey=${key}'
25+
26+
output AZURE_STORAGE_ACCOUNT_NAME string = name
27+
output AZURE_STORAGE_ACCOUNT_KEY string = key
28+
output AZURE_STORAGE_CONNECTION_STRING string = connectionString
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trigger: none
2+
3+
stages:
4+
- template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml
5+
parameters:
6+
ServiceDirectory: core
7+
BuildTargetingString: 'azure-core-tracing-opentelemetry'
8+
EnvVars:
9+
AZURE_SKIP_LIVE_RECORDING: 'true'
10+
AZURE_TEST_RUN_LIVE: 'true'
11+
TestResourceDirectories:
12+
- core/azure-core-tracing-opentelemetry/

sdk/core/azure-core-tracing-opentelemetry/tests/conftest.py

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
import os
6+
57
from opentelemetry import trace
68
from opentelemetry.sdk.trace import TracerProvider
79
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
@@ -27,3 +29,12 @@ def tracer():
2729
def exporter():
2830
span_exporter.clear()
2931
return span_exporter
32+
33+
34+
@pytest.fixture(scope="session")
35+
def config():
36+
return {
37+
"storage_account_name": os.environ["AZURE_STORAGE_ACCOUNT_NAME"],
38+
"storage_account_key": os.environ["AZURE_STORAGE_ACCOUNT_KEY"],
39+
"storage_connection_string": os.environ["AZURE_STORAGE_CONNECTION_STRING"],
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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

Comments
 (0)