From 9f457d312dd8cbc4fe054bc5ccc52a54ade2d85e Mon Sep 17 00:00:00 2001 From: VihasMakwana <121151420+VihasMakwana@users.noreply.github.com> Date: Fri, 20 Oct 2023 04:39:07 +0530 Subject: [PATCH] [extension/encoding/jsonlogencoding] add new extension for JSON codec (#27484) **Description:** Create a new extension for JSON. This will be used in pulsarreceiver/kafkareceiver to populate the log record's map from the raw body. **Link to tracking Issue:** [6272](https://github.com/open-telemetry/opentelemetry-collector/issues/6272) --------- Co-authored-by: Dmitrii Anoshin --- .chloggen/add-json-encoding-extension.yaml | 27 +++++ .github/CODEOWNERS | 1 + .github/ISSUE_TEMPLATE/bug_report.yaml | 1 + .github/ISSUE_TEMPLATE/feature_request.yaml | 1 + .github/ISSUE_TEMPLATE/other.yaml | 1 + .github/dependabot.yml | 10 +- .../jsonlogencodingextension/Makefile | 1 + .../jsonlogencodingextension/README.md | 14 +++ .../jsonlogencodingextension/config.go | 10 ++ .../jsonlogencodingextension/extension.go | 63 ++++++++++ .../extension_test.go | 20 ++++ .../jsonlogencodingextension/factory.go | 30 +++++ .../encoding/jsonlogencodingextension/go.mod | 41 +++++++ .../encoding/jsonlogencodingextension/go.sum | 111 ++++++++++++++++++ .../internal/metadata/generated_status.go | 12 ++ .../jsonlogencodingextension/json_test.go | 39 ++++++ .../jsonlogencodingextension/metadata.yaml | 9 ++ versions.yaml | 1 + 18 files changed, 387 insertions(+), 5 deletions(-) create mode 100644 .chloggen/add-json-encoding-extension.yaml create mode 100644 extension/encoding/jsonlogencodingextension/Makefile create mode 100644 extension/encoding/jsonlogencodingextension/README.md create mode 100644 extension/encoding/jsonlogencodingextension/config.go create mode 100644 extension/encoding/jsonlogencodingextension/extension.go create mode 100644 extension/encoding/jsonlogencodingextension/extension_test.go create mode 100644 extension/encoding/jsonlogencodingextension/factory.go create mode 100644 extension/encoding/jsonlogencodingextension/go.mod create mode 100644 extension/encoding/jsonlogencodingextension/go.sum create mode 100644 extension/encoding/jsonlogencodingextension/internal/metadata/generated_status.go create mode 100644 extension/encoding/jsonlogencodingextension/json_test.go create mode 100644 extension/encoding/jsonlogencodingextension/metadata.yaml diff --git a/.chloggen/add-json-encoding-extension.yaml b/.chloggen/add-json-encoding-extension.yaml new file mode 100644 index 000000000000..00a32fce668f --- /dev/null +++ b/.chloggen/add-json-encoding-extension.yaml @@ -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: new_component + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: encoding/jsonlogencodingextension + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add a new extension to support JSON encoding (only logs) + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [6272] + +# (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: [] diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 72ae34b80148..db8d8726ebb2 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -92,6 +92,7 @@ extension/awsproxy/ @open-te extension/basicauthextension/ @open-telemetry/collector-contrib-approvers @jpkrohling @svrakitin @frzifus extension/bearertokenauthextension/ @open-telemetry/collector-contrib-approvers @jpkrohling @pavankrish123 @frzifus extension/encoding/jaegerencodingextension/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy @atoulme +extension/encoding/jsonlogencodingextension/ @open-telemetry/collector-contrib-approvers @VihasMakwana @atoulme extension/encoding/textencodingextension/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy @atoulme extension/headerssetterextension/ @open-telemetry/collector-contrib-approvers @jpkrohling extension/healthcheckextension/ @open-telemetry/collector-contrib-approvers @jpkrohling diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 6eaafc61824c..4d0477440eaf 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -84,6 +84,7 @@ body: - extension/basicauth - extension/bearertokenauth - extension/encoding/jaegerencoding + - extension/encoding/jsonlogencoding - extension/encoding/textencoding - extension/headerssetter - extension/healthcheck diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml index 814303a8cb55..a494d4bcc2d3 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -78,6 +78,7 @@ body: - extension/basicauth - extension/bearertokenauth - extension/encoding/jaegerencoding + - extension/encoding/jsonlogencoding - extension/encoding/textencoding - extension/headerssetter - extension/healthcheck diff --git a/.github/ISSUE_TEMPLATE/other.yaml b/.github/ISSUE_TEMPLATE/other.yaml index f9d2390eb1c9..23f58f8cb6da 100644 --- a/.github/ISSUE_TEMPLATE/other.yaml +++ b/.github/ISSUE_TEMPLATE/other.yaml @@ -78,6 +78,7 @@ body: - extension/basicauth - extension/bearertokenauth - extension/encoding/jaegerencoding + - extension/encoding/jsonlogencoding - extension/encoding/textencoding - extension/headerssetter - extension/healthcheck diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 615cb65c803b..61463b8c9441 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,6 +7,11 @@ updates: schedule: interval: "weekly" day: "wednesday" + - package-ecosystem: "gomod" + directory: "/cmd/configschema" + schedule: + interval: "weekly" + day: "wednesday" - package-ecosystem: "gomod" directory: "/cmd/otelcontribcol" schedule: @@ -267,11 +272,6 @@ updates: schedule: interval: "weekly" day: "wednesday" - - package-ecosystem: "gomod" - directory: "/exporter/syslogexporter" - schedule: - interval: "weekly" - day: "wednesday" - package-ecosystem: "gomod" directory: "/exporter/tanzuobservabilityexporter" schedule: diff --git a/extension/encoding/jsonlogencodingextension/Makefile b/extension/encoding/jsonlogencodingextension/Makefile new file mode 100644 index 000000000000..bdd863a203be --- /dev/null +++ b/extension/encoding/jsonlogencodingextension/Makefile @@ -0,0 +1 @@ +include ../../../Makefile.Common diff --git a/extension/encoding/jsonlogencodingextension/README.md b/extension/encoding/jsonlogencodingextension/README.md new file mode 100644 index 000000000000..660974f90682 --- /dev/null +++ b/extension/encoding/jsonlogencodingextension/README.md @@ -0,0 +1,14 @@ +# JSON Log encoding extension + + +| Status | | +| ------------- |-----------| +| Stability | [development] | +| Distributions | [] | +| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aextension%2Fjsonlogencoding%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aextension%2Fjsonlogencoding) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aextension%2Fjsonlogencoding%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aextension%2Fjsonlogencoding) | +| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@VihasMakwana](https://www.github.com/VihasMakwana), [@atoulme](https://www.github.com/atoulme) | + +[development]: https://github.com/open-telemetry/opentelemetry-collector#development + + +The `jsonlog` encoding extension is used to marshal/unmarshal JSON log body, ignoring other log fields. \ No newline at end of file diff --git a/extension/encoding/jsonlogencodingextension/config.go b/extension/encoding/jsonlogencodingextension/config.go new file mode 100644 index 000000000000..fe2a9107f937 --- /dev/null +++ b/extension/encoding/jsonlogencodingextension/config.go @@ -0,0 +1,10 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package jsonlogencodingextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension" + +type Config struct{} + +func (c *Config) Validate() error { + return nil +} diff --git a/extension/encoding/jsonlogencodingextension/extension.go b/extension/encoding/jsonlogencodingextension/extension.go new file mode 100644 index 000000000000..ca9987ed3b7a --- /dev/null +++ b/extension/encoding/jsonlogencodingextension/extension.go @@ -0,0 +1,63 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package jsonlogencodingextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension" + +import ( + "context" + "fmt" + "time" + + jsoniter "github.com/json-iterator/go" + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/plog" +) + +type jsonLogExtension struct { +} + +func (e *jsonLogExtension) MarshalLogs(ld plog.Logs) ([]byte, error) { + logRecord := ld.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Body() + var raw map[string]any + switch logRecord.Type() { + case pcommon.ValueTypeMap: + raw = logRecord.Map().AsRaw() + default: + return nil, fmt.Errorf("Marshal: Expected 'Map' found '%v'", logRecord.Type().String()) + } + buf, err := jsoniter.Marshal(raw) + if err != nil { + return nil, err + } + return buf, nil + +} + +func (e *jsonLogExtension) UnmarshalLogs(buf []byte) (plog.Logs, error) { + p := plog.NewLogs() + + // get json logs from the buffer + jsonVal := map[string]interface{}{} + if err := jsoniter.Unmarshal(buf, &jsonVal); err != nil { + return p, err + } + + // create a new log record + logRecords := p.ResourceLogs().AppendEmpty().ScopeLogs().AppendEmpty().LogRecords().AppendEmpty() + logRecords.SetObservedTimestamp(pcommon.NewTimestampFromTime(time.Now())) + + // Set the unmarshaled jsonVal as the body of the log record + if err := logRecords.Body().SetEmptyMap().FromRaw(jsonVal); err != nil { + return p, err + } + return p, nil +} + +func (e *jsonLogExtension) Start(_ context.Context, _ component.Host) error { + return nil +} + +func (e *jsonLogExtension) Shutdown(_ context.Context) error { + return nil +} diff --git a/extension/encoding/jsonlogencodingextension/extension_test.go b/extension/encoding/jsonlogencodingextension/extension_test.go new file mode 100644 index 000000000000..ef6926e6d75c --- /dev/null +++ b/extension/encoding/jsonlogencodingextension/extension_test.go @@ -0,0 +1,20 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package jsonlogencodingextension + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" +) + +func TestExtension_Start_Shutdown(t *testing.T) { + j := &jsonLogExtension{} + err := j.Start(context.Background(), componenttest.NewNopHost()) + require.NoError(t, err) + err = j.Shutdown(context.Background()) + require.NoError(t, err) +} diff --git a/extension/encoding/jsonlogencodingextension/factory.go b/extension/encoding/jsonlogencodingextension/factory.go new file mode 100644 index 000000000000..e911dec1958a --- /dev/null +++ b/extension/encoding/jsonlogencodingextension/factory.go @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package jsonlogencodingextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension" + +import ( + "context" + + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/extension" + + "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension/internal/metadata" +) + +func NewFactory() extension.Factory { + return extension.NewFactory( + metadata.Type, + createDefaultConfig, + createExtension, + metadata.ExtensionStability, + ) +} + +func createExtension(_ context.Context, _ extension.CreateSettings, _ component.Config) (extension.Extension, error) { + return &jsonLogExtension{}, nil +} + +func createDefaultConfig() component.Config { + return &Config{} +} diff --git a/extension/encoding/jsonlogencodingextension/go.mod b/extension/encoding/jsonlogencodingextension/go.mod new file mode 100644 index 000000000000..598fbc95a438 --- /dev/null +++ b/extension/encoding/jsonlogencodingextension/go.mod @@ -0,0 +1,41 @@ +module github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension + +go 1.20 + +require ( + github.com/json-iterator/go v1.1.12 + github.com/stretchr/testify v1.8.4 + go.opentelemetry.io/collector/component v0.87.1-0.20231017160804-ec0725874313 + go.opentelemetry.io/collector/extension v0.87.1-0.20231017160804-ec0725874313 + go.opentelemetry.io/collector/pdata v1.0.0-rcv0016.0.20231017160804-ec0725874313 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/knadh/koanf/maps v0.1.1 // indirect + github.com/knadh/koanf/providers/confmap v0.1.0 // indirect + github.com/knadh/koanf/v2 v2.0.1 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + go.opentelemetry.io/collector/config/configtelemetry v0.87.1-0.20231017160804-ec0725874313 // indirect + go.opentelemetry.io/collector/confmap v0.87.1-0.20231017160804-ec0725874313 // indirect + go.opentelemetry.io/collector/featuregate v1.0.0-rcv0016.0.20231017160804-ec0725874313 // indirect + go.opentelemetry.io/otel v1.19.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect + go.uber.org/multierr v1.11.0 // indirect + go.uber.org/zap v1.26.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect + google.golang.org/grpc v1.59.0 // indirect + google.golang.org/protobuf v1.31.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/extension/encoding/jsonlogencodingextension/go.sum b/extension/encoding/jsonlogencodingextension/go.sum new file mode 100644 index 000000000000..7e3d62aa6d20 --- /dev/null +++ b/extension/encoding/jsonlogencodingextension/go.sum @@ -0,0 +1,111 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NIs= +github.com/knadh/koanf/maps v0.1.1/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI= +github.com/knadh/koanf/providers/confmap v0.1.0 h1:gOkxhHkemwG4LezxxN8DMOFopOPghxRVp7JbIvdvqzU= +github.com/knadh/koanf/providers/confmap v0.1.0/go.mod h1:2uLhxQzJnyHKfxG927awZC7+fyHFdQkd697K4MdLnIU= +github.com/knadh/koanf/v2 v2.0.1 h1:1dYGITt1I23x8cfx8ZnldtezdyaZtfAuRtIFOiRzK7g= +github.com/knadh/koanf/v2 v2.0.1/go.mod h1:ZeiIlIDXTE7w1lMT6UVcNiRAS2/rCeLn/GdLNvY1Dus= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 h1:BpfhmLKZf+SjVanKKhCgf3bg+511DmU9eDQTen7LLbY= +github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opentelemetry.io/collector/component v0.87.1-0.20231017160804-ec0725874313 h1:rQ7OKu7fxWDfNFKU8q7mMr8NVBLY0t3IFlpyglEKnm4= +go.opentelemetry.io/collector/component v0.87.1-0.20231017160804-ec0725874313/go.mod h1:UHArfJc+pijiYXifkEWcq5bNYZyERvGDUQt3r2RnSuU= +go.opentelemetry.io/collector/config/configtelemetry v0.87.1-0.20231017160804-ec0725874313 h1:VugEaPnOkWZ8n5hYlX6lrot0qLXtv9Objvsh8gh/D84= +go.opentelemetry.io/collector/config/configtelemetry v0.87.1-0.20231017160804-ec0725874313/go.mod h1:+LAXM5WFMW/UbTlAuSs6L/W72WC+q8TBJt/6z39FPOU= +go.opentelemetry.io/collector/confmap v0.87.1-0.20231017160804-ec0725874313 h1:IRtWnNC6yOeBBk/2sEq71eQDkdIqPTgPrC/A/CxsG84= +go.opentelemetry.io/collector/confmap v0.87.1-0.20231017160804-ec0725874313/go.mod h1:inqYRP70+bMrUwGGnuhcWyyufxyU3VQT6rl3/EX0f+g= +go.opentelemetry.io/collector/extension v0.87.1-0.20231017160804-ec0725874313 h1:5uUxUkoZkRMVnSNQCKE+hDtg5IY0fvd1D3XYbxpFKDc= +go.opentelemetry.io/collector/extension v0.87.1-0.20231017160804-ec0725874313/go.mod h1:GBJAx4G3Pax5yG06pl6RL9q1fHRnW7/7uP20Zz9Ne/w= +go.opentelemetry.io/collector/featuregate v1.0.0-rcv0016.0.20231017160804-ec0725874313 h1:wzVr3eByIkJnmdmKzfecjhLNGq6bC0rdM4E5rKNlpag= +go.opentelemetry.io/collector/featuregate v1.0.0-rcv0016.0.20231017160804-ec0725874313/go.mod h1:fLmJMf1AoHttkF8p5oJAc4o5ZpHu8yO5XYJ7gbLCLzo= +go.opentelemetry.io/collector/pdata v1.0.0-rcv0016.0.20231017160804-ec0725874313 h1:xVMqIXrZLxP2jH1iRVfvjuVdHRz6TOLzjdz9fyzyZ9I= +go.opentelemetry.io/collector/pdata v1.0.0-rcv0016.0.20231017160804-ec0725874313/go.mod h1:jAsXW4hquZt7NnVqWfFvO8zP0eg9fyCTLqTd9il/MJY= +go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= +go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY= +go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE= +go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8= +go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg= +go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo= +go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= +go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= +google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= +google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/extension/encoding/jsonlogencodingextension/internal/metadata/generated_status.go b/extension/encoding/jsonlogencodingextension/internal/metadata/generated_status.go new file mode 100644 index 000000000000..5d46d9848a56 --- /dev/null +++ b/extension/encoding/jsonlogencodingextension/internal/metadata/generated_status.go @@ -0,0 +1,12 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package metadata + +import ( + "go.opentelemetry.io/collector/component" +) + +const ( + Type = "json_log_encoding" + ExtensionStability = component.StabilityLevelDevelopment +) diff --git a/extension/encoding/jsonlogencodingextension/json_test.go b/extension/encoding/jsonlogencodingextension/json_test.go new file mode 100644 index 000000000000..8b802cfc211f --- /dev/null +++ b/extension/encoding/jsonlogencodingextension/json_test.go @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package jsonlogencodingextension + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/pdata/plog" +) + +func TestMarshalUnmarshal(t *testing.T) { + t.Parallel() + e := &jsonLogExtension{} + json := `{"example":"example valid json to test that the unmarshaler is correctly returning a plog value"}` + ld, err := e.UnmarshalLogs([]byte(json)) + assert.NoError(t, err) + assert.Equal(t, 1, ld.LogRecordCount()) + + buf, err := e.MarshalLogs(ld) + assert.NoError(t, err) + assert.True(t, len(buf) > 0) + assert.Equal(t, json, string(buf)) +} + +func TestInvalidMarshal(t *testing.T) { + e := &jsonLogExtension{} + p := plog.NewLogs() + p.ResourceLogs().AppendEmpty().ScopeLogs().AppendEmpty().LogRecords().AppendEmpty().Body().SetStr("NOT A MAP") + _, err := e.MarshalLogs(p) + assert.ErrorContains(t, err, "Marshal: Expected 'Map' found 'Str'") +} + +func TestInvalidUnmarshal(t *testing.T) { + e := &jsonLogExtension{} + _, err := e.UnmarshalLogs([]byte("NOT A JSON")) + assert.ErrorContains(t, err, "ReadMapCB: expect { or n, but found N") +} diff --git a/extension/encoding/jsonlogencodingextension/metadata.yaml b/extension/encoding/jsonlogencodingextension/metadata.yaml new file mode 100644 index 000000000000..81b0d53df9af --- /dev/null +++ b/extension/encoding/jsonlogencodingextension/metadata.yaml @@ -0,0 +1,9 @@ +type: json_log_encoding + +status: + class: extension + stability: + development: [extension] + distributions: [] + codeowners: + active: [VihasMakwana, atoulme] diff --git a/versions.yaml b/versions.yaml index 18f66f8550de..e8aaf2c434cb 100644 --- a/versions.yaml +++ b/versions.yaml @@ -70,6 +70,7 @@ module-sets: - github.com/open-telemetry/opentelemetry-collector-contrib/extension/basicauthextension - github.com/open-telemetry/opentelemetry-collector-contrib/extension/bearertokenauthextension - github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jaegerencodingextension + - github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension - github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension - github.com/open-telemetry/opentelemetry-collector-contrib/extension/headerssetterextension - github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension