feat: include error.id and error.code in formatError, @elastic/ecs-helpers@2.2.0#233
Open
edosrecki wants to merge 1 commit into
Open
feat: include error.id and error.code in formatError, @elastic/ecs-helpers@2.2.0#233edosrecki wants to merge 1 commit into
edosrecki wants to merge 1 commit into
Conversation
…lpers@2.2.0
The ECS error field set includes `error.id` and `error.code` alongside
`error.type`, `error.message`, and `error.stack_trace`. `formatError()`
was only emitting the latter three, so any `id`/`code` properties on the
source `Error` (for example Node system errors with `err.code === 'ENOENT'`)
were silently dropped.
Copy these fields through when they are defined on the source error,
guarded so plain errors keep the same minimal shape as before. Values
are passed through as-is, matching the existing behavior in
ecs-winston-format (which already surfaces `err.code` via
`Object.assign({}, err)`).
Picked up automatically by @elastic/ecs-pino-format via its call to
formatError. ecs-winston-format and ecs-morgan-format do not call
formatError and are unaffected.
See: https://www.elastic.co/docs/reference/ecs/ecs-error
🤖 GitHub commentsJust comment with:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
The ECS error field set includes
error.idanderror.codealongsideerror.type,error.message, anderror.stack_trace.formatError()was only emitting the latter three, so anyid/codeproperties on the sourceError(for example Node system errors witherr.code === 'ENOENT') were silently dropped.How?
Copy
err.codeanderr.idonto the emittederrorobject when they are defined on the sourceError, guarded so plain errors keep the same minimal shape as before. Values pass through as-is — matching the existing behavior inecs-winston-format, which already surfaceserr.codeviaObject.assign({}, err).Picked up automatically by
@elastic/ecs-pino-formatvia its call toformatError.ecs-winston-formatandecs-morgan-formatdo not callformatErrorand are unaffected. Bumped@elastic/ecs-helperstov2.2.0and added a matching CHANGELOG entry.