File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
articles/azure-monitor/app Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -1322,6 +1322,8 @@ catch(error){
1322
1322
1323
1323
#### [ Python] ( #tab/python )
1324
1324
1325
+ The OpenTelemetry Python SDK is implemented such that exceptions thrown will automatically be captured and recorded. See below for an example of this.
1326
+
1325
1327
``` python
1326
1328
from opentelemetry import trace
1327
1329
from opentelemetry.sdk.trace import TracerProvider
@@ -1339,12 +1341,27 @@ trace.get_tracer_provider().add_span_processor(span_processor)
1339
1341
# Exception events
1340
1342
try :
1341
1343
with tracer.start_as_current_span(" hello" ) as span:
1344
+ # This exception will be automatically recorded
1342
1345
raise Exception (" Custom exception message." )
1343
1346
except Exception :
1344
1347
print (" Exception raised" )
1345
1348
1346
1349
```
1347
1350
1351
+ If you would like to record exceptions manually, you can disable that option when creating the span as show below.
1352
+
1353
+ ``` python
1354
+ ...
1355
+ with tracer.start_as_current_span(" hello" , record_exception = False ) as span:
1356
+ try :
1357
+ raise Exception (" Custom exception message." )
1358
+ except Exception as ex:
1359
+ # Manually record exception
1360
+ span.record_exception(ex)
1361
+ ...
1362
+
1363
+ ```
1364
+
1348
1365
---
1349
1366
1350
1367
## Enable the OTLP Exporter
You can’t perform that action at this time.
0 commit comments