diff --git a/extension/encoding/jsonlogencodingextension/doc.go b/extension/encoding/jsonlogencodingextension/doc.go new file mode 100644 index 000000000000..476aad42b918 --- /dev/null +++ b/extension/encoding/jsonlogencodingextension/doc.go @@ -0,0 +1,5 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +//go:generate mdatagen metadata.yaml +package jsonlogencodingextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension" diff --git a/extension/encoding/jsonlogencodingextension/generated_component_test.go b/extension/encoding/jsonlogencodingextension/generated_component_test.go new file mode 100644 index 000000000000..d2d64305f39d --- /dev/null +++ b/extension/encoding/jsonlogencodingextension/generated_component_test.go @@ -0,0 +1,68 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package jsonlogencodingextension + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/component/componenttest" + + "go.opentelemetry.io/collector/extension/extensiontest" + + "go.opentelemetry.io/collector/confmap/confmaptest" +) + +// assertNoErrorHost implements a component.Host that asserts that there were no errors. +type assertNoErrorHost struct { + component.Host + *testing.T +} + +var _ component.Host = (*assertNoErrorHost)(nil) + +// newAssertNoErrorHost returns a new instance of assertNoErrorHost. +func newAssertNoErrorHost(t *testing.T) component.Host { + return &assertNoErrorHost{ + componenttest.NewNopHost(), + t, + } +} + +func (aneh *assertNoErrorHost) ReportFatalError(err error) { + assert.NoError(aneh, err) +} + +func TestComponentLifecycle(t *testing.T) { + factory := NewFactory() + + cm, err := confmaptest.LoadConf("metadata.yaml") + require.NoError(t, err) + cfg := factory.CreateDefaultConfig() + sub, err := cm.Sub("tests::config") + require.NoError(t, err) + require.NoError(t, component.UnmarshalConfig(sub, cfg)) + + t.Run("shutdown", func(t *testing.T) { + e, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + err = e.Shutdown(context.Background()) + require.NoError(t, err) + }) + + t.Run("lifecycle", func(t *testing.T) { + + firstExt, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + require.NoError(t, firstExt.Start(context.Background(), newAssertNoErrorHost(t))) + require.NoError(t, firstExt.Shutdown(context.Background())) + + secondExt, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + require.NoError(t, secondExt.Start(context.Background(), newAssertNoErrorHost(t))) + require.NoError(t, secondExt.Shutdown(context.Background())) + }) +} diff --git a/extension/encoding/jsonlogencodingextension/go.mod b/extension/encoding/jsonlogencodingextension/go.mod index 4f9ea812ece9..6807af16ba76 100644 --- a/extension/encoding/jsonlogencodingextension/go.mod +++ b/extension/encoding/jsonlogencodingextension/go.mod @@ -7,8 +7,11 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding v0.92.0 github.com/stretchr/testify v1.8.4 go.opentelemetry.io/collector/component v0.92.1-0.20240110091511-bf804d6c4ecc + go.opentelemetry.io/collector/confmap v0.92.1-0.20240110091511-bf804d6c4ecc go.opentelemetry.io/collector/extension v0.92.1-0.20240110091511-bf804d6c4ecc go.opentelemetry.io/collector/pdata v1.0.2-0.20240110091511-bf804d6c4ecc + go.opentelemetry.io/otel/metric v1.21.0 + go.opentelemetry.io/otel/trace v1.21.0 ) require ( @@ -26,11 +29,8 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect go.opentelemetry.io/collector/config/configtelemetry v0.92.1-0.20240110091511-bf804d6c4ecc // indirect - go.opentelemetry.io/collector/confmap v0.92.1-0.20240110091511-bf804d6c4ecc // indirect go.opentelemetry.io/collector/featuregate v1.0.2-0.20240110091511-bf804d6c4ecc // indirect go.opentelemetry.io/otel v1.21.0 // indirect - go.opentelemetry.io/otel/metric v1.21.0 // indirect - go.opentelemetry.io/otel/trace v1.21.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.26.0 // indirect golang.org/x/net v0.18.0 // indirect diff --git a/extension/encoding/jsonlogencodingextension/internal/metadata/generated_status.go b/extension/encoding/jsonlogencodingextension/internal/metadata/generated_status.go index 5d46d9848a56..5346803de057 100644 --- a/extension/encoding/jsonlogencodingextension/internal/metadata/generated_status.go +++ b/extension/encoding/jsonlogencodingextension/internal/metadata/generated_status.go @@ -4,9 +4,19 @@ package metadata import ( "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/otel/metric" + "go.opentelemetry.io/otel/trace" ) const ( Type = "json_log_encoding" ExtensionStability = component.StabilityLevelDevelopment ) + +func Meter(settings component.TelemetrySettings) metric.Meter { + return settings.MeterProvider.Meter("otelcol/jsonlogencoding") +} + +func Tracer(settings component.TelemetrySettings) trace.Tracer { + return settings.TracerProvider.Tracer("otelcol/jsonlogencoding") +} diff --git a/extension/encoding/jsonlogencodingextension/metadata.yaml b/extension/encoding/jsonlogencodingextension/metadata.yaml index 81b0d53df9af..a7e328ff2d79 100644 --- a/extension/encoding/jsonlogencodingextension/metadata.yaml +++ b/extension/encoding/jsonlogencodingextension/metadata.yaml @@ -7,3 +7,6 @@ status: distributions: [] codeowners: active: [VihasMakwana, atoulme] + +tests: + config: