रिपोर्ट त्रुटियां

स्वचालित रूप से त्रुटियाँ रिपोर्ट करना

जैसा कि नीचे दिखाया गया है, आप क्लाउड फ़ंक्शन से त्रुटि रिपोर्टिंग में त्रुटि उत्पन्न कर सकते हैं:

नोड.जे.एस

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

अजगर

@functions_framework.http
def hello_error_1(request):
    # This WILL be reported to 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 Error Reporting,
    # and WILL terminate the function
    raise RuntimeError("I failed you")


@functions_framework.http
def hello_error_2(request):
    # These errors WILL NOT be reported to Error
    # Reporting, but will show up in logs.
    import logging
    import sys

    print(RuntimeError("I failed you (print to stdout)"))
    logging.warning(RuntimeError("I failed you (logging.warning)"))
    logging.error(RuntimeError("I failed you (logging.error)"))
    sys.stderr.write("I failed you (sys.stderr.write)\n")

    # This is considered a successful execution and WILL NOT be reported
    # to Error Reporting, but the status code (500) WILL be logged.
    from flask import abort

    return abort(500)

यदि आप अधिक सुक्ष्म त्रुटि रिपोर्टिंग चाहते हैं, तो आप त्रुटि रिपोर्टिंग क्लाइंट लाइब्रेरीज़ का उपयोग कर सकते हैं।

आप जीसीपी कंसोल में त्रुटि रिपोर्टिंग में रिपोर्ट की गई त्रुटियों को देख सकते हैं। जब आप किसी विशेष फ़ंक्शन को GCP कंसोल में फ़ंक्शन की सूची से चुनते हैं तो आप उससे रिपोर्ट की गई त्रुटियां भी देख सकते हैं।

आपके फ़ंक्शन द्वारा उत्पन्न अनकहा अपवाद त्रुटि रिपोर्टिंग में दिखाई देंगे। ध्यान दें कि कुछ प्रकार के अनदेखे अपवाद (जैसे कि एसिंक्रोनस रूप से फेंके गए) भविष्य में फ़ंक्शन के आह्वान पर ठंडी शुरुआत का कारण बनेंगे। इससे आपके फ़ंक्शन को चलने में लगने वाला समय बढ़ जाता है।

मैन्युअल रूप से त्रुटियों की रिपोर्टिंग

क्लाउड लॉगिंग पर भेजा जा रहा है

क्लाउड फ़ंक्शंस लॉगर एसडीके से error फ़ंक्शन क्लाउड लॉगिंग और त्रुटि रिपोर्टिंग दोनों में त्रुटियों की रिपोर्ट करेगा। संरचित डेटा के रूप में त्रुटि से अधिक संदर्भ शामिल करने के लिए, एक त्रुटि ऑब्जेक्ट को दूसरे तर्क के रूप में पास करें:

} catch (err) {
  // Attach an error object as the second argument
  functions.logger.error(
    "Unable to read quote from Firestore, sending default instead",
    err
  );
}