Skip to content

Commit dbbc891

Browse files
authored
fix(notifier): migrate Sentry Event.Extra to Contexts for sentry-go v0.46 (#33)
* fix(notifier): migrate Sentry Event.Extra to Contexts for sentry-go v0.46 sentry-go v0.46 removed Event.Extra. Move the extra map to event.Contexts["extra"] (Context is a map[string]interface{} alias, so the payload structure is preserved) and bump the dependency to v0.46.2. * fix(notifier): preserve existing Contexts when adding extra Initialize event.Contexts lazily and assign the "extra" key, instead of replacing the whole map, so future contexts added before this point aren't clobbered.
1 parent 21b1808 commit dbbc891

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.25.9
44

55
require (
66
github.com/airbrake/gobrake/v5 v5.6.2
7-
github.com/getsentry/sentry-go v0.43.0
7+
github.com/getsentry/sentry-go v0.46.2
88
github.com/go-coldbrew/log v0.3.0
99
github.com/go-coldbrew/options v0.3.0
1010
github.com/google/uuid v1.6.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4
215215
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
216216
github.com/fzipp/gocyclo v0.6.0 h1:lsblElZG7d3ALtGMx9fmxeTKZaLLpU8mET09yN4BBLo=
217217
github.com/fzipp/gocyclo v0.6.0/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA=
218-
github.com/getsentry/sentry-go v0.43.0 h1:XbXLpFicpo8HmBDaInk7dum18G9KSLcjZiyUKS+hLW4=
219-
github.com/getsentry/sentry-go v0.43.0/go.mod h1:XDotiNZbgf5U8bPDUAfvcFmOnMQQceESxyKaObSssW0=
218+
github.com/getsentry/sentry-go v0.46.2 h1:1jhYwrKGa3sIpo/y5iDNXS5wDoT7I1KNzMHrnK6ojns=
219+
github.com/getsentry/sentry-go v0.46.2/go.mod h1:evVbw2qotNUdYG8KxXbAdjOQWWvWIwKxpjdZZIvcIPw=
220220
github.com/ghostiam/protogetter v0.3.20 h1:oW7OPFit2FxZOpmMRPP9FffU4uUpfeE/rEdE1f+MzD0=
221221
github.com/ghostiam/protogetter v0.3.20/go.mod h1:FjIu5Yfs6FT391m+Fjp3fbAYJ6rkL/J6ySpZBfnODuI=
222222
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=

notifier/notifier.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ func buildSentryEvent(err errors.ErrorExt, level string, extra map[string]interf
295295
Level: sentryLevel,
296296
Environment: sentryEnvironment,
297297
Release: sentryRelease,
298-
Extra: extra,
299298
Exception: []sentry.Exception{
300299
{
301300
Type: reflect.TypeOf(err).String(),
@@ -305,6 +304,13 @@ func buildSentryEvent(err errors.ErrorExt, level string, extra map[string]interf
305304
},
306305
}
307306

307+
if len(extra) > 0 {
308+
if event.Contexts == nil {
309+
event.Contexts = make(map[string]sentry.Context)
310+
}
311+
event.Contexts["extra"] = extra
312+
}
313+
308314
if len(tagData) > 0 {
309315
tags := make(map[string]string)
310316
for _, t := range tagData {

notifier/notifier_sentry_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ func TestSentryExtra(t *testing.T) {
179179
if event == nil {
180180
t.Fatal("expected captured event")
181181
}
182-
if len(event.Extra) == 0 {
183-
t.Error("expected non-empty Extra on event")
182+
if len(event.Contexts["extra"]) == 0 {
183+
t.Error("expected non-empty extra context on event")
184184
}
185185
}
186186

@@ -226,8 +226,8 @@ func TestBuildSentryEvent(t *testing.T) {
226226
if event.Message != "build event test" {
227227
t.Errorf("expected message 'build event test', got %v", event.Message)
228228
}
229-
if event.Extra["key"] != "value" {
230-
t.Errorf("expected extra key=value, got %v", event.Extra["key"])
229+
if event.Contexts["extra"]["key"] != "value" {
230+
t.Errorf("expected extra key=value, got %v", event.Contexts["extra"]["key"])
231231
}
232232
if event.Tags["tag1"] != "val1" {
233233
t.Errorf("expected tag tag1=val1, got %v", event.Tags["tag1"])

0 commit comments

Comments
 (0)