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