Sentry-python: Google Cloud Functions SDK

Created on 27 Nov 2018  路  6Comments  路  Source: getsentry/sentry-python

There is an AWS Lambda integration, but there is no Google Cloud Functions SDK.

Here's their python environment description: https://cloud.google.com/functions/docs/concepts/python-runtime

new-integration

Most helpful comment

It's on our radar but so far there haven't been too many requests for it. I suppose the best way to go about this is to vote with :+1: on the OP (please no comments!) because that's what I can sort issues by.

All 6 comments

It's on our radar but so far there haven't been too many requests for it. I suppose the best way to go about this is to vote with :+1: on the OP (please no comments!) because that's what I can sort issues by.

In the meantime is there a suggestion for a basic way to configure and use Sentry within a python Google Cloud Function?

Thanks!

@davegaeddert just calling sentry_sdk.init() without integrations should be fine, as per https://docs.sentry.io/quickstart/?platform=python

You might encounter issues where Google suspends your process before events are sent, because we don't have a synchronous transport... in master we have a new function Client.flush() which you can call to wait for all events to be sent out.

Example:

from sentry_sdk import *

init("my dsn")

def sentry_cloud_function(f):
    def inner(*a, **kw):
        try:
            return f(*a, **kw)
        except Exception:
            capture_exception()
            raise
        finally:
            flush()
    return inner

@sentry_cloud_function
def hello_http(...): # see google cloud function docs
    capture_message("hi!")
    pass

This decorator is now shipped with the SDK: https://docs.sentry.io/platforms/python/serverless/

Awesome, thanks @untitaker!

Was this page helpful?
0 / 5 - 0 ratings