设置Stackdriver错误报告以显示详细信息

时间:2017-04-07 08:59:10

标签: stackdriver google-compute-engine google-cloud-error-reporting

我有一个基本设置工作,我从GKE发送日志并根据Stackdriver Error Reporting中的规则对其进行格式化。

我可以看到堆栈跟踪,但缺少用户,版本等附加信息。这就是我所看到的: error reporting detail view

当我点击show logs时,我可以看到格式化的日志条目,在我看来它的格式正确... 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请求时,我缺少什么?

1 个答案:

答案 0 :(得分:0)

The entry payload in your example has a structure like

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

and the intermediate message structure is causing problems. You want something like

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

Error Reporting is still able to parse out the exception message, but is expecting the other fields at specific JSON paths.

I tried writing two messages to Stackdriver Logging, with and without the extra message nesting. Both appeared in Error Reporting, but only the one without included service, version, user, etc in the sample.