Backend: Error Monitoring
Go
Java
JS
Python
Ruby
Backend: Logging
Go
JS
Python
Ruby
Java
Hosting Providers
Backend: Tracing
Go
Node.js
Python
Native OpenTelemetry
Fullstack Frameworks
Overview
Self Host & Local Dev
Menu
Using highlight.io with Python on Google Cloud Functions
Learn how to set up highlight.io on Google Cloud Functions.
1
Setup your frontend Highlight snippet with tracingOrigins.
Make sure that you followed the fullstack mapping guide.
H.init("<YOUR_PROJECT_ID>", {
tracingOrigins: ['localhost', 'example.myapp.com/backend'],
networkRecording: {
enabled: true,
recordHeadersAndBody: true,
},
});
2
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
3
Initialize the Highlight SDK.
Setup the SDK. Add the @observe_handler
decorator to your functions.
import logging
import random
from datetime import datetime
import functions_framework
import highlight_io
from highlight_io.integrations.gcp 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
@functions_framework.http
def hello_http(request):
return "Hello {}!".format(name)
4
Verify your installation.
Check that your installation is valid by throwing an error. Add an operation that raises an exception to your function. Setup an HTTP trigger and visit your function on the internet. You should see a DivideByZero
error in the Highlight errors page within a few moments.
import logging
import random
from datetime import datetime
import functions_framework
import highlight_io
from highlight_io.integrations.gcp 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
@functions_framework.http
def hello_http(request):
return f"This might be a bad idea: {5/0}"
5
Set up logging.
With the Python SDK, your logs are reported automatically from builtin logging methods. See the Python logging setup guide for more details.