Reporting Errors

You can emit an error from a Cloud Function to Stackdriver Error Reporting as shown below:

Node.js

// These WILL be reported to Stackdriver Error Reporting
console.error(new Error('I failed you'));
throw new Error('I failed you'); // Will cause a cold start if not caught

// These will NOT be reported to Stackdriver Error Reporting
console.info(new Error('I failed you')); // Logging an Error object at the info level
console.error('I failed you'); // Logging something other than an Error object
throw 1; // Throwing something other than an Error object
callback('I failed you');
res.status(500).send('I failed you');

Python (Beta)

# This WILL be reported to Stackdriver Error
# Reporting, and WILL NOT show up in logs or
# terminate the function.
from google.cloud import error_reporting
client = error_reporting.Client()

try:
    raise RuntimeError('I failed you')
except RuntimeError:
    client.report_exception()

# This WILL be reported to Stackdriver Error Reporting,
# and WILL terminate the function
raise RuntimeError('I failed you')

# WILL NOT be reported to Stackdriver Error Reporting, but will show up
# in logs
import logging
print(RuntimeError('I failed you (print to stdout)'))
logging.warn(RuntimeError('I failed you (logging.warn)'))
logging.error(RuntimeError('I failed you (logging.error)'))
sys.stderr.write('I failed you (sys.stderr.write)\n')

# This WILL be reported to Stackdriver Error Reporting
from flask import abort
return abort(500)

You can view the reported errors in Stackdriver Error Reporting in the GCP Console. You can also see the errors reported from a particular function when you select it from the list of functions in the GCP Console.

Uncaught exceptions produced by your function will appear in Stackdriver Error Reporting. Note that some uncaught exceptions, for example, those thrown asynchronously, may cause a cold start on a future function invocation. This reduces function performance.

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Functions Documentation