Skip to content

Forward zap fields to Sentry instead of dropping them - #11

Merged
BenHall-1 merged 1 commit into
masterfrom
zap-fields
Sep 5, 2026
Merged

Forward zap fields to Sentry instead of dropping them#11
BenHall-1 merged 1 commit into
masterfrom
zap-fields

Conversation

@biast12

@biast12 biast12 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Description

ZapSentryAdapter was built on zapcore.RegisterHooks, whose callback receives a bare zapcore.Entry — a type that carries no fields. Every zap.String / zap.Uint64 / zap.Error attached to a log line was discarded before the event reached Sentry.

The result is that a production error arrives as a message, a caller and a stack, and nothing else: no guild id, no table name, no SQLSTATE. That is most of what you need to diagnose it, and it affects every service using this adapter.

Reimplemented as a real zapcore.Core that carries fields from both With() and the call site into Sentry Extra. When an error field is present it is folded into the exception value so the underlying error shows in the event title rather than the generic log message.

Check must add the wrapping core rather than the inner one, or zap writes straight through and Write never runs.

Type of Change

  • Bug fix
  • New feature
  • Breaking change

Testing

Get an error that logs in sentry, you should see the zap fields now

Checklist

  • My code follows the style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Replace the hook-based Sentry integration with a custom zap core so error logs include structured fields from both logger context and call-site fields. The new core captures caller/stack metadata, keeps environment wiring, and improves exception values by including the `error` field when present.
@biast12
biast12 requested a review from a team as a code owner September 4, 2026 16:31
@github-actions github-actions Bot added the type:bug Bug Fixes label Sep 4, 2026
@BenHall-1
BenHall-1 merged commit 38e4090 into master Sep 5, 2026
1 check passed
@BenHall-1
BenHall-1 deleted the zap-fields branch September 5, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants