I have a basic setup working where i sent logs from GKE and format them according to the rules from Stackdriver Error Reporting.
I can see the stacktraces but the additional information like user, version, ... is missing. This is what i see: error reporting detail view
When i click on show logs i can see the formated log entry and it seems to me that it is in the right format... The log entry in Stackdriver logging for the example looks like this:
{
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"
}
The user, the httpContext and the other context attributes are in the json log. What am I missing to get the result shown in the example where you can see the effected user and the http request?
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.