Socket
Socket
Sign inDemoInstall

@elastic/ecs-morgan-format

Package Overview
Dependencies
11
Maintainers
57
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.4.0

99

index.js

@@ -48,6 +48,11 @@ // Licensed to Elasticsearch B.V. under one or more contributor

// - "service.name" - the configured serviceName in the agent
// - "event.dataset" - set to "$serviceName.log" for correlation in Kibana
// - "event.dataset" - set to "$serviceName" for correlation in Kibana
// - "trace.id", "transaction.id", and "span.id" - if there is a current
// active trace when the log call is made
// Default true.
// - {String} serviceName - override `service.name` field from APM agent
// - {String} serviceVersion - override `service.version` field from APM agent
// - {String} serviceEnvironment - override `service.environment` field from APM agent
// - {String} serviceNodeName - override `service.name` field from APM agent
// - {String} eventDataset - override `event.dataset` field
//

@@ -64,6 +69,6 @@ // For backwards compatibility, the first argument can be a String or Function

// Usage: ecsFormat({ /* opts */ })
if (hasOwnProperty.call(opts, 'format')) {
if (opts.format != null) {
format = opts.format
}
if (hasOwnProperty.call(opts, 'apmIntegration')) {
if (opts.apmIntegration != null) {
apmIntegration = opts.apmIntegration

@@ -74,2 +79,6 @@ }

format = opts
opts = {}
} else {
// Usage: ecsFormat()
opts = {}
}

@@ -88,20 +97,58 @@

let serviceField
let eventField
if (apm) {
// https://github.com/elastic/apm-agent-nodejs/pull/1949 is adding
// getServiceName() in v3.11.0. Fallback to private `apm._conf`.
const extraFields = {}
// Set a number of correlation fields from (a) the given options or (b) an
// APM agent, if there is one running.
let serviceName = opts.serviceName
if (serviceName == null && apm) {
// istanbul ignore next
const serviceName = apm.getServiceName
? apm.getServiceName()
: apm._conf.serviceName
// A mis-configured APM Agent can be "started" but not have a
// "serviceName".
// istanbul ignore else
if (serviceName) {
serviceField = { name: serviceName }
eventField = { dataset: serviceName + '.log' }
}
serviceName = (apm.getServiceName
? apm.getServiceName() // added in elastic-apm-node@3.11.0
: apm._conf.serviceName) // fallback to private `_conf`
}
if (serviceName) {
extraFields['service.name'] = serviceName
}
let serviceVersion = opts.serviceVersion
// istanbul ignore next
if (serviceVersion == null && apm) {
serviceVersion = (apm.getServiceVersion
? apm.getServiceVersion() // added in elastic-apm-node@...
: apm._conf.serviceVersion) // fallback to private `_conf`
}
if (serviceVersion) {
extraFields['service.version'] = serviceVersion
}
let serviceEnvironment = opts.serviceEnvironment
if (serviceEnvironment == null && apm) {
// istanbul ignore next
serviceEnvironment = (apm.getServiceEnvironment
? apm.getServiceEnvironment() // added in elastic-apm-node@...
: apm._conf.environment) // fallback to private `_conf`
}
if (serviceEnvironment) {
extraFields['service.environment'] = serviceEnvironment
}
let serviceNodeName = opts.serviceNodeName
if (serviceNodeName == null && apm) {
// istanbul ignore next
serviceNodeName = (apm.getServiceNodeName
? apm.getServiceNodeName() // added in elastic-apm-node@...
: apm._conf.serviceNodeName) // fallback to private `_conf`
}
if (serviceNodeName) {
extraFields['service.node.name'] = serviceNodeName
}
let eventDataset = opts.eventDataset
if (eventDataset == null && serviceName) {
eventDataset = serviceName
}
if (eventDataset) {
extraFields['event.dataset'] = eventDataset
}
return function formatter (token, req, res) {

@@ -112,12 +159,6 @@ const ecsFields = {

message: fmt(token, req, res),
ecs: { version }
'ecs.version': version,
...extraFields
}
if (serviceField) {
ecsFields.service = serviceField
}
if (eventField) {
ecsFields.event = eventField
}
// https://www.elastic.co/guide/en/ecs/current/ecs-tracing.html

@@ -128,6 +169,4 @@ if (apm) {

if (tx) {
ecsFields.trace = ecsFields.trace || {}
ecsFields.trace.id = tx.traceId
ecsFields.transaction = ecsFields.transaction || {}
ecsFields.transaction.id = tx.id
ecsFields['trace.id'] = tx.traceId
ecsFields['transaction.id'] = tx.id
// Not including `span.id` because the way morgan logs (on the HTTP

@@ -134,0 +173,0 @@ // Response "finished" event), any spans during the request handler

{
"name": "@elastic/ecs-morgan-format",
"version": "1.1.0",
"version": "1.4.0",
"description": "A formatter for the morgan logger compatible with Elastic Common Schema.",

@@ -30,5 +30,7 @@ "main": "index.js",

},
"homepage": "https://github.com/elastic/ecs-logging-nodejs/blob/master/loggers/morgan/README.md",
"homepage": "https://github.com/elastic/ecs-logging-nodejs/blob/main/loggers/morgan/README.md",
"scripts": {
"test": "standard && tap --100 --timeout ${TAP_TIMEOUT:-10} test/*.test.js"
"lint": "standard",
"lint:fix": "standard --fix",
"test": "tap --timeout ${TAP_TIMEOUT:-10} test/*.test.js"
},

@@ -44,3 +46,3 @@ "engines": {

"ajv-formats": "^1.5.1",
"elastic-apm-node": "^3.10.0",
"elastic-apm-node": "^3.23.0",
"express": "^4.17.1",

@@ -50,4 +52,4 @@ "morgan": "^1.9.1",

"standard": "16.x",
"tap": "^14.x"
"tap": "^15.0.10"
}
}

@@ -5,3 +5,3 @@ <img align="right" width="auto" height="auto" src="https://www.elastic.co/static-res/images/elastic-logo-200.png">

[![Build Status](https://apm-ci.elastic.co/buildStatus/icon?job=apm-agent-nodejs%2Fecs-logging-nodejs-mbp%2Fmaster)](https://apm-ci.elastic.co/job/apm-agent-nodejs/job/ecs-logging-nodejs-mbp/job/master/) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)
[![Build Status](https://apm-ci.elastic.co/buildStatus/icon?job=apm-agent-nodejs%2Fecs-logging-nodejs-mbp%2Fmain)](https://apm-ci.elastic.co/job/apm-agent-nodejs/job/ecs-logging-nodejs-mbp/job/main/) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)

@@ -32,3 +32,3 @@ This Node.js package provides a formatter for the

app.use(morgan(ecsFormat()))
app.use(morgan(ecsFormat(/* options */)))

@@ -48,8 +48,5 @@ app.get('/', function (req, res) {

{
"@timestamp": "2021-01-16T00:03:23.279Z",
"@timestamp": "2023-10-16T22:00:33.782Z",
"log.level": "info",
"message": "::1 - - [16/Jan/2021:00:03:23 +0000] \"GET / HTTP/1.1\" 200 13 \"-\" \"curl/7.64.1\"",
"ecs": {
"version": "1.6.0"
},
"message": "::ffff:127.0.0.1 - - [16/Oct/2023:22:00:33 +0000] \"GET / HTTP/1.1\" 200 13 \"-\" \"curl/8.1.2\"",
"http": {

@@ -61,2 +58,3 @@ "version": "1.1",

"host": "localhost:3000",
"user-agent": "curl/8.1.2",
"accept": "*/*"

@@ -70,2 +68,3 @@ }

"content-type": "text/html; charset=utf-8",
"content-length": "13",
"etag": "W/\"d-HwnTDHB9U/PRbFMN1z1wps51lqk\""

@@ -83,5 +82,11 @@ },

},
"client": {
"address": "::ffff:127.0.0.1",
"ip": "::ffff:127.0.0.1",
"port": 60455
},
"user_agent": {
"original": "curl/7.64.1"
}
"original": "curl/8.1.2"
},
"ecs.version": "1.6.0"
}

@@ -88,0 +93,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc