Analytics Vidhya
Published in

Analytics Vidhya

Azure Synapse Spark logs runtime errors to Application insights

Using open census library to push error logs to Azure monitor



name: example-environment
- conda-forge
- python
- numpy
- pip
- pip:
- opencensus-ext-azure


import logging
from import AzureLogHandler
logger = logging.getLogger(__name__)# TODO: replace the all-zero GUID with your instrumentation key.
logger.warning("Sample from open census test 01")
logger.error("Sample from open census test 02")
from import AzureExporter
from opencensus.trace.samplers import ProbabilitySampler
from opencensus.trace.tracer import Tracer
properties = {'custom_dimensions': {'key_1': 'value_1', 'key_2': 'value_2'}}# Use properties in exception logs
result = 1 / 0 # generate a ZeroDivisionError
except Exception:
logger.exception('Captured an exception.', extra=properties)



Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store