@elastic/ecs-helpers
Advanced tools
Comparing version 0.5.0 to 0.6.0
# @elastic/ecs-helpers Changelog | ||
## v0.6.0 | ||
- Add `formatError` for adding [ECS Error fields](https://www.elastic.co/guide/en/ecs/current/ecs-error.html) | ||
for a given `Error` object. | ||
([#42](https://github.com/elastic/ecs-logging-js/pull/42)) | ||
## v0.5.0 | ||
@@ -4,0 +10,0 @@ |
@@ -32,4 +32,4 @@ // Licensed to Elasticsearch B.V under one or more agreements. | ||
ecs.url.full = (socket.encrypted ? 'https://' : 'http://') + headers.host + url | ||
var hasQuery = url.indexOf('?') | ||
var hasAnchor = url.indexOf('#') | ||
const hasQuery = url.indexOf('?') | ||
const hasAnchor = url.indexOf('#') | ||
if (hasQuery > -1 && hasAnchor > -1) { | ||
@@ -52,3 +52,5 @@ ecs.url.path = url.slice(0, hasQuery) | ||
ecs.url.domain = host | ||
if (port) ecs.url.port = Number(port) | ||
if (port) { | ||
ecs.url.port = Number(port) | ||
} | ||
} | ||
@@ -62,6 +64,6 @@ | ||
var hasHeaders = Object.keys(headers).length > 0 | ||
const hasHeaders = Object.keys(headers).length > 0 | ||
if (hasHeaders === true) { | ||
ecs.http.request.headers = ecs.http.request.headers || {} | ||
for (var header in headers) { | ||
for (const header in headers) { | ||
if (header === 'content-length') { | ||
@@ -82,3 +84,3 @@ ecs.http.request.body = ecs.http.request.body || {} | ||
function formatHttpResponse (ecs, res) { | ||
var { statusCode } = res | ||
const { statusCode } = res | ||
ecs.http = ecs.http || {} | ||
@@ -88,7 +90,7 @@ ecs.http.response = ecs.http.response || {} | ||
var headers = res.getHeaders() | ||
var hasHeaders = Object.keys(headers).length > 0 | ||
const headers = res.getHeaders() | ||
const hasHeaders = Object.keys(headers).length > 0 | ||
if (hasHeaders === true) { | ||
ecs.http.response.headers = ecs.http.response.headers || {} | ||
for (var header in headers) { | ||
for (const header in headers) { | ||
if (header === 'content-length') { | ||
@@ -95,0 +97,0 @@ ecs.http.response.body = ecs.http.response.body || {} |
@@ -8,2 +8,3 @@ // Licensed to Elasticsearch B.V under one or more agreements. | ||
const stringify = require('./serializer') | ||
const errorFormatters = require('./error-formatters') | ||
const httpFormatters = require('./http-formatters') | ||
@@ -14,3 +15,4 @@ | ||
stringify, | ||
...errorFormatters, | ||
...httpFormatters | ||
} |
@@ -131,2 +131,12 @@ // Licensed to Elasticsearch B.V under one or more agreements. | ||
additionalProperties: true | ||
}, | ||
// https://www.elastic.co/guide/en/ecs/current/ecs-error.html | ||
error: { | ||
type: 'object', | ||
properties: { | ||
type: string, | ||
message: string, | ||
stack_trace: string | ||
}, | ||
additionalProperties: true | ||
} | ||
@@ -133,0 +143,0 @@ }, |
{ | ||
"name": "@elastic/ecs-helpers", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "ECS loggers helpers", | ||
@@ -20,3 +20,3 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"test": "standard && ava -v" | ||
"test": "standard && tap --timeout 10 test.js" | ||
}, | ||
@@ -30,9 +30,8 @@ "engines": { | ||
"devDependencies": { | ||
"ajv": "^6.11.0", | ||
"ava": "^3.1.0", | ||
"ajv": "^7.0.3", | ||
"ajv-formats": "^1.5.1", | ||
"semver": "^7.1.3", | ||
"simple-get": "^3.1.0", | ||
"standard": "^14.3.1", | ||
"stoppable": "^1.1.0" | ||
"standard": "16.x", | ||
"tap": "^14.x" | ||
} | ||
} |
@@ -11,4 +11,5 @@ <img align="right" width="auto" height="auto" src="https://www.elastic.co/static-res/images/elastic-logo-200.png"> | ||
## Install | ||
```sh | ||
npm i @elastic/ecs-helpers | ||
npm install @elastic/ecs-helpers | ||
``` | ||
@@ -19,2 +20,3 @@ | ||
### `version` | ||
The currently supported version of [Elastic Common Schema](https://www.elastic.co/guide/en/ecs/current/index.html). | ||
@@ -49,3 +51,37 @@ | ||
### `formatError` | ||
A function that adds [ECS Error fields](https://www.elastic.co/guide/en/ecs/current/ecs-error.html) | ||
for a given `Error` object. | ||
```js | ||
const { formatError } = require('@elastic/ecs-helpers') | ||
const logRecord = { msg: 'oops', /* ... */ } | ||
formatError(logRecord, new Error('boom')) | ||
console.log(logRecord) | ||
``` | ||
will show: | ||
```js | ||
{ | ||
msg: 'oops', | ||
error: { | ||
type: 'Error', | ||
message: 'boom', | ||
stack_trace: 'Error: boom\n' + | ||
' at REPL30:1:26\n' + | ||
' at Script.runInThisContext (vm.js:133:18)\n' + | ||
// ... | ||
} | ||
} | ||
``` | ||
The ECS logging libraries typically use this to automatically handle an `err` | ||
metadata field passed to a logging statement. E.g. | ||
`log.warn({err: myErr}, '...')` for pino, `log.warn('...', {err: myErr})` | ||
for winston. | ||
### `formatHttpRequest` | ||
Function that enhances an ECS object with http request data. | ||
@@ -73,2 +109,3 @@ The request object should be Node.js's core request object. | ||
### `formatHttpResponse` | ||
Function that enhances an ECS object with http response data. | ||
@@ -96,2 +133,3 @@ The response object should be Node.js's core response object. | ||
## License | ||
This software is licensed under the [Apache 2 license](./LICENSE). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
24117
5
8
266
131
0