You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto instrumentation of Logs is currently only supported when using `applicationinsights` v3 Beta package. (https://www.npmjs.com/package/applicationinsights/v/beta)
155
+
Automatic instrumentation of Logs is currently only supported when using `applicationinsights` v3 Beta package. (https://www.npmjs.com/package/applicationinsights/v/beta)
@@ -268,21 +269,23 @@ To add a community instrumentation library (not officially supported/included in
268
269
> Instrumenting a [supported instrumentation library](.\opentelemetry-add-modify.md?tabs=python#included-instrumentation-libraries) manually with `instrument()` in conjunction with the distro `configure_azure_monitor()` is not recommended. This is not a supported scenario and you may get undesired behavior for your telemetry.
269
270
270
271
```python
272
+
# Import the `configure_azure_monitor()`, `SQLAlchemyInstrumentor`, `create_engine`, and `text` functions from the appropriate packages.
271
273
from azure.monitor.opentelemetry import configure_azure_monitor
272
274
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
273
275
from sqlalchemy import create_engine, text
274
276
277
+
# Configure OpenTelemetry to use Azure Monitor.
275
278
configure_azure_monitor()
276
279
280
+
# Create a SQLAlchemy engine.
277
281
engine = create_engine("sqlite:///:memory:")
278
-
# SQLAlchemy instrumentation is not officially supported by this package
279
-
# However, you can use the OpenTelemetry instrument() method manually in
280
-
# conjunction with configure_azure_monitor
282
+
283
+
# SQLAlchemy instrumentation is not officially supported by this package, however, you can use the OpenTelemetry `instrument()` method manually in conjunction with `configure_azure_monitor()`.
281
284
SQLAlchemyInstrumentor().instrument(
282
285
engine=engine,
283
286
)
284
287
285
-
# Database calls using the SqlAlchemy library will be automatically captured
288
+
# Database calls using the SQLAlchemy library will be automatically captured.
286
289
with engine.connect() as conn:
287
290
result = conn.execute(text("select 'hello world'"))
288
291
print(result.all())
@@ -489,19 +492,26 @@ public class Program {
489
492
#### [Python](#tab/python)
490
493
491
494
```python
495
+
# Import the `configure_azure_monitor()` and `metrics` functions from the appropriate packages.
492
496
from azure.monitor.opentelemetry import configure_azure_monitor
493
497
from opentelemetry import metrics
494
498
499
+
# Configure OpenTelemetry to use Azure Monitor with the specified connection string.
500
+
# Replace `<your-connection-string>` with the connection string to your Azure Monitor Application Insights resource.
495
501
configure_azure_monitor(
496
502
connection_string="<your-connection-string>",
497
503
)
504
+
505
+
# Get a meter provider and a meter with the name "otel_azure_monitor_histogram_demo".
498
506
meter = metrics.get_meter_provider().get_meter("otel_azure_monitor_histogram_demo")
@@ -966,16 +997,22 @@ You can use `opentelemetry-api` to update the status of a span and record except
966
997
The OpenTelemetry Python SDK is implemented in such a way that exceptions thrown are automatically captured and recorded. See the following code sample for an example of this behavior.
967
998
968
999
```python
1000
+
# Import the necessary packages.
969
1001
from azure.monitor.opentelemetry import configure_azure_monitor
970
1002
from opentelemetry import trace
971
1003
1004
+
# Configure OpenTelemetry to use Azure Monitor with the specified connection string.
1005
+
# Replace `<your-connection-string>` with the connection string to your Azure Monitor Application Insights resource.
with tracer.start_as_current_span("hello") as span:
980
1017
# This exception will be automatically recorded
981
1018
raiseException("Custom exception message.")
@@ -989,8 +1026,10 @@ within the context manager and use `record_exception()` directly as shown in the
989
1026
990
1027
```python
991
1028
...
1029
+
# Start a new span with the name "hello" and disable exception recording.
992
1030
with tracer.start_as_current_span("hello", record_exception=False) as span:
993
1031
try:
1032
+
# Raise an exception.
994
1033
raiseException("Custom exception message.")
995
1034
exceptExceptionas ex:
996
1035
# Manually record exception
@@ -1165,15 +1204,20 @@ The code example shows how to use the `tracer.start_as_current_span()` method to
1165
1204
1166
1205
```python
1167
1206
...
1207
+
# Import the necessary packages.
1168
1208
from opentelemetry import trace
1169
1209
1210
+
# Get a tracer for the current module.
1170
1211
tracer = trace.get_tracer(__name__)
1171
1212
1213
+
# Start a new span with the name "my first span" and make it the current span.
1172
1214
# The "with" context manager starts, makes the span current, and ends the span within it's context
1173
1215
with tracer.start_as_current_span("my first span") as span:
1174
1216
try:
1175
-
# Do stuff within the context of this
1217
+
# Do stuff within the context of this span.
1218
+
# All telemetry generated within this scope will be attributed to this span.
1176
1219
exceptExceptionas ex:
1220
+
# Record the exception on the span.
1177
1221
span.record_exception(ex)
1178
1222
...
1179
1223
@@ -1185,11 +1229,16 @@ If your method represents a background job not already captured by autoinstrumen
1185
1229
1186
1230
```python
1187
1231
...
1232
+
# Import the necessary packages.
1188
1233
from opentelemetry import trace
1189
1234
from opentelemetry.trace import SpanKind
1190
1235
1236
+
# Get a tracer for the current module.
1191
1237
tracer = trace.get_tracer(__name__)
1238
+
1239
+
# Start a new span with the name "my request span" and the kind set to SpanKind.SERVER.
1192
1240
with tracer.start_as_current_span("my request span", kind=SpanKind.SERVER) as span:
1241
+
# Do stuff within the context of this span.
1193
1242
...
1194
1243
```
1195
1244
@@ -1329,7 +1378,7 @@ Not available in .NET.
1329
1378
1330
1379
If you want to add custom events or access the Application Insights API, replace the @azure/monitor-opentelemetry package with the `applicationinsights` [v3 Beta package](https://www.npmjs.com/package/applicationinsights/v/beta). It offers the same methods and interfaces, and all sample code for @azure/monitor-opentelemetry applies to the v3 Beta package.
1331
1380
1332
-
To send custom telemetry with the Application Insights Classic API, use the `applicationinsights` [v3 Beta package](https://www.npmjs.com/package/applicationinsights/v/beta).
1381
+
You need to use the `applicationinsights` v3 Beta package to send custom telemetry using the Application Insights classic API. (https://www.npmjs.com/package/applicationinsights/v/beta)
0 commit comments