פתרון בעיות

מעקב אחרי בעיות ב-GRPC

לפני שמתחילים

חשוב לאתחל ולהפעיל הרשאות כתיבה לפני שכותבים בקובץ היומן. בדוגמה הבאה, שם קובץ היומן הוא /var/log/grpc.log:

touch /var/log/grpc.log
chmod 666 /var/log/grpc.log

אם נתקלים בבעיות בהרשאות הקובץ, יכול להיות שצריך להוסיף את sudo לפני הפקודות הקודמות.

רישום ביומן לקובץ

כדי לשמור את יומני ה-gRPC בקובץ, מוסיפים את השורות הבאות לקובץ php.ini:

grpc.grpc_verbosity=debug
grpc.grpc_trace=all,-timer_check
grpc.log_filename=/var/log/grpc.log

כדי לכתוב יומנים אל stderr במקום זאת, מחריגים את השורה האחרונה מהדוגמה הקודמת. מידע נוסף על אפשרויות אחרות זמין במאמר בנושא משתני סביבה של gRPC.

פרטי שגיאה

שירותי Google Cloud פועלים בהתאם להנחיות של AIP-193 כשמוחזרות שגיאות. שירותי Google Cloud משתמשים בקבוצה מוגדרת של מטעני נתונים סטנדרטיים של שגיאות, שאפשר למצוא ב-google.rpc.error_details.proto. הם כוללים את שגיאות ה-API הנפוצות ביותר, כמו חריגה מהמכסה ופרמטרים לא תקינים.

שגיאות API שמופקות על ידי ספריות לקוח של PHP מכילות את השדות message,‏ code,‏ status ו-details. בשדה details, נתונים נוספים של google.rpc.ErrorInfo מופיעים בשדות reason, domain ו-metadata. בדוגמה הבאה מוצגת שגיאה שעשויה להופיע אם קראתם לספריית התרגום עם פרויקט בענן לפני שהפעלתם את Translate API:

Google\ApiCore\ApiException: {
    "reason": "SERVICE_DISABLED",
    "domain": "googleapis.com",
    "errorInfoMetadata": {
        "consumer": "projects\PROJECT_ID",
        "service": "translate.googleapis.com"
    },
    "message": "Cloud Translation API has not been used in project PROJECT_ID before or it is disabled. Enable it by visiting https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=PROJECT_ID then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "code": 7,
    "status": "PERMISSION_DENIED",
    "details": [
        {
            "@type": "google.rpc.errorinfo-bin",
            "reason": "SERVICE_DISABLED",
            "domain": "googleapis.com",
            "metadata": {
                "consumer": "projects\PROJECT_ID",
                "service": "translate.googleapis.com"
            }
        },
        {
            "@type": "google.rpc.help-bin",
            "links": [
                {
                    "description": "Google developers console API activation",
                    "url": "https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=PROJECT_ID"
                }
            ]
        }
    ]
}

מידע נוסף על מודל השגיאות הכללי של ממשקי Google API זמין במאמר שגיאות ב-Cloud API.