Skip to content

Commit 22208ce

Browse files
authored
Add aad auth samples to distro (#37352)
1 parent 089f850 commit 22208ce

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
### Other Changes
1212

13+
- Added AAD auth samples to distro
14+
([#37352](https://github.com/Azure/azure-sdk-for-python/pull/37352))
15+
1316
## 1.6.2 (2024-09-05)
1417

1518
### Bugs Fixed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
"""
4+
An example to show an application using Opentelemetry tracing api and sdk with a Azure Managed Identity
5+
Credential. Credentials are used for Azure Active Directory/EntraId Authentication.
6+
"""
7+
# You will need to install azure-identity
8+
from azure.identity import ManagedIdentityCredential
9+
from azure.monitor.opentelemetry import configure_azure_monitor
10+
from opentelemetry import trace
11+
12+
13+
credential = ManagedIdentityCredential(client_id="<client_id>")
14+
configure_azure_monitor(
15+
credential=credential,
16+
)
17+
18+
tracer = trace.get_tracer(__name__)
19+
20+
with tracer.start_as_current_span("hello with aad managed identity"):
21+
print("Hello, World!")
22+
23+
input()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
"""
4+
An example to show an application using Opentelemetry tracing api and sdk with a Azure Client Secret
5+
Credential. Credentials are used for Azure Active Directory/EntraId Authentication.
6+
"""
7+
# You will need to install azure-identity
8+
from azure.identity import ClientSecretCredential
9+
from azure.monitor.opentelemetry import configure_azure_monitor
10+
from opentelemetry import trace
11+
12+
credential = ClientSecretCredential(
13+
tenant_id="<tenant_id",
14+
client_id="<client_id>",
15+
client_secret="<client_secret>",
16+
)
17+
configure_azure_monitor(
18+
credential=credential,
19+
)
20+
21+
tracer = trace.get_tracer(__name__)
22+
23+
with tracer.start_as_current_span("hello with aad client secret"):
24+
print("Hello, World!")
25+
26+
input()

0 commit comments

Comments
 (0)