简体   繁体   English

Stackdriver Python记录RPC错误

[英]Stackdriver python log RPC error

I am having a RPC issue with logging an error to GCP StackDriver. 我在将错误记录到GCP StackDriver时遇到RPC问题。 Following is the error message: 以下是错误消息:

grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.DEADLINE_EXCEEDED, Deadline Exceeded)>

Here is the python code for logging: 这是用于记录的python代码:

import logging
import logging.handlers
import os
import config
import google.cloud.logging as gcp_logging
from google.oauth2 import service_account

logger = logging.getLogger('my_logger')
## using Google Stackdriver logging
#client = gcp_logging.Client(project=config.project, credentials=config.credentials_gcp_ml)
#client = gcp_logging.Client.from_service_account_json('./cred.json')
cred = service_account.Credentials.from_service_account_file('./cred.json')
client = gcp_logging.Client(project = config.project, credentials=cred)
hdlr = client.get_default_handler()
logger = logging.getLogger('cloudLogger')

formatter = logging.Formatter('%(asctime)s  %(levelname)s   %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)

I run this code in my local computer connecting to my GCP account. 我在连接到GCP帐户的本地计算机上运行此代码。

google-auth 1.2.0; google-cloud-logging 1.4.0

I have tried your code (slightly modified to adapt it to my project, and with a last line added in order to output logs to the Stackdriver Logging console ) and it is working for me. 我已经尝试了您的代码(稍作修改以使其适合我的项目,并添加了最后一行,以便将日志输出到Stackdriver Logging控制台 ),并且它对我有用

Here I share the code I have used: 在这里,我分享了我曾经使用的代码:

import logging
import logging.handlers
import os
import google.cloud.logging as gcp_logging
from google.oauth2 import service_account

logger = logging.getLogger('my_logger')
cred = service_account.Credentials.from_service_account_file('./private-key.json')
client = gcp_logging.Client(project = "<YOUR_PROJECT_ID>", credentials=cred)
hdlr = client.get_default_handler()
logger = logging.getLogger('cloudLogger')

formatter = logging.Formatter('%(asctime)s  %(levelname)s   %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
logger.info('This is a Logging Test.')

And after running the command python test.py in my local machine, this is the result I obtain: 在我的本地计算机上运行命令python test.py之后,这是我得到的结果:

Program shutting down, attempting to send 1 queued log entries to Stackdriver Logging...
Waiting up to 5 seconds.
Sent all pending logs.

Then, if I move to the console link I provided before and filter using the Global resource type ( resource.type="global" ), this is what I see: 然后,如果我移至之前提供的控制台链接,并使用Global资源类型( resource.type="global" )进行过滤,则将看到以下内容:

在此处输入图片说明

As stated by @A.Queue, I am also running google-auth version 1.3.0 and google-cloud-logging 1.4.0 , so you should try upgrading google-auth , using the command: 如@ A.Queue所述,我还在运行google-auth版本1.3.0google-cloud-logging 1.4.0 ,因此您应该尝试使用以下命令升级google-auth

pip install --upgrade google-auth

Try that and come back to us if the same error keeps coming up. 如果仍然出现相同的错误,请尝试尝试并返回给我们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM