Skip to content

Commit

Permalink
[chore] remove unnecessary duplicate code with AsRaw (open-telemetry#…
Browse files Browse the repository at this point in the history
…17895)

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Jan 24, 2023
1 parent 6970681 commit 7fe0dc4
Showing 1 changed file with 4 additions and 29 deletions.
33 changes: 4 additions & 29 deletions pkg/translator/loki/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,37 +131,12 @@ func EncodeLogfmt(lr plog.LogRecord, res pcommon.Resource, scope pcommon.Instrum
}

func serializeBodyJSON(body pcommon.Value) ([]byte, error) {
var str []byte
var err error
switch body.Type() {
case pcommon.ValueTypeEmpty:
if body.Type() == pcommon.ValueTypeEmpty {
// no body

case pcommon.ValueTypeStr:
str, err = json.Marshal(body.Str())

case pcommon.ValueTypeInt:
str, err = json.Marshal(body.Int())

case pcommon.ValueTypeDouble:
str, err = json.Marshal(body.Double())

case pcommon.ValueTypeBool:
str, err = json.Marshal(body.Bool())

case pcommon.ValueTypeMap:
str, err = json.Marshal(body.Map().AsRaw())

case pcommon.ValueTypeSlice:
str, err = json.Marshal(body.Slice().AsRaw())

case pcommon.ValueTypeBytes:
str, err = json.Marshal(body.Bytes().AsRaw())

default:
err = fmt.Errorf("unsuported body type to serialize")
return nil, nil
}
return str, err

return json.Marshal(body.AsRaw())
}

func bodyToKeyvals(body pcommon.Value) []interface{} {
Expand Down

0 comments on commit 7fe0dc4

Please sign in to comment.