@@ -627,23 +627,58 @@ useAzureMonitor(options);
627
627
628
628
### [Python](#tab/python)
629
629
630
- We support the credential classes provided by [Azure Identity ](https :// github.com/Azure/azure-sdk-for-net /tree/main /sdk/identity/Azure.Identity #credential-classes).
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
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 `
632
640
```python
633
- # Import the `ManagedIdentityCredential` class from the `azure.identity` package.
641
+ import os
642
+ # You will need to install azure-identity
634
643
from azure .identity import ManagedIdentityCredential
635
- # Import the `configure_azure_monitor()` function from the `azure.monitor.opentelemetry` package.
636
644
from azure .monitor .opentelemetry import configure_azure_monitor
645
+ from opentelemetry import trace
637
646
638
- # Configure the Distro to authenticate with Azure Monitor using a managed identity credential.
647
+ credential = ManagedIdentityCredential ( client_id = " <client_id> " )
639
648
configure_azure_monitor (
640
- connection_string = " your-connection-string " ,
641
- credential = ManagedIdentityCredential () ,
649
+ connection_string = os . environ [ " APPLICATIONINSIGHTS_CONNECTION_STRING " ] ,
650
+ credential = credential ,
642
651
)
643
652
653
+ tracer = trace .get_tracer (__name__ )
654
+
655
+ with tracer .start_as_current_span (" hello with aad managed identity" ):
656
+ print (" Hello, World!" )
657
+
644
658
```
645
- You can find more details [here ](./ azure - ad - authentication ? tabs = python ).
646
659
660
+ If using `ClientSecretCredential `
661
+ ```python
662
+ import os
663
+ # You will need to install azure-identity
664
+ from azure .identity import ClientSecretCredential
665
+ from azure .monitor .opentelemetry import configure_azure_monitor
666
+ from opentelemetry import trace
667
+
668
+ credential = ClientSecretCredential (
669
+ tenant_id = " <tenant_id" ,
670
+ client_id = " <client_id>" ,
671
+ client_secret = " <client_secret>" ,
672
+ )
673
+ configure_azure_monitor (
674
+ connection_string = os .environ [" APPLICATIONINSIGHTS_CONNECTION_STRING" ],
675
+ credential = credential ,
676
+ )
677
+
678
+ with tracer .start_as_current_span (" hello with aad client identity" ):
679
+ print (" Hello, World!" )
680
+
681
+ ```
647
682
-- -
648
683
649
684
## Offline Storage and Automatic Retries
0 commit comments