Using highlight.io with Python on Azure Functions
Learn how to set up highlight.io with Azure Functions.
Configure client-side Highlight. (optional)
If you're using Highlight on the frontend for your application, make sure you've initialized it correctly and followed the fullstack mapping guide.
Install the highlight-io python package.
Download the package from pypi and save it to your requirements. If you use a zip or s3 file upload to publish your function, you will want to make sure highlight-io
is part of the build.
poetry add highlight-io
# or with pip
pip install highlight-io
Initialize the Highlight SDK.
Setup the SDK. Add the @observe_handler
decorator to your azure functions.
import azure.functions as func
import highlight_io
from highlight_io.integrations.azure import observe_handler
# `instrument_logging=True` sets up logging instrumentation.
# if you do not want to send logs or are using `loguru`, pass `instrument_logging=False`
H = highlight_io.H(
"<YOUR_PROJECT_ID>",
instrument_logging=True,
service_name="my-app",
service_version="git-sha",
environment="production",
)
@observe_handler
def main(req: func.HttpRequest) -> func.HttpResponse:
return func.HttpResponse(
"This HTTP triggered function executed successfully.",
status_code=200,
)
Verify your installation.
Check that your installation is valid by throwing an error. Add an operation that raises an exception to your azure function. Setup an HTTP trigger and visit your azure function on the internet. You should see a DivideByZero
error in the Highlight errors page within a few moments.
import azure.functions as func
import highlight_io
from highlight_io.integrations.azure import observe_handler
# `instrument_logging=True` sets up logging instrumentation.
# if you do not want to send logs or are using `loguru`, pass `instrument_logging=False`
H = highlight_io.H(
"<YOUR_PROJECT_ID>",
instrument_logging=True,
service_name="my-app",
service_version="git-sha",
environment="production",
)
@observe_handler
def main(req: func.HttpRequest) -> func.HttpResponse:
return func.HttpResponse(
f"Not a good idea: {5 / 0}.",
)
Verify your backend logs are being recorded.
Visit the highlight logs portal and check that backend logs are coming in.
Verify your backend traces are being recorded.
Visit the highlight traces portal and check that backend traces are coming in.