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){
13221322
13231323#### [ Python] ( #tab/python )
13241324
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+
13251327``` python
13261328from opentelemetry import trace
13271329from opentelemetry.sdk.trace import TracerProvider
@@ -1339,12 +1341,27 @@ trace.get_tracer_provider().add_span_processor(span_processor)
13391341# Exception events
13401342try :
13411343 with tracer.start_as_current_span(" hello" ) as span:
1344+ # This exception will be automatically recorded
13421345 raise Exception (" Custom exception message." )
13431346except Exception :
13441347 print (" Exception raised" )
13451348
13461349```
13471350
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+
13481365---
13491366
13501367## Enable the OTLP Exporter
You can’t perform that action at this time.
0 commit comments