diff --git a/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md b/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md index 747df77eb172..8b830841cc34 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md @@ -10,6 +10,9 @@ ### Other Changes +- Added AAD auth samples to distro + ([#37352](https://github.com/Azure/azure-sdk-for-python/pull/37352)) + ## 1.6.2 (2024-09-05) ### Bugs Fixed diff --git a/sdk/monitor/azure-monitor-opentelemetry/samples/authentication/sample_managed_credential.py b/sdk/monitor/azure-monitor-opentelemetry/samples/authentication/sample_managed_credential.py new file mode 100644 index 000000000000..dd8d8106e216 --- /dev/null +++ b/sdk/monitor/azure-monitor-opentelemetry/samples/authentication/sample_managed_credential.py @@ -0,0 +1,23 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +""" +An example to show an application using Opentelemetry tracing api and sdk with a Azure Managed Identity +Credential. Credentials are used for Azure Active Directory/EntraId Authentication. +""" +# You will need to install azure-identity +from azure.identity import ManagedIdentityCredential +from azure.monitor.opentelemetry import configure_azure_monitor +from opentelemetry import trace + + +credential = ManagedIdentityCredential(client_id="") +configure_azure_monitor( + credential=credential, +) + +tracer = trace.get_tracer(__name__) + +with tracer.start_as_current_span("hello with aad managed identity"): + print("Hello, World!") + +input() diff --git a/sdk/monitor/azure-monitor-opentelemetry/samples/authentication/sample_secret_credential.py b/sdk/monitor/azure-monitor-opentelemetry/samples/authentication/sample_secret_credential.py new file mode 100644 index 000000000000..8e3d5aea3973 --- /dev/null +++ b/sdk/monitor/azure-monitor-opentelemetry/samples/authentication/sample_secret_credential.py @@ -0,0 +1,26 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +""" +An example to show an application using Opentelemetry tracing api and sdk with a Azure Client Secret +Credential. Credentials are used for Azure Active Directory/EntraId Authentication. +""" +# You will need to install azure-identity +from azure.identity import ClientSecretCredential +from azure.monitor.opentelemetry import configure_azure_monitor +from opentelemetry import trace + +credential = ClientSecretCredential( + tenant_id="