-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: prefer dotted field names; drop ".log" suffix on `event.datase…
…t` (#150) - Change to adding dotted field names (`"ecs.version": "1.6.0"`), rather than namespaced fields (`"ecs": {"version": "1.6.0"}`) for most fields. This is supported by the ecs-logging spec, and arguably preferred in the ECS logging docs. It is also what the ecs-logging-java libraries do. The resulting output is slightly shorter, and accidental collisions with user fields is less likely. - Stop adding ".log" suffix to `event.dataset` field. Closes: #95
- Loading branch information
Showing
23 changed files
with
256 additions
and
448 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ try { | |
// APM agent is detected, then log records will include the following | ||
// fields: | ||
// - "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. | ||
|
@@ -82,21 +82,17 @@ function ecsFormat (opts) { | |
apm = elasticApm | ||
} | ||
|
||
let serviceField | ||
let eventField | ||
const extraFields = {} | ||
if (apm) { | ||
// https://github.com/elastic/apm-agent-nodejs/pull/1949 is adding | ||
// getServiceName() in v3.11.0. Fallback to private `apm._conf`. | ||
// istanbul ignore next | ||
const serviceName = apm.getServiceName | ||
? apm.getServiceName() | ||
? apm.getServiceName() // added in [email protected] | ||
: apm._conf.serviceName | ||
// A mis-configured APM Agent can be "started" but not have a | ||
// "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' } | ||
extraFields['service.name'] = serviceName | ||
extraFields['event.dataset'] = serviceName | ||
} | ||
} | ||
|
||
|
@@ -105,25 +101,17 @@ function ecsFormat (opts) { | |
'@timestamp': new Date().toISOString(), | ||
'log.level': res.statusCode < 500 ? 'info' : 'error', | ||
message: fmt(token, req, res), | ||
ecs: { version } | ||
} | ||
|
||
if (serviceField) { | ||
ecsFields.service = serviceField | ||
} | ||
if (eventField) { | ||
ecsFields.event = eventField | ||
'ecs.version': version, | ||
...extraFields | ||
} | ||
|
||
// https://www.elastic.co/guide/en/ecs/current/ecs-tracing.html | ||
if (apm) { | ||
const tx = apm.currentTransaction | ||
// istanbul ignore else | ||
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 | ||
// Response "finished" event), any spans during the request handler | ||
// are no longer active. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.