Skip to content

Commit 1313f79

Browse files
authored
Merge pull request #124031 from lzchen/patch-1
Update AAD for Python sdk
2 parents 0b1ef02 + a297d01 commit 1313f79

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

articles/azure-monitor/app/opentelemetry-configuration.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,20 +627,60 @@ useAzureMonitor(options);
627627

628628
### [Python](#tab/python)
629629

630+
Azure Monitor OpenTelemetry Distro for Python support the credential classes provided by [Azure Identity](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#credential-classes).
631+
632+
- We recommend `DefaultAzureCredential` for local development.
633+
- We recommend `ManagedIdentityCredential` for system-assigned and user-assigned managed identities.
634+
- For system-assigned, use the default constructor without parameters.
635+
- For user-assigned, provide the `client_id` to the constructor.
636+
- We recommend `ClientSecretCredential` for service principals.
637+
- Provide the tenant ID, client ID, and client secret to the constructor.
638+
639+
If using `ManagedIdentityCredential`
630640
```python
631641
# Import the `ManagedIdentityCredential` class from the `azure.identity` package.
632642
from azure.identity import ManagedIdentityCredential
633643
# Import the `configure_azure_monitor()` function from the `azure.monitor.opentelemetry` package.
634644
from azure.monitor.opentelemetry import configure_azure_monitor
645+
from opentelemetry import trace
635646

636647
# Configure the Distro to authenticate with Azure Monitor using a managed identity credential.
648+
credential = ManagedIdentityCredential(client_id="<client_id>")
637649
configure_azure_monitor(
638650
connection_string="your-connection-string",
639-
credential=ManagedIdentityCredential(),
651+
credential=credential,
640652
)
641653

654+
tracer = trace.get_tracer(__name__)
655+
656+
with tracer.start_as_current_span("hello with aad managed identity"):
657+
print("Hello, World!")
658+
642659
```
643660

661+
If using `ClientSecretCredential`
662+
```python
663+
# Import the `ClientSecretCredential` class from the `azure.identity` package.
664+
from azure.identity import ClientSecretCredential
665+
# Import the `configure_azure_monitor()` function from the `azure.monitor.opentelemetry` package.
666+
from azure.monitor.opentelemetry import configure_azure_monitor
667+
from opentelemetry import trace
668+
669+
# Configure the Distro to authenticate with Azure Monitor using a client secret credential.
670+
credential = ClientSecretCredential(
671+
tenant_id="<tenant_id",
672+
client_id="<client_id>",
673+
client_secret="<client_secret>",
674+
)
675+
configure_azure_monitor(
676+
connection_string="your-connection-string",
677+
credential=credential,
678+
)
679+
680+
with tracer.start_as_current_span("hello with aad client secret identity"):
681+
print("Hello, World!")
682+
683+
```
644684
---
645685

646686
## Offline Storage and Automatic Retries

0 commit comments

Comments
 (0)