Skip to content

report: migrate Event.Extra to Event.Contexts (sentry-go v0.46+ compat)#159

Open
denniszag wants to merge 1 commit intocockroachdb:masterfrom
denniszag:fix/sentry-go-v0.46-compat
Open

report: migrate Event.Extra to Event.Contexts (sentry-go v0.46+ compat)#159
denniszag wants to merge 1 commit intocockroachdb:masterfrom
denniszag:fix/sentry-go-v0.46-compat

Conversation

@denniszag
Copy link
Copy Markdown

@denniszag denniszag commented Apr 22, 2026

Problem

sentry-go v0.46.0 removed the Extra field from sentry.Event
(getsentry/sentry-go#1274). The merge at report/report.go:369 writes
event.Extra[k] = v and no longer compiles. Because report_api.go in
the root errors package imports the report sub-package, the whole
module fails to typecheck for every downstream consumer once they pick up
sentry-go >= v0.46.0.

Fixes #158.

Change

  • report/report.go: replace the Extra merge with Contexts; each
    extra is stored as sentry.Context{"value": v} to match the Context
    schema (map[string]interface{}).
  • report/report_test.go, fmttests/datadriven_test.go: read the new
    location in the test printers.

Collateral required to compile against sentry-go v0.46.0

  • sentry.Transport gained Close() and FlushWithContext(ctx);
    implemented on the test-only interceptingTransport in both
    report/report_test.go and fmttests/datadriven_test.go.
  • sentry.NewEvent() now pre-populates Contexts with default
    device/os/runtime/trace entries (map-shaped, not
    {"value": …}). The fmttests printer now filters to entries that
    carry a "value" sub-key, so Sentry defaults don't leak into
    fixtures. Net fixture diff is zero — same == Extra "<key>"
    output as before.
  • go.mod: bump getsentry/sentry-go to v0.46.0.
  • go directive raised from 1.23.0 to 1.25.0 because sentry-go
    v0.46.0's own go.mod declares go 1.25.0. The redundant
    toolchain go1.23.8 line is dropped. This is forced by the upstream
    dependency, not a preference; happy to split it out if the maintainers
    prefer a separate "bump Go floor" PR first.
  • fmttests/datadriven_test.go: pre-existing non-constant format string
    in a call to issuelink.UnimplementedErrorf(...) was flagged by the
    stricter go vet in the Go 1.25 toolchain and was blocking go test;
    fixed with a "%s" format specifier. Behaviour-preserving.

Verification

  • go build ./... — clean.
  • go test -race ./... — all packages pass except a pre-existing
    environmental failure in withstack.TestReportableStackTrace that
    asserts stack frame filenames contain /errors/ or /errors@ and so
    fails for any checkout located outside a path with /errors in it
    (same failure reproduces on untouched upstream/master; unrelated to
    this change).
  • fmttests/testdata/ — zero diff; the -rewrite pass produced no
    changes thanks to the "value" sub-key filter in the printer.

Alternatives considered

  1. Use Scope.SetContext inside ReportError instead of merging into
    the event directly.
    Cleaner in some ways, but breaks test code that
    reads event.Extra["error types"] after BuildSentryReport — extras
    would never land on the event. Chose direct event.Contexts merge to
    preserve the existing read-after-report pattern.
  2. Rename the printed == Extra label to == Context. Rejected to
    keep fixture diffs empty; can be renamed in a follow-up.
  3. Split "bump Go floor" into its own PR. Willing to do this if
    preferred — just say the word and I'll rebase.

This change is Reviewable

sentry-go v0.46.0 removed the Extra field from sentry.Event (see
getsentry/sentry-go#1274). ReportError merged its extraDetails map into
event.Extra, which now fails to compile against sentry-go >= v0.46.0.

Because report_api.go in the root errors package imports the report
sub-package, the typecheck failure blocks the entire module for every
downstream consumer -- not just callers of the Sentry reporting code.

Switches the per-key merge to event.Contexts, which is the documented
replacement. Each extra is stored under sentry.Context{"value": v} to
conform to the Context schema (map[string]interface{}).

Along the way:

- Adds the new Close() and FlushWithContext(ctx) methods required by the
  v0.46.0 sentry.Transport interface on the test-only interceptingTransport
  in report/report_test.go and fmttests/datadriven_test.go.
- In the fmttests printer, filters to only Contexts entries that carry
  our "value" sub-key, so Sentry's built-in default contexts
  (device/os/runtime/trace) emitted by sentry.NewEvent() do not leak into
  fixtures. Preserves the "== Extra" label -- net fixture diff is empty.
- Fixes a pre-existing non-constant-format-string call in
  fmttests/datadriven_test.go flagged by the stricter go vet in the Go
  toolchain now required by sentry-go v0.46.0.
- Bumps the go directive to 1.25.0 (drops the no-longer-needed toolchain
  line) because sentry-go v0.46.0 itself declares go 1.25.0.

Fixes cockroachdb#158
Copilot AI review requested due to automatic review settings April 22, 2026 11:26
@cockroachlabs-cla-agent
Copy link
Copy Markdown

cockroachlabs-cla-agent Bot commented Apr 22, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Sentry reporting integration to compile with getsentry/sentry-go v0.46.0+ after the removal of sentry.Event.Extra, while keeping test fixtures stable.

Changes:

  • Migrate Sentry “extra” payload merging from Event.Extra to Event.Contexts (storing each value under a "value" sub-key).
  • Update report printers/tests to read from Event.Contexts and filter out Sentry’s default contexts to avoid fixture churn.
  • Bump dependencies (notably sentry-gov0.46.0) and raise the module go version to 1.25.0; update test transports for new sentry.Transport methods.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
report/report.go Switch extra merge target from Event.Extra to Event.Contexts.
report/report_test.go Read “error types” from Contexts and add new sentry.Transport methods to the test transport.
fmttests/datadriven_test.go Keep fixtures stable by printing only "value"-wrapped contexts; fix vet issue in UnimplementedErrorf; update test transport interface methods.
go.mod Upgrade sentry-go, raise go directive to 1.25.0, adjust deps.
go.sum Dependency checksum updates for the module changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread report/report.go

if event.Contexts == nil {
event.Contexts = make(map[string]sentry.Context)
}
@rez1dent3
Copy link
Copy Markdown

@dhartunian @jeffswenson Hello. Can you help with the release?

@dhartunian
Copy link
Copy Markdown
Contributor

@rez1dent3 @denniszag is go 1.25 acceptable? Seems like that's what the sentry lib upgrade requires and I'd prefer to stay as low as necessary. I'm going to bump separately on master and then you can rebase.

@dhartunian
Copy link
Copy Markdown
Contributor

master is bumped. let me know if you run into issues. ping me when this is RFAL. Code changes looked good and I can review and cut a release tomorrow.

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.

report: v1.12.0 fails to compile against sentry-go v0.46.0 (event.Extra removed)

4 participants