Skip to content

Commit

Permalink
feat: Set sentry event extra attributes from the additional fields in…
Browse files Browse the repository at this point in the history
… zerolog data
  • Loading branch information
partizaans committed Dec 28, 2022
1 parent b5935f0 commit b3fae06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,21 @@ func (w *Writer) parseLogEvent(data []byte) (*sentry.Event, bool) {
Timestamp: now(),
Level: sentryLvl,
Logger: logger,
Extra: map[string]interface{}{},
}

err = jsonparser.ObjectEach(data, func(key, value []byte, vt jsonparser.ValueType, offset int) error {
switch string(key) {
// case zerolog.LevelFieldName, zerolog.TimestampFieldName:
case zerolog.MessageFieldName:
event.Message = bytesToStrUnsafe(value)
case zerolog.ErrorFieldName:
event.Exception = append(event.Exception, sentry.Exception{
Value: bytesToStrUnsafe(value),
Stacktrace: newStacktrace(),
})
case zerolog.LevelFieldName, zerolog.TimestampFieldName:
default:
event.Extra[string(key)] = bytesToStrUnsafe(value)
}

return nil
Expand Down
3 changes: 3 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func TestParseLogEvent(t *testing.T) {

require.Len(t, ev.Exception, 1)
assert.Equal(t, "dial timeout", ev.Exception[0].Value)

require.Len(t, ev.Extra, 1)
assert.Equal(t, "bee07485-2485-4f64-99e1-d10165884ca7", ev.Extra["requestId"])
}

func BenchmarkParseLogEvent(b *testing.B) {
Expand Down

0 comments on commit b3fae06

Please sign in to comment.