Skip to content

Commit 800ca20

Browse files
committed
encourage env var usage, added credential, added community
instrumentation, cleaned up modify section
1 parent ef6e6e3 commit 800ca20

File tree

2 files changed

+52
-30
lines changed

2 files changed

+52
-30
lines changed

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

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

4949
### [Python](#tab/python)
5050

51-
Currently unavailable.
51+
Use one of the following two ways to configure the connection string:
52+
53+
- Set an environment variable:
54+
55+
```console
56+
APPLICATIONINSIGHTS_CONNECTION_STRING=<Your Connection String>
57+
```
58+
59+
- Pass into `configure_azure_monitor`:
60+
61+
```python
62+
from azure.monitor.opentelemetry import configure_azure_monitor
63+
64+
configure_azure_monitor(
65+
connection_string="<your-connection-string>",
66+
)
67+
```
5268

5369
---
5470

@@ -212,7 +228,12 @@ const appInsights = new ApplicationInsightsClient(config);
212228
#### [Python](#tab/python)
213229
214230
```python
215-
Currently unavailable.
231+
from azure.identity import ManagedIdentityCredential
232+
from azure.monitor.opentelemetry import configure_azure_monitor
233+
234+
configure_azure_monitor(
235+
credential=ManagedIdentityCredential(),
236+
)
216237
```
217238
218239
---

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

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,8 @@ const appInsights = new ApplicationInsightsClient(config);
176176

177177
```python
178178
from azure.monitor.opentelemetry import configure_azure_monitor
179-
from opentelemetry import trace
180-
181-
configure_azure_monitor(
182-
connection_string="<Your Connection String>",
183-
)
184-
185-
tracer = trace.get_tracer(__name__)
186-
187-
with tracer.start_as_current_span("hello"):
188-
print("Hello, World!")
189-
190-
input()
191179

180+
configure_azure_monitor()
192181
```
193182

194183
---
@@ -468,7 +457,29 @@ Other OpenTelemetry Instrumentations are available [here](https://github.com/ope
468457
```
469458

470459
### [Python](#tab/python)
471-
Currently unavailable.
460+
461+
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.
462+
463+
```python
464+
from azure.monitor.opentelemetry import configure_azure_monitor
465+
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
466+
from sqlalchemy import create_engine, text
467+
468+
configure_azure_monitor()
469+
470+
engine = create_engine("sqlite:///:memory:")
471+
# SQLAlchemy instrumentation is not officially supported by this package
472+
# However, you can use the OpenTelemetry instument method manually in
473+
# conjunction with configure_azure_monitor
474+
SQLAlchemyInstrumentor().instrument(
475+
engine=engine,
476+
)
477+
478+
# Database calls using the SqlAlchemy library will be automatically captured
479+
with engine.connect() as conn:
480+
result = conn.execute(text("select 'hello world'"))
481+
print(result.all())
482+
```
472483

473484
---
474485

@@ -608,9 +619,7 @@ public class Program {
608619
from azure.monitor.opentelemetry import configure_azure_monitor
609620
from opentelemetry import metrics
610621

611-
configure_azure_monitor(
612-
connection_string="<your-connection-string>",
613-
)
622+
configure_azure_monitor()
614623
meter = metrics.get_meter_provider().get_meter("otel_azure_monitor_histogram_demo")
615624

616625
histogram = meter.create_histogram("histogram")
@@ -701,9 +710,7 @@ public class Program {
701710
from azure.monitor.opentelemetry import configure_azure_monitor
702711
from opentelemetry import metrics
703712

704-
configure_azure_monitor(
705-
connection_string="<your-connection-string>",
706-
)
713+
configure_azure_monitor()
707714
meter = metrics.get_meter_provider().get_meter("otel_azure_monitor_counter_demo")
708715

709716
counter = meter.create_counter("counter")
@@ -835,9 +842,7 @@ from azure.monitor.opentelemetry import configure_azure_monitor
835842
from opentelemetry import metrics
836843
from opentelemetry.metrics import CallbackOptions, Observation
837844

838-
configure_azure_monitor(
839-
connection_string="<your-connection-string>",
840-
)
845+
configure_azure_monitor()
841846
meter = metrics.get_meter_provider().get_meter("otel_azure_monitor_gauge_demo")
842847

843848
def observable_gauge_generator(options: CallbackOptions) -> Iterable[Observation]:
@@ -932,9 +937,7 @@ The OpenTelemetry Python SDK is implemented in such a way that exceptions thrown
932937
from azure.monitor.opentelemetry import configure_azure_monitor
933938
from opentelemetry import trace
934939

935-
configure_azure_monitor(
936-
connection_string="<your-connection-string>",
937-
)
940+
configure_azure_monitor()
938941
tracer = trace.get_tracer("otel_azure_monitor_exception_demo")
939942

940943
# Exception events
@@ -1417,9 +1420,7 @@ Use a custom processor:
14171420
from azure.monitor.opentelemetry import configure_azure_monitor
14181421
from opentelemetry import trace
14191422
1420-
configure_azure_monitor(
1421-
connection_string="<your-connection-string>",
1422-
)
1423+
configure_azure_monitor()
14231424
span_enrich_processor = SpanEnrichingProcessor()
14241425
# Add the processor shown below to the current `TracerProvider`
14251426
trace.get_tracer_provider().add_span_processor(span_enrich_processor)

0 commit comments

Comments
 (0)