1

我有一个基本设置工作,我从GKE发送日志并根据Stackdriver错误报告的规则对其进行格式化。设置Stackdriver错误报告以显示详细信息

我可以看到堆栈跟踪,但像用户,版本等附加信息丢失。这是我看到: error reporting detail view

当我上显示日志点击我可以看到格式化的日志条目,并在我看来,这是在正确的格式...在为Stackdriver日志记录的日志记录的例子看起来像这样:

{ 
insertId: "vd0zy9g5mw3iof" 
jsonPayload: { 
    message: { 
     context: { 
      reportLocation: { 
       functionName: "error_router" 
       filePath: "/usr/local/lib/python2.7/site-packages/flask_restplus/api.py" 
       lineNumber: 554 
      } 
      httpRequest: { 
      method: "POST" 
      remoteIp: "213.47.170.171" 
      referrer: "https://api-staging.smaxtec.com/api/v1/" 
      userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" 
      url: "https://api-staging.smaxtec.com/api/v1/device/update_name" 
      responseStatusCode: 404 
      } 
      user: "569e0bcda80a5f1c07b542be" 
     } 
     message: "Traceback (most recent call last): 
     File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request 
      rv = self.dispatch_request() 
     File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request 
      return self.view_functions[rule.endpoint](**req.view_args) 
     File "/usr/local/lib/python2.7/site-packages/flask_restplus/api.py", line 313, in wrapper 
      resp = resource(*args, **kwargs) 
     File "/usr/local/lib/python2.7/site-packages/flask/views.py", line 84, in view 
      return self.dispatch_request(*args, **kwargs) 
     File "/usr/local/lib/python2.7/site-packages/flask_restplus/resource.py", line 44, in dispatch_request 
      resp = meth(*args, **kwargs) 
     File "/usr/local/lib/python2.7/site-packages/webargs/core.py", line 445, in wrapper 
      return func(*new_args, **kwargs) 
     File "/app/anthilldata/core/restapi/namespace.py", line 154, in dump_wrapper 
      response = func(*args, **kwargs) 
     File "/app/anthilldata/api/publicv1/base.py", line 144, in decorated 
      return f(*args, auth=auth, **kwargs) 
     File "/app/anthilldata/api/publicv1/device.py", line 98, in post 
      dev = devices.getById(device_id) 
     File "/app/anthilldata/devices/__init__.py", line 102, in getById 
      device = self._getById(id) 
     File "/app/anthilldata/core/__init__.py", line 171, in _getById 
      self.__model__.__name__, id)) 
     NotFoundError: Device(strisdfsdfsdfsdfsdfsdfng) not found 
     " 
     serviceContext: { 
      version: "v1.20-25-gf94b2b7" 
      service: "anthilldata" 
     } 
     } 
     thread: 140663840671488 
} 
resource: { 
    type: "container" 
    labels: { 
    pod_id: "api-staging-deployment-3325000162-npq9r" 
    zone: "europe-west1-d" 
    project_id: "smaxtec-system" 
    cluster_name: "kuhbernetes1" 
    container_name: "anthilldata" 
    namespace_id: "default" 
    instance_id: "4882784730069069317" 
    } 
} 
timestamp: "2017-04-07T08:06:30.247392892Z" 
severity: "ERROR" 
labels: { 
    container.googleapis.com/container_name: "anthilldata" 
    compute.googleapis.com/resource_name: "fluentd-cloud-logging-gke-kuhbernetes1-default-pool-b875e508-7x" 
    container.googleapis.com/instance_id: "4882784730069069317" 
    container.googleapis.com/pod_name: "api-staging-deployment-3325000162-npq9r" 
    container.googleapis.com/stream: "stderr" 
    container.googleapis.com/namespace_name: "default" 
    compute.googleapis.com/resource_type: "instance" 
    compute.googleapis.com/resource_id: "4882784730069069317" 
    container.googleapis.com/cluster_name: "kuhbernetes1" 
} 
logName: "projects/smaxtec-system/logs/anthilldata" 
} 

用户,httpContext和其他上下文属性在json日志中。我错过了什么以获得example中显示的结果,您可以在其中看到受影响的用户和http请求?

回答

0

在你的实施例中的条目有效载荷具有类似于

jsonPayload: { 
    message: { 
     context: {...}, 
     message: "...", 
     serviceContext: {...} 
    } 
} 

和中间message结构导致的问题的结构。你要像

jsonPayload: { 
    context: {...}, 
    message: "...", 
    serviceContext: {...} 
} 

错误报告仍然能够解析出异常消息,但预计在特定JSON路径等领域。

我试着写两条消息到Stackdriver Logging,有和没有额外的message嵌套。两者都出现在错误报告中,但只有样本中没有包含服务,版本,用户等的一个。

+0

非常感谢,因为没有看到它而感到哑巴。完全解决了我的问题。 – MTHS