How agents log APM Server errors
- Dominant language
- Gherkin
- Stars
- 427
- Forks
- 125
- PR merge metrics
- No merged PRs in 30d
Description
If the APM Server encounters any error it will respond with a non 2xx response code and a JSON body like so:
```json
{
"accepted": 0,
"errors": [
{
"message": "Problem validating JSON document against schema: I[#] S[#] doesn't validate with \"metadata#\"\n I[#/service/framework] S[#/properties/service/properties/framework/required] missing properties: \"version\"",
"document": "{\"metadata\":{\"service\":{\"name\":\"elastic-apm-node\",\"runtime\":{\"name\":\"node\",\"version\":\"11.0.0\"},\"language\":{\"name\":\"javascript\"},\"agent\":{\"name\":\"nodejs\",\"version\":\"1.13.0\"},\"framework\":{\"name\":\"test\"}},\"process\":{\"pid\":66903,\"ppid\":2097,\"title\":\"node\",\"argv\":[\"/Users/watson/.nvm/versions/node/v11.0.0/bin/node\",\"/Users/watson/code/node_modules/elastic-apm-node/tst.js\"]},\"system\":{\"hostname\":\"watson.local\",\"architecture\":\"x64\",\"platform\":\"darwin\"}}}"
}
]
}
```
The documents inside the `errors` array will always have a `message` property and optionally a `document` property.
I just discovered that we didn't log these errors in the Node.js agent and wanted to fix that. It would maybe make sense if all agents aligned on how to log these if possible?
This is how I was thinking of logging them in the Node.js agent (I've repeated the same error twice to show how it would look for more than one error):
```
An error occrued while communicating with the APM Server: Unexpected response code from APM Server: 400
The APM Server accepted 0 events in the last request
Error #1: Problem validating JSON document against schema: I[#] S[#] doesn't validate with "metadata#"
I[#/service/framework] S[#/properties/service/properties/framework/required] missing properties: "version"
Document: {"metadata":{"service":{"name":"elastic-apm-node","runtime":{"name":"node","version":"11.0.0"},"language":{"name":"javascript"},"agent":{"name":"nodejs","version":"1.13.0"},"framework":{"name":"test"}},"process":{"pid":81864,"ppid":2097,"title":"node","argv":["/Users/watson/.nvm/versions/node/v11.0.0/bin/node","/Users/watson/code/node_modules/elastic-apm-node/tst.js"]},"system":{"hostname":"watson.local","architecture":"x64","platform":"darwin"}}}
Error #2: Problem validating JSON document against schema: I[#] S[#] doesn't validate with "metadata#"
I[#/service/framework] S[#/properties/service/properties/framework/required] missing properties: "version"
Document: {"metadata":{"service":{"name":"elastic-apm-node","runtime":{"name":"node","version":"11.0.0"},"language":{"name":"javascript"},"agent":{"name":"nodejs","version":"1.13.0"},"framework":{"name":"test"}},"process":{"pid":81864,"ppid":2097,"title":"node","argv":["/Users/watson/.nvm/versions/node/v11.0.0/bin/node","/Users/watson/code/node_modules/elastic-apm-node/tst.js"]},"system":{"hostname":"watson.local","architecture":"x64","platform":"darwin"}}}
```
The first line is just how the node agent currently logs _any_ communication error with the APM Server.
The errors from the JSON Schema validator unfortunately includes linebreaks, so that's why the message is broken into two lines, but since the 2nd line is indented, it actually doesn't look that bad.
@elastic/apm-agent-devs Please let me know how you currently output these errors. I don't have any strong preferences, but it would of course be nice to settle on a format that most log-readers would see as "one message". That's what I'm trying to do with the indentation - but I'm not sure if that's actually a standard 😅
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.