Skip to content

Commit 6fafb0f

Browse files
authored
Update opentelemetry-configuration.md
1 parent 7e4b576 commit 6fafb0f

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

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

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -627,23 +627,58 @@ useAzureMonitor(options);
627627

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

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).
631631
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`
632640
```python
633-
# Import the `ManagedIdentityCredential` class from the `azure.identity` package.
641+
import os
642+
# You will need to install azure-identity
634643
from azure.identity import ManagedIdentityCredential
635-
# Import the `configure_azure_monitor()` function from the `azure.monitor.opentelemetry` package.
636644
from azure.monitor.opentelemetry import configure_azure_monitor
645+
from opentelemetry import trace
637646

638-
# Configure the Distro to authenticate with Azure Monitor using a managed identity credential.
647+
credential = ManagedIdentityCredential(client_id="<client_id>")
639648
configure_azure_monitor(
640-
connection_string="your-connection-string",
641-
credential=ManagedIdentityCredential(),
649+
connection_string=os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"],
650+
credential=credential,
642651
)
643652

653+
tracer = trace.get_tracer(__name__)
654+
655+
with tracer.start_as_current_span("hello with aad managed identity"):
656+
print("Hello, World!")
657+
644658
```
645-
You can find more details [here](./azure-ad-authentication?tabs=python).
646659

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+
```
647682
---
648683

649684
## Offline Storage and Automatic Retries

0 commit comments

Comments
 (0)