Skip to content

Commit 41a81f8

Browse files
Merge pull request #237484 from jeremydvoss/python-docs
Python docs update
2 parents 811cb83 + fb08b57 commit 41a81f8

File tree

2 files changed

+54
-36
lines changed

2 files changed

+54
-36
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,23 @@ Use one of the following two ways to configure the connection string:
8383

8484
### [Python](#tab/python)
8585

86-
Currently unavailable.
86+
Use one of the following two ways to configure the connection string:
87+
88+
- Set an environment variable:
89+
90+
```console
91+
APPLICATIONINSIGHTS_CONNECTION_STRING=<Your Connection String>
92+
```
93+
94+
- Pass into `configure_azure_monitor`:
95+
96+
```python
97+
from azure.monitor.opentelemetry import configure_azure_monitor
98+
99+
configure_azure_monitor(
100+
connection_string="<your-connection-string>",
101+
)
102+
```
87103

88104
---
89105

@@ -264,7 +280,12 @@ const appInsights = new ApplicationInsightsClient(config);
264280
#### [Python](#tab/python)
265281

266282
```python
267-
Currently unavailable.
283+
from azure.identity import ManagedIdentityCredential
284+
from azure.monitor.opentelemetry import configure_azure_monitor
285+
286+
configure_azure_monitor(
287+
credential=ManagedIdentityCredential(),
288+
)
268289
```
269290

270291
---

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

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,8 @@ const appInsights = new ApplicationInsightsClient(config);
171171

172172
```python
173173
from azure.monitor.opentelemetry import configure_azure_monitor
174-
from opentelemetry import trace
175-
176-
configure_azure_monitor(
177-
connection_string="<Your Connection String>",
178-
)
179-
180-
tracer = trace.get_tracer(__name__)
181-
182-
with tracer.start_as_current_span("hello"):
183-
print("Hello, World!")
184-
185-
input()
186174

175+
configure_azure_monitor()
187176
```
188177

189178
---
@@ -463,7 +452,29 @@ Other OpenTelemetry Instrumentations are available [here](https://github.com/ope
463452
```
464453

465454
### [Python](#tab/python)
466-
Currently unavailable.
455+
456+
Other OpenTelemetry Instrumentations are available [here](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation) and can be used in addition to `configure_azure_monitor`. Here is an example for adding the SQLAlchemy Instrumentation.
457+
458+
```python
459+
from azure.monitor.opentelemetry import configure_azure_monitor
460+
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
461+
from sqlalchemy import create_engine, text
462+
463+
configure_azure_monitor()
464+
465+
engine = create_engine("sqlite:///:memory:")
466+
# SQLAlchemy instrumentation is not officially supported by this package
467+
# However, you can use the OpenTelemetry instument method manually in
468+
# conjunction with configure_azure_monitor
469+
SQLAlchemyInstrumentor().instrument(
470+
engine=engine,
471+
)
472+
473+
# Database calls using the SqlAlchemy library will be automatically captured
474+
with engine.connect() as conn:
475+
result = conn.execute(text("select 'hello world'"))
476+
print(result.all())
477+
```
467478

468479
---
469480

@@ -603,9 +614,7 @@ public class Program {
603614
from azure.monitor.opentelemetry import configure_azure_monitor
604615
from opentelemetry import metrics
605616

606-
configure_azure_monitor(
607-
connection_string="<your-connection-string>",
608-
)
617+
configure_azure_monitor()
609618
meter = metrics.get_meter_provider().get_meter("otel_azure_monitor_histogram_demo")
610619

611620
histogram = meter.create_histogram("histogram")
@@ -696,9 +705,7 @@ public class Program {
696705
from azure.monitor.opentelemetry import configure_azure_monitor
697706
from opentelemetry import metrics
698707

699-
configure_azure_monitor(
700-
connection_string="<your-connection-string>",
701-
)
708+
configure_azure_monitor()
702709
meter = metrics.get_meter_provider().get_meter("otel_azure_monitor_counter_demo")
703710

704711
counter = meter.create_counter("counter")
@@ -791,9 +798,7 @@ from azure.monitor.opentelemetry import configure_azure_monitor
791798
from opentelemetry import metrics
792799
from opentelemetry.metrics import CallbackOptions, Observation
793800

794-
configure_azure_monitor(
795-
connection_string="<your-connection-string>",
796-
)
801+
configure_azure_monitor()
797802
meter = metrics.get_meter_provider().get_meter("otel_azure_monitor_gauge_demo")
798803

799804
def observable_gauge_generator(options: CallbackOptions) -> Iterable[Observation]:
@@ -888,9 +893,7 @@ The OpenTelemetry Python SDK is implemented in such a way that exceptions thrown
888893
from azure.monitor.opentelemetry import configure_azure_monitor
889894
from opentelemetry import trace
890895

891-
configure_azure_monitor(
892-
connection_string="<your-connection-string>",
893-
)
896+
configure_azure_monitor()
894897
tracer = trace.get_tracer("otel_azure_monitor_exception_demo")
895898

896899
# Exception events
@@ -1373,9 +1376,7 @@ Use a custom processor:
13731376
from azure.monitor.opentelemetry import configure_azure_monitor
13741377
from opentelemetry import trace
13751378
1376-
configure_azure_monitor(
1377-
connection_string="<your-connection-string>",
1378-
)
1379+
configure_azure_monitor()
13791380
span_enrich_processor = SpanEnrichingProcessor()
13801381
# Add the processor shown below to the current `TracerProvider`
13811382
trace.get_tracer_provider().add_span_processor(span_enrich_processor)
@@ -1655,9 +1656,7 @@ Use the add [custom property example](#add-a-custom-property-to-a-span), but rep
16551656
from azure.monitor.opentelemetry import configure_azure_monitor
16561657
16571658
# Configure Azure monitor collection telemetry pipeline
1658-
configure_azure_monitor(
1659-
connection_string="<your-connection-string>",
1660-
)
1659+
configure_azure_monitor()
16611660
app = flask.Flask(__name__)
16621661
16631662
# Requests sent to this endpoint will not be tracked due to
@@ -1675,9 +1674,7 @@ Use the add [custom property example](#add-a-custom-property-to-a-span), but rep
16751674
from azure.monitor.opentelemetry import configure_azure_monitor
16761675
from opentelemetry import trace
16771676
1678-
configure_azure_monitor(
1679-
connection_string="<your-connection-string>",
1680-
)
1677+
configure_azure_monitor()
16811678
trace.get_tracer_provider().add_span_processor(SpanFilteringProcessor())
16821679
...
16831680
```

0 commit comments

Comments
 (0)