Skip to content

Commit

Permalink
drop unsafe bytes to str conv
Browse files Browse the repository at this point in the history
  • Loading branch information
archdx committed Jul 13, 2024
1 parent dd4d17f commit 5ae2fbd
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"net/http"
"time"
"unsafe"

"github.com/buger/jsonparser"
"github.com/getsentry/sentry-go"
Expand Down Expand Up @@ -147,17 +146,17 @@ func (w *Writer) parseLogEvent(data []byte) (*sentry.Event, bool) {
}

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

return nil
Expand Down Expand Up @@ -202,10 +201,6 @@ outer:
return st
}

func bytesToStrUnsafe(data []byte) string {
return *(*string)(unsafe.Pointer(&data))
}

// WriterOption configures sentry events writer.
type WriterOption interface {
apply(*config)
Expand Down

0 comments on commit 5ae2fbd

Please sign in to comment.