Skip to content

Commit f3bd8db

Browse files
committed
update
1 parent 89a36f5 commit f3bd8db

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

articles/azure-monitor/app/opencensus-python.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ Below is a list of standard metrics that are currently sent:
268268
- Process CPU Usage (percentage)
269269
- Process Private Bytes (bytes)
270270

271-
You should be able to see these metrics in `performanceCounters`. Incoming request rate would be under `customMetrics`.
271+
You should be able to see these metrics in `performanceCounters`. Incoming request rate would be under `customMetrics`. For more information, see [performance counters](https://docs.microsoft.com/azure/azure-monitor/app/performance-counters).
272+
272273
#### Modify telemetry
273274

274275
For details on how to modify tracked telemetry before it is sent to Azure Monitor, see OpenCensus Python [telemetry processors](https://docs.microsoft.com/azure/azure-monitor/app/api-filtering-sampling#opencensus-python-telemetry-processors).
@@ -385,13 +386,33 @@ For details on how to modify tracked telemetry before it is sent to Azure Monito
385386

386387
# Use properties in logging statements
387388
logger.warning('action', extra=properties)
389+
```
390+
391+
#### Sending exceptions
392+
393+
OpenCensus Python does not automatically track and send `exception` telemetry. They are sent through the `AzureLogHandler` by using exceptions through the Python logging library. You can add custom properties just like with normal logging.
394+
395+
```python
396+
import logging
397+
398+
from opencensus.ext.azure.log_exporter import AzureLogHandler
399+
400+
logger = logging.getLogger(__name__)
401+
# TODO: replace the all-zero GUID with your instrumentation key.
402+
logger.addHandler(AzureLogHandler(
403+
connection_string='InstrumentationKey=00000000-0000-0000-0000-000000000000')
404+
)
405+
406+
properties = {'custom_dimensions': {'key_1': 'value_1', 'key_2': 'value_2'}}
388407

389408
# Use properties in exception logs
390409
try:
391410
result = 1 / 0 # generate a ZeroDivisionError
392411
except Exception:
393-
logger.exception('Captured an exception.', extra=properties)
412+
logger.exception('Captured an exception.', extra=properties)
394413
```
414+
Since you must log exceptions explicitly, it is up to the user in how they want to log unhandled exceptions. OpenCensus does not place restrictions in how a user wants to do this, as long as they explicitly log an exception telemetry.
415+
395416
#### Sampling
396417

397418
For information on sampling in OpenCensus, take a look at [sampling in OpenCensus](sampling.md#configuring-fixed-rate-sampling-for-opencensus-python-applications).

0 commit comments

Comments
 (0)