diff --git a/packages/authentication/azure/kiota_authentication_azure/azure_identity_access_token_provider.py b/packages/authentication/azure/kiota_authentication_azure/azure_identity_access_token_provider.py index d116f29e..e03b03d7 100644 --- a/packages/authentication/azure/kiota_authentication_azure/azure_identity_access_token_provider.py +++ b/packages/authentication/azure/kiota_authentication_azure/azure_identity_access_token_provider.py @@ -1,6 +1,5 @@ import base64 import inspect -from pickle import TRUE from typing import Any, Optional, Union from urllib.parse import urlparse @@ -85,7 +84,7 @@ async def get_authorization_token( span.record_exception(exc) raise exc - span.set_attribute(self.IS_VALID_URL, TRUE) + span.set_attribute(self.IS_VALID_URL, True) decoded_claim = None if all( diff --git a/packages/authentication/azure/tests/test_azure_identity_access_token_provider.py b/packages/authentication/azure/tests/test_azure_identity_access_token_provider.py index c4c219fa..512707b5 100644 --- a/packages/authentication/azure/tests/test_azure_identity_access_token_provider.py +++ b/packages/authentication/azure/tests/test_azure_identity_access_token_provider.py @@ -2,6 +2,9 @@ import pytest from kiota_abstractions.authentication import AllowedHostsValidator +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import SimpleSpanProcessor +from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter from kiota_authentication_azure.azure_identity_access_token_provider import ( AzureIdentityAccessTokenProvider, @@ -109,6 +112,21 @@ async def test_get_authorization_token_sync(): assert token == "This is a dummy token" +@pytest.mark.asyncio +async def test_get_authorization_token_marks_valid_url_span_attribute_true(monkeypatch): + exporter = InMemorySpanExporter() + provider = TracerProvider() + provider.add_span_processor(SimpleSpanProcessor(exporter)) + monkeypatch.setattr( + "kiota_authentication_azure.azure_identity_access_token_provider.tracer", + provider.get_tracer(__name__) + ) + token_provider = AzureIdentityAccessTokenProvider(DummySyncAzureTokenCredential(), None) + await token_provider.get_authorization_token('https://graph.microsoft.com') + [span] = exporter.get_finished_spans() + assert span.attributes[AzureIdentityAccessTokenProvider.IS_VALID_URL] is True + + @pytest.mark.asyncio async def test_get_authorization_token_invalid_url():