সমস্যার ব্যাপারে অভিযোগ জানানো

সমস্যার ব্যাপারে অটোমেটিক রিপোর্ট করা

আপনি কোনও ফাংশন থেকে সমস্যার রিপোর্ট করতে পারেন, যেমন নিচে দেখানো হয়েছে:

Node.js

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

Python

@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)

আপনি যদি আরও সূক্ষ্মভাবে সমস্যার রিপোর্ট করতে চান, তাহলে সমস্যার রিপোর্ট করার ক্লায়েন্ট লাইব্রেরি ব্যবহার করতে পারেন।

Google Cloud কনসোলে সমস্যার রিপোর্ট থেকে আপনি অভিযোগ জানানো সমস্যা দেখতে পাবেন। এছাড়াও, Google Cloud কনসোলে ফাংশনের তালিকা থেকে কোনও ফাংশন বেছে নিলে, সেই ফাংশন থেকে পাওয়া ত্রুটি দেখতে পাবেন।

আপনার ফাংশনের মাধ্যমে তৈরি করা আনকড ব্যতিক্রমগুলি 'সমস্যা সংক্রান্ত রিপোর্ট' ফিচারে দেখা যাবে। মনে রাখবেন, কিছু ধরনের আনক্যাচড ব্যতিক্রম (যেমন, অ্যাসিঙ্ক্রোনাসভাবে থ্রো করা) ভবিষ্যতে ফাংশন ইনভোকেশন করার সময় কোল্ড স্টার্ট হওয়ার কারণ হবে। এর ফলে আপনার ফাংশন রান করতে বেশি সময় লাগবে।

ম্যানুয়ালি সমস্যার ব্যাপারে রিপোর্ট করা

ডিপেন্ডেন্সি ইমপোর্ট করা

ফাংশন থেকে সমস্যা রিপোর্ট করার জন্য সমস্যা রিপোর্ট করতে, Cloud Functions logger SDK থেকে error ফাংশন ইমপোর্ট করুন:

// All available logging functions
const {
  log,
  info,
  debug,
  warn,
  error,
  write,
} = require("firebase-functions/logger");

Cloud Logging-এ পাঠানো হচ্ছে

Cloud Functions logger SDK-এর error ফাংশন Cloud Logging ও Error Reporting, দু'টি জায়গাতেই সমস্যার রিপোর্ট করবে। স্ট্রাকচার্ড ডেটা হিসেবে সমস্যার আরও প্রসঙ্গ যোগ করতে, দ্বিতীয় আর্গুমেন্ট হিসেবে একটি সমস্যার অবজেক্ট পাস করুন:

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