Skip to content

feat(node-core): Attach log message and fields to pino error events#21422

Merged
andreiborza merged 2 commits into
developfrom
feat/pino-error-event-context
Jun 10, 2026
Merged

feat(node-core): Attach log message and fields to pino error events#21422
andreiborza merged 2 commits into
developfrom
feat/pino-error-event-context

Conversation

@andreiborza

@andreiborza andreiborza commented Jun 10, 2026

Copy link
Copy Markdown
Member

The pinoIntegration previously captured error events with no context beyond the error itself. For logger.error(err, 'Failed to do X'), the log message was dropped entirely, as were all other fields on the log line (child logger bindings, merge object fields like request IDs, the logger name).

This PR attaches a pino context to events captured via error.levels — on both the captureException and captureMessage paths — containing:

  • the formatted log message, stored under the logger's resolved messageKey (msg by default), so user merge fields named e.g. message are never clobbered
  • all remaining fields of the serialized log line (child logger bindings, merge object fields, logger name, ...)

The serialized error itself is excluded from the context since it is already captured as the event exception, and the level/time/pid/hostname housekeeping fields are stripped, matching the existing log capture path. Custom messageKey/errorKey configurations are respected, and the fields are taken from the serialized log line, so pino redaction/serializers still apply.

Example: logger.error({ err, requestId: 'abc-123' }, 'Failed to do X') now produces an error event with

{
  "contexts": {
    "pino": {
      "name": "myapp",
      "requestId": "abc-123",
      "msg": "Failed to do X"
    }
  }
}

Fixes #17969

Closes: #17969

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@andreiborza andreiborza requested a review from a team as a code owner June 10, 2026 08:43
@andreiborza andreiborza requested review from JPeer264 and mydea and removed request for a team June 10, 2026 08:43
Comment thread packages/node-core/src/integrations/pino.ts

@nicohrubec nicohrubec left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

…text

Store the log message under the resolved messageKey so a merge-object field named 'message' is preserved.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@andreiborza andreiborza merged commit 2e83696 into develop Jun 10, 2026
528 of 532 checks passed
@andreiborza andreiborza deleted the feat/pino-error-event-context branch June 10, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom context / more fields in context for Pino errors

2 participants