diff --git a/exporter/azuredataexplorerexporter/adx_exporter_test.go b/exporter/azuredataexplorerexporter/adx_exporter_test.go index 5d5427626e8a..857ab8902ebb 100644 --- a/exporter/azuredataexplorerexporter/adx_exporter_test.go +++ b/exporter/azuredataexplorerexporter/adx_exporter_test.go @@ -37,18 +37,24 @@ func TestNewExporter(t *testing.T) { LogTableMapping: "otellogs_mapping", TraceTableMapping: "oteltraces_mapping", } - texp, err := newExporter(&c, logger, metricsType, component.NewDefaultBuildInfo().Version) + mexp, err := newExporter(&c, logger, metricsType, component.NewDefaultBuildInfo().Version) assert.NoError(t, err) - assert.NotNil(t, texp) - texp, err = newExporter(&c, logger, logsType, component.NewDefaultBuildInfo().Version) + assert.NotNil(t, mexp) + assert.NoError(t, mexp.Close(context.Background())) + + lexp, err := newExporter(&c, logger, logsType, component.NewDefaultBuildInfo().Version) assert.NoError(t, err) - assert.NotNil(t, texp) - texp, err = newExporter(&c, logger, tracesType, component.NewDefaultBuildInfo().Version) + assert.NotNil(t, lexp) + assert.NoError(t, lexp.Close(context.Background())) + + texp, err := newExporter(&c, logger, tracesType, component.NewDefaultBuildInfo().Version) assert.NoError(t, err) assert.NotNil(t, texp) - texp, err = newExporter(&c, logger, 5, component.NewDefaultBuildInfo().Version) + assert.NoError(t, texp.Close(context.Background())) + + fexp, err := newExporter(&c, logger, 5, component.NewDefaultBuildInfo().Version) assert.Error(t, err) - assert.Nil(t, texp) + assert.Nil(t, fexp) } func TestMetricsDataPusherStreaming(t *testing.T) { @@ -67,6 +73,7 @@ func TestMetricsDataPusherStreaming(t *testing.T) { assert.NotNil(t, adxDataProducer) err := adxDataProducer.metricsDataPusher(context.Background(), createMetricsData(10)) assert.Error(t, err) + assert.NoError(t, adxDataProducer.Close(context.Background())) } func TestMetricsDataPusherQueued(t *testing.T) { @@ -85,6 +92,7 @@ func TestMetricsDataPusherQueued(t *testing.T) { assert.NotNil(t, adxDataProducer) err := adxDataProducer.metricsDataPusher(context.Background(), createMetricsData(10)) assert.Error(t, err) + assert.NoError(t, adxDataProducer.Close(context.Background())) } func TestLogsDataPusher(t *testing.T) { @@ -103,6 +111,7 @@ func TestLogsDataPusher(t *testing.T) { assert.NotNil(t, adxDataProducer) err := adxDataProducer.logsDataPusher(context.Background(), createLogsData()) assert.Error(t, err) + assert.NoError(t, adxDataProducer.Close(context.Background())) } func TestTracesDataPusher(t *testing.T) { @@ -121,6 +130,7 @@ func TestTracesDataPusher(t *testing.T) { assert.NotNil(t, adxDataProducer) err := adxDataProducer.tracesDataPusher(context.Background(), createTracesData()) assert.Error(t, err) + assert.NoError(t, adxDataProducer.Close(context.Background())) } func TestClose(t *testing.T) { diff --git a/exporter/azuredataexplorerexporter/go.mod b/exporter/azuredataexplorerexporter/go.mod index 2c4e34de0f74..7e39215d53de 100644 --- a/exporter/azuredataexplorerexporter/go.mod +++ b/exporter/azuredataexplorerexporter/go.mod @@ -16,6 +16,7 @@ require ( go.opentelemetry.io/collector/pdata v1.0.2-0.20240130181942-9c7177496fd5 go.opentelemetry.io/otel/metric v1.22.0 go.opentelemetry.io/otel/trace v1.22.0 + go.uber.org/goleak v1.3.0 go.uber.org/zap v1.26.0 ) diff --git a/exporter/azuredataexplorerexporter/go.sum b/exporter/azuredataexplorerexporter/go.sum index 1d2dffe1c13e..bb0b227daf42 100644 --- a/exporter/azuredataexplorerexporter/go.sum +++ b/exporter/azuredataexplorerexporter/go.sum @@ -162,6 +162,7 @@ go.opentelemetry.io/otel/sdk/metric v1.22.0/go.mod h1:KjQGeMIDlBNEOo6HvjhxIec1p/ go.opentelemetry.io/otel/trace v1.22.0 h1:Hg6pPujv0XG9QaVbGOBVHunyuLcCC3jN7WEhPx83XD0= go.opentelemetry.io/otel/trace v1.22.0/go.mod h1:RbbHXVqKES9QhzZq/fE5UnOSILqRt40a21sPw2He1xo= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= 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= diff --git a/exporter/azuredataexplorerexporter/package_test.go b/exporter/azuredataexplorerexporter/package_test.go new file mode 100644 index 000000000000..37c834b440ea --- /dev/null +++ b/exporter/azuredataexplorerexporter/package_test.go @@ -0,0 +1,17 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package azuredataexplorerexporter + +import ( + "testing" + + "go.uber.org/goleak" +) + +// The IgnoreTopFunction call prevents catching the leak generated by opencensus +// defaultWorker.Start which at this time is part of the package's init call. +// See https://github.com/census-instrumentation/opencensus-go/issues/1191 for more information. +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start")) +}