@@ -627,20 +627,60 @@ useAzureMonitor(options);
627
627
628
628
### [Python](#tab/python)
629
629
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 `
630
640
```python
631
641
# Import the `ManagedIdentityCredential` class from the `azure.identity` package.
632
642
from azure .identity import ManagedIdentityCredential
633
643
# Import the `configure_azure_monitor()` function from the `azure.monitor.opentelemetry` package.
634
644
from azure .monitor .opentelemetry import configure_azure_monitor
645
+ from opentelemetry import trace
635
646
636
647
# Configure the Distro to authenticate with Azure Monitor using a managed identity credential.
648
+ credential = ManagedIdentityCredential (client_id = " <client_id>" )
637
649
configure_azure_monitor (
638
650
connection_string = " your-connection-string" ,
639
- credential = ManagedIdentityCredential () ,
651
+ credential = credential ,
640
652
)
641
653
654
+ tracer = trace .get_tracer (__name__ )
655
+
656
+ with tracer .start_as_current_span (" hello with aad managed identity" ):
657
+ print (" Hello, World!" )
658
+
642
659
```
643
660
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
+ ```
644
684
-- -
645
685
646
686
## Offline Storage and Automatic Retries
0 commit comments