Skip to content

Commit

Permalink
[extension/jsonlogencoding] use goccy/go-json instead of jsoniter
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Nov 3, 2024
1 parent 8dd2b7b commit 56436e2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .chloggen/jsoniter_replacement.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: jsonlogencodingextension

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Use goccy/go-json instead of jsoniter

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: []

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
8 changes: 4 additions & 4 deletions extension/encoding/jsonlogencodingextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"time"

jsoniter "github.com/json-iterator/go"
"github.com/goccy/go-json"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
Expand Down Expand Up @@ -37,7 +37,7 @@ func (e *jsonLogExtension) MarshalLogs(ld plog.Logs) ([]byte, error) {
default:
return nil, fmt.Errorf("Marshal: Expected 'Map' found '%v'", logRecord.Type().String())
}
buf, err := jsoniter.Marshal(raw)
buf, err := json.Marshal(raw)
if err != nil {
return nil, err
}
Expand All @@ -49,7 +49,7 @@ func (e *jsonLogExtension) UnmarshalLogs(buf []byte) (plog.Logs, error) {

// get json logs from the buffer
jsonVal := map[string]any{}
if err := jsoniter.Unmarshal(buf, &jsonVal); err != nil {
if err := json.Unmarshal(buf, &jsonVal); err != nil {
return p, err
}

Expand Down Expand Up @@ -96,7 +96,7 @@ func (e *jsonLogExtension) logProcessor(ld plog.Logs) ([]byte, error) {
}
}

return jsoniter.Marshal(logs)
return json.Marshal(logs)
}

type logBody struct {
Expand Down
1 change: 1 addition & 0 deletions extension/encoding/jsonlogencodingextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/extension/encod
go 1.22.0

require (
github.com/goccy/go-json v0.10.3
github.com/json-iterator/go v1.1.12
github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding v0.112.0
github.com/stretchr/testify v1.9.0
Expand Down
2 changes: 2 additions & 0 deletions extension/encoding/jsonlogencodingextension/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 56436e2

Please sign in to comment.