From d464abf1f34107553944826dd4999e7fb5c58fed Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Mon, 4 Aug 2025 21:48:04 +0200 Subject: [PATCH] chore: enable unused-parameter rule from revive (#7122) #### Description Enable and fixes [unused-parameter](https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#unused-parameter) rule from revive Signed-off-by: Matthieu MOREL --- .golangci.yml | 1 + attribute/filter.go | 4 +- attribute/set_test.go | 6 +- bridge/opencensus/internal/span.go | 4 +- bridge/opencensus/metric.go | 2 +- bridge/opentracing/bridge.go | 8 +-- bridge/opentracing/bridge_grpc_test.go | 2 +- bridge/opentracing/bridge_test.go | 8 +-- bridge/opentracing/mix_test.go | 20 +++---- bridge/opentracing/mock.go | 4 +- bridge/opentracing/provider_test.go | 2 +- bridge/opentracing/wrapper.go | 2 +- .../otlp/otlplog/otlploggrpc/client_test.go | 2 +- .../otlp/otlplog/otlploggrpc/exporter.go | 2 +- .../otlp/otlplog/otlploggrpc/exporter_test.go | 2 +- .../otlp/otlplog/otlploghttp/exporter.go | 4 +- exporters/otlp/otlptrace/exporter_test.go | 6 +- exporters/prometheus/config_test.go | 2 +- exporters/prometheus/exporter.go | 2 +- exporters/prometheus/exporter_test.go | 4 +- exporters/stdout/stdouttrace/trace.go | 2 +- internal/baggage/context_test.go | 4 +- internal/global/alternate_meter_test.go | 30 +++++----- internal/global/instruments_test.go | 32 +++++------ internal/global/internal_logging_test.go | 2 +- internal/global/meter_test.go | 6 +- internal/global/meter_types_test.go | 55 +++++++++---------- internal/global/trace_test.go | 14 ++--- log/internal/global/log_test.go | 4 +- log/logtest/recorder_test.go | 2 +- metric/asyncfloat64_test.go | 2 +- metric/asyncint64_test.go | 2 +- metric/example_test.go | 8 +-- metric/instrument_test.go | 2 +- metric_test.go | 2 +- propagation/propagation_test.go | 4 +- propagation/propagators_test.go | 6 +- sdk/log/bench_test.go | 18 +++--- sdk/log/example_test.go | 6 +- sdk/log/exporter_test.go | 6 +- sdk/log/logtest/example_test.go | 2 +- sdk/log/provider_test.go | 4 +- sdk/log/simple_test.go | 2 +- sdk/metric/config_test.go | 14 ++--- sdk/metric/exemplar/filter.go | 4 +- sdk/metric/exemplar/fixed_size_reservoir.go | 2 +- sdk/metric/exemplar/histogram_reservoir.go | 2 +- sdk/metric/instrument.go | 4 +- sdk/metric/manual_reader_test.go | 2 +- sdk/metric/meter_test.go | 36 ++++++------ sdk/metric/periodic_reader_test.go | 2 +- sdk/metric/pipeline_registry_test.go | 20 +++---- sdk/metric/pipeline_test.go | 8 +-- sdk/metric/provider_test.go | 8 +-- sdk/metric/reader_test.go | 8 +-- sdk/metric/view_test.go | 2 +- sdk/resource/builtin.go | 2 +- sdk/resource/container.go | 2 +- sdk/resource/container_test.go | 4 +- sdk/resource/host_id.go | 2 +- sdk/resource/host_id_test.go | 4 +- sdk/resource/os.go | 4 +- sdk/resource/os_unix_test.go | 2 +- sdk/resource/process.go | 16 +++--- sdk/resource/resource_test.go | 2 +- sdk/trace/batch_span_processor.go | 2 +- sdk/trace/benchmark_test.go | 2 +- sdk/trace/evictedqueue_test.go | 2 +- sdk/trace/id_generator.go | 4 +- sdk/trace/provider_test.go | 2 +- sdk/trace/simple_span_processor_test.go | 2 +- sdk/trace/span_processor_test.go | 2 +- sdk/trace/trace_test.go | 6 +- trace/noop.go | 2 +- trace_test.go | 2 +- 75 files changed, 239 insertions(+), 239 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 2a48f4543..efcbfaa99 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -181,6 +181,7 @@ linters: - fmt.Print - fmt.Printf - fmt.Println + - name: unused-parameter - name: unnecessary-stmt - name: use-any - name: useless-break diff --git a/attribute/filter.go b/attribute/filter.go index 74e011a9c..624ebbe38 100644 --- a/attribute/filter.go +++ b/attribute/filter.go @@ -16,7 +16,7 @@ type Filter func(KeyValue) bool // If keys is empty a deny-all filter is returned. func NewAllowKeysFilter(keys ...Key) Filter { if len(keys) == 0 { - return func(kv KeyValue) bool { return false } + return func(KeyValue) bool { return false } } allowed := make(map[Key]struct{}, len(keys)) @@ -35,7 +35,7 @@ func NewAllowKeysFilter(keys ...Key) Filter { // If keys is empty an allow-all filter is returned. func NewDenyKeysFilter(keys ...Key) Filter { if len(keys) == 0 { - return func(kv KeyValue) bool { return true } + return func(KeyValue) bool { return true } } forbid := make(map[Key]struct{}, len(keys)) diff --git a/attribute/set_test.go b/attribute/set_test.go index c73f0212c..5f141026f 100644 --- a/attribute/set_test.go +++ b/attribute/set_test.go @@ -214,21 +214,21 @@ func TestFiltering(t *testing.T) { { name: "None", in: []attribute.KeyValue{a, b, c}, - filter: func(kv attribute.KeyValue) bool { return false }, + filter: func(attribute.KeyValue) bool { return false }, kept: nil, drop: []attribute.KeyValue{a, b, c}, }, { name: "All", in: []attribute.KeyValue{a, b, c}, - filter: func(kv attribute.KeyValue) bool { return true }, + filter: func(attribute.KeyValue) bool { return true }, kept: []attribute.KeyValue{a, b, c}, drop: nil, }, { name: "Empty", in: []attribute.KeyValue{}, - filter: func(kv attribute.KeyValue) bool { return true }, + filter: func(attribute.KeyValue) bool { return true }, kept: nil, drop: nil, }, diff --git a/bridge/opencensus/internal/span.go b/bridge/opencensus/internal/span.go index 7ac424a4c..4e7e1c35b 100644 --- a/bridge/opencensus/internal/span.go +++ b/bridge/opencensus/internal/span.go @@ -80,7 +80,7 @@ func (s *Span) Annotatef(attributes []octrace.Attribute, format string, a ...any } // AddMessageSendEvent adds a message send event to this span. -func (s *Span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize int64) { +func (s *Span) AddMessageSendEvent(_, uncompressedByteSize, compressedByteSize int64) { s.otelSpan.AddEvent(MessageSendEvent, trace.WithAttributes( attribute.KeyValue{ @@ -95,7 +95,7 @@ func (s *Span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedBy } // AddMessageReceiveEvent adds a message receive event to this span. -func (s *Span) AddMessageReceiveEvent(messageID, uncompressedByteSize, compressedByteSize int64) { +func (s *Span) AddMessageReceiveEvent(_, uncompressedByteSize, compressedByteSize int64) { s.otelSpan.AddEvent(MessageReceiveEvent, trace.WithAttributes( attribute.KeyValue{ diff --git a/bridge/opencensus/metric.go b/bridge/opencensus/metric.go index f4c8408db..5bf343b91 100644 --- a/bridge/opencensus/metric.go +++ b/bridge/opencensus/metric.go @@ -23,7 +23,7 @@ type MetricProducer struct { // NewMetricProducer returns a metric.Producer that fetches metrics from // OpenCensus. -func NewMetricProducer(opts ...MetricOption) *MetricProducer { +func NewMetricProducer(...MetricOption) *MetricProducer { return &MetricProducer{ manager: metricproducer.GlobalManager(), } diff --git a/bridge/opentracing/bridge.go b/bridge/opentracing/bridge.go index 08cb49852..6d0fc45d0 100644 --- a/bridge/opentracing/bridge.go +++ b/bridge/opentracing/bridge.go @@ -321,10 +321,10 @@ var ( func NewBridgeTracer() *BridgeTracer { return &BridgeTracer{ setTracer: bridgeSetTracer{ - warningHandler: func(msg string) {}, + warningHandler: func(string) {}, otelTracer: noopTracer, }, - warningHandler: func(msg string) {}, + warningHandler: func(string) {}, propagator: nil, } } @@ -832,12 +832,12 @@ func newTextMapWrapperForInject(carrier any) (*textMapWrapper, error) { type textMapWriter struct{} -func (t *textMapWriter) Set(key, value string) { +func (t *textMapWriter) Set(string, string) { // maybe print a warning log. } type textMapReader struct{} -func (t *textMapReader) ForeachKey(handler func(key, val string) error) error { +func (t *textMapReader) ForeachKey(func(string, string) error) error { return nil // maybe print a warning log. } diff --git a/bridge/opentracing/bridge_grpc_test.go b/bridge/opentracing/bridge_grpc_test.go index d1b234b7f..7b3d6be84 100644 --- a/bridge/opentracing/bridge_grpc_test.go +++ b/bridge/opentracing/bridge_grpc_test.go @@ -22,7 +22,7 @@ import ( type testGRPCServer struct{} -func (*testGRPCServer) UnaryCall(ctx context.Context, r *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { +func (*testGRPCServer) UnaryCall(_ context.Context, r *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { return &testpb.SimpleResponse{Payload: r.Payload * 2}, nil } diff --git a/bridge/opentracing/bridge_test.go b/bridge/opentracing/bridge_test.go index 204644017..bab6b5a23 100644 --- a/bridge/opentracing/bridge_test.go +++ b/bridge/opentracing/bridge_test.go @@ -134,7 +134,7 @@ var ( type testTextMapPropagator struct{} -func (t testTextMapPropagator) Inject(ctx context.Context, carrier propagation.TextMapCarrier) { +func (t testTextMapPropagator) Inject(_ context.Context, carrier propagation.TextMapCarrier) { carrier.Set(testHeader, traceID.String()+":"+spanID.String()) // Test for panic @@ -370,7 +370,7 @@ type nonDeferWrapperTracer struct { } func (t *nonDeferWrapperTracer) Start( - ctx context.Context, + _ context.Context, name string, opts ...trace.SpanStartOption, ) (context.Context, trace.Span) { @@ -393,7 +393,7 @@ func TestBridgeTracer_StartSpan(t *testing.T) { }, { name: "with wrapper tracer set", - before: func(t *testing.T, bridge *BridgeTracer) { + before: func(_ *testing.T, bridge *BridgeTracer) { wTracer := NewWrapperTracer(bridge, otel.Tracer("test")) bridge.SetOpenTelemetryTracer(wTracer) }, @@ -401,7 +401,7 @@ func TestBridgeTracer_StartSpan(t *testing.T) { }, { name: "with a non-deferred wrapper tracer", - before: func(t *testing.T, bridge *BridgeTracer) { + before: func(_ *testing.T, bridge *BridgeTracer) { wTracer := &nonDeferWrapperTracer{ NewWrapperTracer(bridge, otel.Tracer("test")), } diff --git a/bridge/opentracing/mix_test.go b/bridge/opentracing/mix_test.go index da74f5e53..aa868e7d1 100644 --- a/bridge/opentracing/mix_test.go +++ b/bridge/opentracing/mix_test.go @@ -128,7 +128,7 @@ func newSimpleTest() *simpleTest { } } -func (st *simpleTest) setup(t *testing.T, tracer *mockTracer) { +func (st *simpleTest) setup(_ *testing.T, tracer *mockTracer) { tracer.SpareTraceIDs = append(tracer.SpareTraceIDs, st.traceID) tracer.SpareSpanIDs = append(tracer.SpareSpanIDs, st.spanIDs...) } @@ -145,7 +145,7 @@ func (st *simpleTest) runOTOtelOT(t *testing.T, ctx context.Context) { runOTOtelOT(t, ctx, "simple", st.noop) } -func (st *simpleTest) noop(t *testing.T, ctx context.Context) context.Context { +func (st *simpleTest) noop(_ *testing.T, ctx context.Context) context.Context { return ctx } @@ -166,7 +166,7 @@ func newCurrentActiveSpanTest() *currentActiveSpanTest { } } -func (cast *currentActiveSpanTest) setup(t *testing.T, tracer *mockTracer) { +func (cast *currentActiveSpanTest) setup(_ *testing.T, tracer *mockTracer) { tracer.SpareTraceIDs = append(tracer.SpareTraceIDs, cast.traceID) tracer.SpareSpanIDs = append(tracer.SpareSpanIDs, cast.spanIDs...) @@ -221,7 +221,7 @@ func (cast *currentActiveSpanTest) runOTOtelOT(t *testing.T, ctx context.Context runOTOtelOT(t, ctx, "cast", cast.recordSpans) } -func (cast *currentActiveSpanTest) recordSpans(t *testing.T, ctx context.Context) context.Context { +func (cast *currentActiveSpanTest) recordSpans(_ *testing.T, ctx context.Context) context.Context { spanID := trace.SpanContextFromContext(ctx).SpanID() cast.recordedCurrentOtelSpanIDs = append(cast.recordedCurrentOtelSpanIDs, spanID) @@ -273,14 +273,14 @@ func newContextIntactTest() *contextIntactTest { } } -func (coin *contextIntactTest) setup(t *testing.T, tracer *mockTracer) { +func (coin *contextIntactTest) setup(_ *testing.T, tracer *mockTracer) { tracer.SpareContextKeyValues = append(tracer.SpareContextKeyValues, coin.contextKeyValues...) coin.recordedContextValues = nil coin.recordIdx = 0 } -func (coin *contextIntactTest) check(t *testing.T, tracer *mockTracer) { +func (coin *contextIntactTest) check(t *testing.T, _ *mockTracer) { if len(coin.recordedContextValues) != len(coin.contextKeyValues) { t.Errorf( "Expected to have %d recorded context values, got %d", @@ -352,12 +352,12 @@ func newBaggageItemsPreservationTest() *baggageItemsPreservationTest { } } -func (bip *baggageItemsPreservationTest) setup(t *testing.T, tracer *mockTracer) { +func (bip *baggageItemsPreservationTest) setup(*testing.T, *mockTracer) { bip.step = 0 bip.recordedBaggage = nil } -func (bip *baggageItemsPreservationTest) check(t *testing.T, tracer *mockTracer) { +func (bip *baggageItemsPreservationTest) check(t *testing.T, _ *mockTracer) { if len(bip.recordedBaggage) != len(bip.baggageItems) { t.Errorf("Expected %d recordings, got %d", len(bip.baggageItems), len(bip.recordedBaggage)) } @@ -450,13 +450,13 @@ func newBaggageInteroperationTest() *baggageInteroperationTest { } } -func (bio *baggageInteroperationTest) setup(t *testing.T, tracer *mockTracer) { +func (bio *baggageInteroperationTest) setup(*testing.T, *mockTracer) { bio.step = 0 bio.recordedOTBaggage = nil bio.recordedOtelBaggage = nil } -func (bio *baggageInteroperationTest) check(t *testing.T, tracer *mockTracer) { +func (bio *baggageInteroperationTest) check(t *testing.T, _ *mockTracer) { checkBIORecording(t, "OT", bio.baggageItems, bio.recordedOTBaggage) checkBIORecording(t, "Otel", bio.baggageItems, bio.recordedOtelBaggage) } diff --git a/bridge/opentracing/mock.go b/bridge/opentracing/mock.go index 602647706..7b720d0a9 100644 --- a/bridge/opentracing/mock.go +++ b/bridge/opentracing/mock.go @@ -66,7 +66,7 @@ func newMockTracer() *mockTracer { // Start returns a new trace span with the given name and options. func (t *mockTracer) Start( ctx context.Context, - name string, + _ string, opts ...trace.SpanStartOption, ) (context.Context, trace.Span) { config := trace.NewSpanStartConfig(opts...) @@ -172,7 +172,7 @@ func (t *mockTracer) getRandTraceID() trace.TraceID { } // DeferredContextSetupHook implements the DeferredContextSetupTracerExtension interface. -func (t *mockTracer) DeferredContextSetupHook(ctx context.Context, span trace.Span) context.Context { +func (t *mockTracer) DeferredContextSetupHook(ctx context.Context, _ trace.Span) context.Context { return t.addSpareContextValue(ctx) } diff --git a/bridge/opentracing/provider_test.go b/bridge/opentracing/provider_test.go index 091916141..65603bcaa 100644 --- a/bridge/opentracing/provider_test.go +++ b/bridge/opentracing/provider_test.go @@ -21,7 +21,7 @@ type namedMockTracerProvider struct{ embedded.TracerProvider } var _ trace.TracerProvider = (*namedMockTracerProvider)(nil) // Tracer returns the WrapperTracer associated with the WrapperTracerProvider. -func (p *namedMockTracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer { +func (p *namedMockTracerProvider) Tracer(name string, _ ...trace.TracerOption) trace.Tracer { return &namedMockTracer{ name: name, mockTracer: newMockTracer(), diff --git a/bridge/opentracing/wrapper.go b/bridge/opentracing/wrapper.go index 79be509b8..24a32f681 100644 --- a/bridge/opentracing/wrapper.go +++ b/bridge/opentracing/wrapper.go @@ -24,7 +24,7 @@ type WrapperTracerProvider struct { var _ trace.TracerProvider = (*WrapperTracerProvider)(nil) // Tracer returns the WrapperTracer associated with the WrapperTracerProvider. -func (p *WrapperTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer { +func (p *WrapperTracerProvider) Tracer(string, ...trace.TracerOption) trace.Tracer { return p.wTracer } diff --git a/exporters/otlp/otlplog/otlploggrpc/client_test.go b/exporters/otlp/otlplog/otlploggrpc/client_test.go index fa47a0f6d..2023ff1bc 100644 --- a/exporters/otlp/otlplog/otlploggrpc/client_test.go +++ b/exporters/otlp/otlplog/otlploggrpc/client_test.go @@ -268,7 +268,7 @@ func TestNewClient(t *testing.T) { // The gRPC connection created by newClient. conn, err := grpc.NewClient("test", grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) - newGRPCClientFn = func(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) { + newGRPCClientFn = func(string, ...grpc.DialOption) (*grpc.ClientConn, error) { return conn, nil } diff --git a/exporters/otlp/otlplog/otlploggrpc/exporter.go b/exporters/otlp/otlplog/otlploggrpc/exporter.go index 4ced020a0..392ebb5c4 100644 --- a/exporters/otlp/otlplog/otlploggrpc/exporter.go +++ b/exporters/otlp/otlplog/otlploggrpc/exporter.go @@ -89,6 +89,6 @@ func (e *Exporter) Shutdown(ctx context.Context) error { } // ForceFlush does nothing. The Exporter holds no state. -func (e *Exporter) ForceFlush(ctx context.Context) error { +func (e *Exporter) ForceFlush(context.Context) error { return nil } diff --git a/exporters/otlp/otlplog/otlploggrpc/exporter_test.go b/exporters/otlp/otlplog/otlploggrpc/exporter_test.go index 04414781e..65a9c49be 100644 --- a/exporters/otlp/otlplog/otlploggrpc/exporter_test.go +++ b/exporters/otlp/otlplog/otlploggrpc/exporter_test.go @@ -117,7 +117,7 @@ func TestExporterForceFlush(t *testing.T) { assert.NoError(t, e.ForceFlush(ctx), "ForceFlush") } -func TestExporterConcurrentSafe(t *testing.T) { +func TestExporterConcurrentSafe(*testing.T) { e := newExporter(&mockClient{}) const goroutines = 10 diff --git a/exporters/otlp/otlplog/otlploghttp/exporter.go b/exporters/otlp/otlplog/otlploghttp/exporter.go index f1c8d3ae0..7860da2c8 100644 --- a/exporters/otlp/otlplog/otlploghttp/exporter.go +++ b/exporters/otlp/otlplog/otlploghttp/exporter.go @@ -58,7 +58,7 @@ func (e *Exporter) Export(ctx context.Context, records []log.Record) error { // Shutdown shuts down the Exporter. Calls to Export or ForceFlush will perform // no operation after this is called. -func (e *Exporter) Shutdown(ctx context.Context) error { +func (e *Exporter) Shutdown(context.Context) error { if e.stopped.Swap(true) { return nil } @@ -68,6 +68,6 @@ func (e *Exporter) Shutdown(ctx context.Context) error { } // ForceFlush does nothing. The Exporter holds no state. -func (e *Exporter) ForceFlush(ctx context.Context) error { +func (e *Exporter) ForceFlush(context.Context) error { return nil } diff --git a/exporters/otlp/otlptrace/exporter_test.go b/exporters/otlp/otlptrace/exporter_test.go index 036a7b510..302f76760 100644 --- a/exporters/otlp/otlptrace/exporter_test.go +++ b/exporters/otlp/otlptrace/exporter_test.go @@ -21,15 +21,15 @@ type client struct { var _ otlptrace.Client = &client{} -func (c *client) Start(ctx context.Context) error { +func (c *client) Start(context.Context) error { return nil } -func (c *client) Stop(ctx context.Context) error { +func (c *client) Stop(context.Context) error { return nil } -func (c *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.ResourceSpans) error { +func (c *client) UploadTraces(context.Context, []*tracepb.ResourceSpans) error { return c.uploadErr } diff --git a/exporters/prometheus/config_test.go b/exporters/prometheus/config_test.go index 68fae27cb..36a6acdad 100644 --- a/exporters/prometheus/config_test.go +++ b/exporters/prometheus/config_test.go @@ -152,6 +152,6 @@ func TestNewConfig(t *testing.T) { type noopProducer struct{} -func (*noopProducer) Produce(ctx context.Context) ([]metricdata.ScopeMetrics, error) { +func (*noopProducer) Produce(context.Context) ([]metricdata.ScopeMetrics, error) { return nil, nil } diff --git a/exporters/prometheus/exporter.go b/exporters/prometheus/exporter.go index b130d9e9a..9664b3da8 100644 --- a/exporters/prometheus/exporter.go +++ b/exporters/prometheus/exporter.go @@ -143,7 +143,7 @@ func New(opts ...Option) (*Exporter, error) { } // Describe implements prometheus.Collector. -func (c *collector) Describe(ch chan<- *prometheus.Desc) { +func (c *collector) Describe(chan<- *prometheus.Desc) { // The Opentelemetry SDK doesn't have information on which will exist when the collector // is registered. By returning nothing we are an "unchecked" collector in Prometheus, // and assume responsibility for consistency of the metrics produced. diff --git a/exporters/prometheus/exporter_test.go b/exporters/prometheus/exporter_test.go index f2d108def..dfe9c45ea 100644 --- a/exporters/prometheus/exporter_test.go +++ b/exporters/prometheus/exporter_test.go @@ -886,7 +886,7 @@ func TestDuplicateMetrics(t *testing.T) { }, { name: "conflict_type_counter_and_updowncounter", - recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) { + recordMetrics: func(ctx context.Context, meterA, _ otelmetric.Meter) { counter, err := meterA.Int64Counter("foo", otelmetric.WithUnit("By"), otelmetric.WithDescription("meter foo")) @@ -907,7 +907,7 @@ func TestDuplicateMetrics(t *testing.T) { }, { name: "conflict_type_histogram_and_updowncounter", - recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) { + recordMetrics: func(ctx context.Context, meterA, _ otelmetric.Meter) { fooA, err := meterA.Int64UpDownCounter("foo", otelmetric.WithUnit("By"), otelmetric.WithDescription("meter gauge foo")) diff --git a/exporters/stdout/stdouttrace/trace.go b/exporters/stdout/stdouttrace/trace.go index a68790ed0..1118869d6 100644 --- a/exporters/stdout/stdouttrace/trace.go +++ b/exporters/stdout/stdouttrace/trace.go @@ -83,7 +83,7 @@ func (e *Exporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan) } // Shutdown is called to stop the exporter, it performs no action. -func (e *Exporter) Shutdown(ctx context.Context) error { +func (e *Exporter) Shutdown(context.Context) error { e.stoppedMu.Lock() e.stopped = true e.stoppedMu.Unlock() diff --git a/internal/baggage/context_test.go b/internal/baggage/context_test.go index 7074f4b49..17870d4c9 100644 --- a/internal/baggage/context_test.go +++ b/internal/baggage/context_test.go @@ -44,7 +44,7 @@ func TestListFromContext(t *testing.T) { func TestContextWithSetHook(t *testing.T) { var called bool - f := func(ctx context.Context, list List) context.Context { + f := func(ctx context.Context, _ List) context.Context { called = true return ctx } @@ -65,7 +65,7 @@ func TestContextWithSetHook(t *testing.T) { func TestContextWithGetHook(t *testing.T) { var called bool - f := func(ctx context.Context, list List) List { + f := func(_ context.Context, list List) List { called = true return list } diff --git a/internal/global/alternate_meter_test.go b/internal/global/alternate_meter_test.go index 0bc66a29b..c6b4af328 100644 --- a/internal/global/alternate_meter_test.go +++ b/internal/global/alternate_meter_test.go @@ -28,7 +28,7 @@ type altMeterProvider struct { var _ metric.MeterProvider = &altMeterProvider{} -func (amp *altMeterProvider) Meter(name string, opts ...metric.MeterOption) metric.Meter { +func (amp *altMeterProvider) Meter(string, ...metric.MeterOption) metric.Meter { am := &altMeter{ provider: amp, } @@ -126,8 +126,8 @@ func (am *altMeter) Int64Gauge(name string, _ ...metric.Int64GaugeOption) (metri } func (am *altMeter) Int64ObservableCounter( - name string, - options ...metric.Int64ObservableCounterOption, + string, + ...metric.Int64ObservableCounterOption, ) (metric.Int64ObservableCounter, error) { return &testAiCounter{ meter: am, @@ -135,8 +135,8 @@ func (am *altMeter) Int64ObservableCounter( } func (am *altMeter) Int64ObservableUpDownCounter( - name string, - options ...metric.Int64ObservableUpDownCounterOption, + string, + ...metric.Int64ObservableUpDownCounterOption, ) (metric.Int64ObservableUpDownCounter, error) { return &testAiUpDownCounter{ meter: am, @@ -144,8 +144,8 @@ func (am *altMeter) Int64ObservableUpDownCounter( } func (am *altMeter) Int64ObservableGauge( - name string, - options ...metric.Int64ObservableGaugeOption, + string, + ...metric.Int64ObservableGaugeOption, ) (metric.Int64ObservableGauge, error) { return &testAiGauge{ meter: am, @@ -165,18 +165,18 @@ func (am *altMeter) Float64UpDownCounter( func (am *altMeter) Float64Histogram( name string, - options ...metric.Float64HistogramOption, + _ ...metric.Float64HistogramOption, ) (metric.Float64Histogram, error) { return noop.NewMeterProvider().Meter("noop").Float64Histogram(name) } -func (am *altMeter) Float64Gauge(name string, options ...metric.Float64GaugeOption) (metric.Float64Gauge, error) { +func (am *altMeter) Float64Gauge(name string, _ ...metric.Float64GaugeOption) (metric.Float64Gauge, error) { return noop.NewMeterProvider().Meter("noop").Float64Gauge(name) } func (am *altMeter) Float64ObservableCounter( - name string, - options ...metric.Float64ObservableCounterOption, + string, + ...metric.Float64ObservableCounterOption, ) (metric.Float64ObservableCounter, error) { return &testAfCounter{ meter: am, @@ -184,8 +184,8 @@ func (am *altMeter) Float64ObservableCounter( } func (am *altMeter) Float64ObservableUpDownCounter( - name string, - options ...metric.Float64ObservableUpDownCounterOption, + string, + ...metric.Float64ObservableUpDownCounterOption, ) (metric.Float64ObservableUpDownCounter, error) { return &testAfUpDownCounter{ meter: am, @@ -193,8 +193,8 @@ func (am *altMeter) Float64ObservableUpDownCounter( } func (am *altMeter) Float64ObservableGauge( - name string, - options ...metric.Float64ObservableGaugeOption, + string, + ...metric.Float64ObservableGaugeOption, ) (metric.Float64ObservableGauge, error) { return &testAfGauge{ meter: am, diff --git a/internal/global/instruments_test.go b/internal/global/instruments_test.go index 74a89892b..bcf1e4f39 100644 --- a/internal/global/instruments_test.go +++ b/internal/global/instruments_test.go @@ -55,19 +55,19 @@ func testInt64ConcurrentSafe(interact func(int64), setDelegate func(metric.Meter func TestAsyncInstrumentSetDelegateConcurrentSafe(t *testing.T) { // Float64 Instruments t.Run("Float64", func(t *testing.T) { - t.Run("Counter", func(t *testing.T) { + t.Run("Counter", func(*testing.T) { delegate := &afCounter{} f := func(float64) { _ = delegate.unwrap() } testFloat64ConcurrentSafe(f, delegate.setDelegate) }) - t.Run("UpDownCounter", func(t *testing.T) { + t.Run("UpDownCounter", func(*testing.T) { delegate := &afUpDownCounter{} f := func(float64) { _ = delegate.unwrap() } testFloat64ConcurrentSafe(f, delegate.setDelegate) }) - t.Run("Gauge", func(t *testing.T) { + t.Run("Gauge", func(*testing.T) { delegate := &afGauge{} f := func(float64) { _ = delegate.unwrap() } testFloat64ConcurrentSafe(f, delegate.setDelegate) @@ -77,19 +77,19 @@ func TestAsyncInstrumentSetDelegateConcurrentSafe(t *testing.T) { // Int64 Instruments t.Run("Int64", func(t *testing.T) { - t.Run("Counter", func(t *testing.T) { + t.Run("Counter", func(*testing.T) { delegate := &aiCounter{} f := func(int64) { _ = delegate.unwrap() } testInt64ConcurrentSafe(f, delegate.setDelegate) }) - t.Run("UpDownCounter", func(t *testing.T) { + t.Run("UpDownCounter", func(*testing.T) { delegate := &aiUpDownCounter{} f := func(int64) { _ = delegate.unwrap() } testInt64ConcurrentSafe(f, delegate.setDelegate) }) - t.Run("Gauge", func(t *testing.T) { + t.Run("Gauge", func(*testing.T) { delegate := &aiGauge{} f := func(int64) { _ = delegate.unwrap() } testInt64ConcurrentSafe(f, delegate.setDelegate) @@ -99,26 +99,26 @@ func TestAsyncInstrumentSetDelegateConcurrentSafe(t *testing.T) { func TestSyncInstrumentSetDelegateConcurrentSafe(t *testing.T) { // Float64 Instruments - t.Run("Float64", func(t *testing.T) { - t.Run("Counter", func(t *testing.T) { + t.Run("Float64", func(*testing.T) { + t.Run("Counter", func(*testing.T) { delegate := &sfCounter{} f := func(v float64) { delegate.Add(context.Background(), v) } testFloat64ConcurrentSafe(f, delegate.setDelegate) }) - t.Run("UpDownCounter", func(t *testing.T) { + t.Run("UpDownCounter", func(*testing.T) { delegate := &sfUpDownCounter{} f := func(v float64) { delegate.Add(context.Background(), v) } testFloat64ConcurrentSafe(f, delegate.setDelegate) }) - t.Run("Histogram", func(t *testing.T) { + t.Run("Histogram", func(*testing.T) { delegate := &sfHistogram{} f := func(v float64) { delegate.Record(context.Background(), v) } testFloat64ConcurrentSafe(f, delegate.setDelegate) }) - t.Run("Gauge", func(t *testing.T) { + t.Run("Gauge", func(*testing.T) { delegate := &sfGauge{} f := func(v float64) { delegate.Record(context.Background(), v) } testFloat64ConcurrentSafe(f, delegate.setDelegate) @@ -127,26 +127,26 @@ func TestSyncInstrumentSetDelegateConcurrentSafe(t *testing.T) { // Int64 Instruments - t.Run("Int64", func(t *testing.T) { - t.Run("Counter", func(t *testing.T) { + t.Run("Int64", func(*testing.T) { + t.Run("Counter", func(*testing.T) { delegate := &siCounter{} f := func(v int64) { delegate.Add(context.Background(), v) } testInt64ConcurrentSafe(f, delegate.setDelegate) }) - t.Run("UpDownCounter", func(t *testing.T) { + t.Run("UpDownCounter", func(*testing.T) { delegate := &siUpDownCounter{} f := func(v int64) { delegate.Add(context.Background(), v) } testInt64ConcurrentSafe(f, delegate.setDelegate) }) - t.Run("Histogram", func(t *testing.T) { + t.Run("Histogram", func(*testing.T) { delegate := &siHistogram{} f := func(v int64) { delegate.Record(context.Background(), v) } testInt64ConcurrentSafe(f, delegate.setDelegate) }) - t.Run("Gauge", func(t *testing.T) { + t.Run("Gauge", func(*testing.T) { delegate := &siGauge{} f := func(v int64) { delegate.Record(context.Background(), v) } testInt64ConcurrentSafe(f, delegate.setDelegate) diff --git a/internal/global/internal_logging_test.go b/internal/global/internal_logging_test.go index c09695bbc..5937b0f30 100644 --- a/internal/global/internal_logging_test.go +++ b/internal/global/internal_logging_test.go @@ -88,7 +88,7 @@ func TestLogLevel(t *testing.T) { } func newBuffLogger(buf *bytes.Buffer, verbosity int) logr.Logger { - return funcr.New(func(prefix, args string) { + return funcr.New(func(_, args string) { _, _ = buf.WriteString(args) }, funcr.Options{ Verbosity: verbosity, diff --git a/internal/global/meter_test.go b/internal/global/meter_test.go index 7b444d617..6a64886b7 100644 --- a/internal/global/meter_test.go +++ b/internal/global/meter_test.go @@ -18,7 +18,7 @@ import ( "go.opentelemetry.io/otel/metric/noop" ) -func TestMeterProviderConcurrentSafe(t *testing.T) { +func TestMeterProviderConcurrentSafe(*testing.T) { mp := &meterProvider{} done := make(chan struct{}) finish := make(chan struct{}) @@ -39,7 +39,7 @@ func TestMeterProviderConcurrentSafe(t *testing.T) { <-done } -var zeroCallback metric.Callback = func(ctx context.Context, or metric.Observer) error { +var zeroCallback metric.Callback = func(context.Context, metric.Observer) error { return nil } @@ -143,7 +143,7 @@ func testSetupAllInstrumentTypes( _, err = m.Int64ObservableGauge("test_Async_Gauge") assert.NoError(t, err) - _, err = m.RegisterCallback(func(ctx context.Context, obs metric.Observer) error { + _, err = m.RegisterCallback(func(_ context.Context, obs metric.Observer) error { obs.ObserveFloat64(afcounter, 3) return nil }, afcounter) diff --git a/internal/global/meter_types_test.go b/internal/global/meter_types_test.go index a0257b34c..39c9fe7a9 100644 --- a/internal/global/meter_types_test.go +++ b/internal/global/meter_types_test.go @@ -16,9 +16,8 @@ type testMeterProvider struct { count int } -func (p *testMeterProvider) Meter(name string, opts ...metric.MeterOption) metric.Meter { +func (p *testMeterProvider) Meter(string, ...metric.MeterOption) metric.Meter { p.count++ - return &testMeter{} } @@ -46,105 +45,105 @@ type testMeter struct { callbacks []metric.Callback } -func (m *testMeter) Int64Counter(name string, options ...metric.Int64CounterOption) (metric.Int64Counter, error) { +func (m *testMeter) Int64Counter(string, ...metric.Int64CounterOption) (metric.Int64Counter, error) { m.siCount++ return &testCountingIntInstrument{}, nil } func (m *testMeter) Int64UpDownCounter( - name string, - options ...metric.Int64UpDownCounterOption, + string, + ...metric.Int64UpDownCounterOption, ) (metric.Int64UpDownCounter, error) { m.siUDCount++ return &testCountingIntInstrument{}, nil } -func (m *testMeter) Int64Histogram(name string, options ...metric.Int64HistogramOption) (metric.Int64Histogram, error) { +func (m *testMeter) Int64Histogram(string, ...metric.Int64HistogramOption) (metric.Int64Histogram, error) { m.siHist++ return &testCountingIntInstrument{}, nil } -func (m *testMeter) Int64Gauge(name string, options ...metric.Int64GaugeOption) (metric.Int64Gauge, error) { +func (m *testMeter) Int64Gauge(string, ...metric.Int64GaugeOption) (metric.Int64Gauge, error) { m.siGauge++ return &testCountingIntInstrument{}, nil } func (m *testMeter) Int64ObservableCounter( - name string, - options ...metric.Int64ObservableCounterOption, + string, + ...metric.Int64ObservableCounterOption, ) (metric.Int64ObservableCounter, error) { m.aiCount++ return &testCountingIntInstrument{}, nil } func (m *testMeter) Int64ObservableUpDownCounter( - name string, - options ...metric.Int64ObservableUpDownCounterOption, + string, + ...metric.Int64ObservableUpDownCounterOption, ) (metric.Int64ObservableUpDownCounter, error) { m.aiUDCount++ return &testCountingIntInstrument{}, nil } func (m *testMeter) Int64ObservableGauge( - name string, - options ...metric.Int64ObservableGaugeOption, + string, + ...metric.Int64ObservableGaugeOption, ) (metric.Int64ObservableGauge, error) { m.aiGauge++ return &testCountingIntInstrument{}, nil } -func (m *testMeter) Float64Counter(name string, options ...metric.Float64CounterOption) (metric.Float64Counter, error) { +func (m *testMeter) Float64Counter(string, ...metric.Float64CounterOption) (metric.Float64Counter, error) { m.sfCount++ return &testCountingFloatInstrument{}, nil } func (m *testMeter) Float64UpDownCounter( - name string, - options ...metric.Float64UpDownCounterOption, + string, + ...metric.Float64UpDownCounterOption, ) (metric.Float64UpDownCounter, error) { m.sfUDCount++ return &testCountingFloatInstrument{}, nil } func (m *testMeter) Float64Histogram( - name string, - options ...metric.Float64HistogramOption, + string, + ...metric.Float64HistogramOption, ) (metric.Float64Histogram, error) { m.sfHist++ return &testCountingFloatInstrument{}, nil } -func (m *testMeter) Float64Gauge(name string, options ...metric.Float64GaugeOption) (metric.Float64Gauge, error) { +func (m *testMeter) Float64Gauge(string, ...metric.Float64GaugeOption) (metric.Float64Gauge, error) { m.sfGauge++ return &testCountingFloatInstrument{}, nil } func (m *testMeter) Float64ObservableCounter( - name string, - options ...metric.Float64ObservableCounterOption, + string, + ...metric.Float64ObservableCounterOption, ) (metric.Float64ObservableCounter, error) { m.afCount++ return &testCountingFloatInstrument{}, nil } func (m *testMeter) Float64ObservableUpDownCounter( - name string, - options ...metric.Float64ObservableUpDownCounterOption, + string, + ...metric.Float64ObservableUpDownCounterOption, ) (metric.Float64ObservableUpDownCounter, error) { m.afUDCount++ return &testCountingFloatInstrument{}, nil } func (m *testMeter) Float64ObservableGauge( - name string, - options ...metric.Float64ObservableGaugeOption, + string, + ...metric.Float64ObservableGaugeOption, ) (metric.Float64ObservableGauge, error) { m.afGauge++ return &testCountingFloatInstrument{}, nil } // RegisterCallback captures the function that will be called during Collect. -func (m *testMeter) RegisterCallback(f metric.Callback, i ...metric.Observable) (metric.Registration, error) { +func (m *testMeter) RegisterCallback(f metric.Callback, _ ...metric.Observable) (metric.Registration, error) { m.callbacks = append(m.callbacks, f) return testReg{ f: func(idx int) func() { @@ -183,14 +182,14 @@ type observationRecorder struct { ctx context.Context } -func (o observationRecorder) ObserveFloat64(i metric.Float64Observable, value float64, _ ...metric.ObserveOption) { +func (o observationRecorder) ObserveFloat64(i metric.Float64Observable, _ float64, _ ...metric.ObserveOption) { iImpl, ok := i.(*testCountingFloatInstrument) if ok { iImpl.observe() } } -func (o observationRecorder) ObserveInt64(i metric.Int64Observable, value int64, _ ...metric.ObserveOption) { +func (o observationRecorder) ObserveInt64(i metric.Int64Observable, _ int64, _ ...metric.ObserveOption) { iImpl, ok := i.(*testCountingIntInstrument) if ok { iImpl.observe() diff --git a/internal/global/trace_test.go b/internal/global/trace_test.go index d16a8946d..ce1832075 100644 --- a/internal/global/trace_test.go +++ b/internal/global/trace_test.go @@ -59,11 +59,11 @@ func TestTraceProviderDelegation(t *testing.T) { _, span1 := tracer1.Start(ctx, "span1") SetTracerProvider(fnTracerProvider{ - tracer: func(name string, opts ...trace.TracerOption) trace.Tracer { + tracer: func(name string, _ ...trace.TracerOption) trace.Tracer { spans, ok := expected[name] assert.Truef(t, ok, "invalid tracer: %s", name) return fnTracer{ - start: func(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { + start: func(ctx context.Context, spanName string, _ ...trace.SpanStartOption) (context.Context, trace.Span) { if ok { if len(spans) == 0 { t.Errorf("unexpected span: %s", spanName) @@ -105,7 +105,7 @@ func TestTraceProviderDelegates(t *testing.T) { // Configure it with a spy. called := false SetTracerProvider(fnTracerProvider{ - tracer: func(name string, opts ...trace.TracerOption) trace.Tracer { + tracer: func(name string, _ ...trace.TracerOption) trace.Tracer { called = true assert.Equal(t, "abc", name) return noop.NewTracerProvider().Tracer("") @@ -142,7 +142,7 @@ func TestTraceProviderDelegatesConcurrentSafe(t *testing.T) { // Configure it with a spy. called := int32(0) SetTracerProvider(fnTracerProvider{ - tracer: func(name string, opts ...trace.TracerOption) trace.Tracer { + tracer: func(name string, _ ...trace.TracerOption) trace.Tracer { newVal := atomic.AddInt32(&called, 1) assert.Equal(t, "abc", name) if newVal == 10 { @@ -186,10 +186,10 @@ func TestTracerDelegatesConcurrentSafe(t *testing.T) { // Configure it with a spy. called := int32(0) SetTracerProvider(fnTracerProvider{ - tracer: func(name string, opts ...trace.TracerOption) trace.Tracer { + tracer: func(name string, _ ...trace.TracerOption) trace.Tracer { assert.Equal(t, "abc", name) return fnTracer{ - start: func(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { + start: func(ctx context.Context, spanName string, _ ...trace.SpanStartOption) (context.Context, trace.Span) { newVal := atomic.AddInt32(&called, 1) assert.Equal(t, "name", spanName) if newVal == 10 { @@ -218,7 +218,7 @@ func TestTraceProviderDelegatesSameInstance(t *testing.T) { assert.Same(t, tracer, gtp.Tracer("abc", trace.WithInstrumentationVersion("xyz"))) SetTracerProvider(fnTracerProvider{ - tracer: func(name string, opts ...trace.TracerOption) trace.Tracer { + tracer: func(string, ...trace.TracerOption) trace.Tracer { return noop.NewTracerProvider().Tracer("") }, }) diff --git a/log/internal/global/log_test.go b/log/internal/global/log_test.go index ae2c5b2a6..811b44356 100644 --- a/log/internal/global/log_test.go +++ b/log/internal/global/log_test.go @@ -16,7 +16,7 @@ import ( "go.opentelemetry.io/otel/log/noop" ) -func TestLoggerProviderConcurrentSafe(t *testing.T) { +func TestLoggerProviderConcurrentSafe(*testing.T) { p := &loggerProvider{} done := make(chan struct{}) @@ -41,7 +41,7 @@ func TestLoggerProviderConcurrentSafe(t *testing.T) { <-done } -func TestLoggerConcurrentSafe(t *testing.T) { +func TestLoggerConcurrentSafe(*testing.T) { l := &logger{} done := make(chan struct{}) diff --git a/log/logtest/recorder_test.go b/log/logtest/recorder_test.go index cee2d290e..feea565a9 100644 --- a/log/logtest/recorder_test.go +++ b/log/logtest/recorder_test.go @@ -149,7 +149,7 @@ func TestRecorderLoggerEmitAndReset(t *testing.T) { assert.Equal(t, want, got) } -func TestRecorderConcurrentSafe(t *testing.T) { +func TestRecorderConcurrentSafe(*testing.T) { const goRoutineN = 10 var wg sync.WaitGroup diff --git a/metric/asyncfloat64_test.go b/metric/asyncfloat64_test.go index 7ef2b0d02..af7ebf438 100644 --- a/metric/asyncfloat64_test.go +++ b/metric/asyncfloat64_test.go @@ -35,7 +35,7 @@ func TestFloat64ObservableConfiguration(t *testing.T) { } } - cback := func(ctx context.Context, obsrv Float64Observer) error { + cback := func(_ context.Context, obsrv Float64Observer) error { obsrv.Observe(token) return nil } diff --git a/metric/asyncint64_test.go b/metric/asyncint64_test.go index bc39e996d..e09a192d5 100644 --- a/metric/asyncint64_test.go +++ b/metric/asyncint64_test.go @@ -35,7 +35,7 @@ func TestInt64ObservableConfiguration(t *testing.T) { } } - cback := func(ctx context.Context, obsrv Int64Observer) error { + cback := func(_ context.Context, obsrv Int64Observer) error { obsrv.Observe(token) return nil } diff --git a/metric/example_test.go b/metric/example_test.go index 37ace8467..78ee82162 100644 --- a/metric/example_test.go +++ b/metric/example_test.go @@ -110,7 +110,7 @@ func ExampleMeter_counter() { if err != nil { panic(err) } - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc("/", func(_ http.ResponseWriter, r *http.Request) { apiCounter.Add(r.Context(), 1) // do some work in an API call @@ -195,7 +195,7 @@ func ExampleMeter_histogram() { if err != nil { panic(err) } - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc("/", func(_ http.ResponseWriter, r *http.Request) { start := time.Now() // do some work in an API call @@ -231,7 +231,7 @@ func ExampleMeter_observableCounter() { func ExampleMeter_observableUpDownCounter() { // The function registers asynchronous metrics for the provided db. // Make sure to unregister metric.Registration before closing the provided db. - _ = func(db *sql.DB, meter metric.Meter, poolName string) (metric.Registration, error) { + _ = func(db *sql.DB, meter metric.Meter, _ string) (metric.Registration, error) { m, err := meter.Int64ObservableUpDownCounter( "db.client.connections.max", metric.WithDescription("The maximum number of open connections allowed."), @@ -301,7 +301,7 @@ func ExampleMeter_attributes() { if err != nil { panic(err) } - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc("/", func(_ http.ResponseWriter, r *http.Request) { // do some work in an API call and set the response HTTP status code statusCode := http.StatusOK diff --git a/metric/instrument_test.go b/metric/instrument_test.go index 15a6e9e9c..f7fc295d6 100644 --- a/metric/instrument_test.go +++ b/metric/instrument_test.go @@ -90,7 +90,7 @@ func testConfAttr(newConf func(...MeasurementOption) attrConf) func(t *testing.T } } -func TestWithAttributesConcurrentSafe(t *testing.T) { +func TestWithAttributesConcurrentSafe(*testing.T) { attrs := []attribute.KeyValue{ attribute.String("user", "Alice"), attribute.Bool("admin", true), diff --git a/metric_test.go b/metric_test.go index 6454dc07f..c98e0e4a6 100644 --- a/metric_test.go +++ b/metric_test.go @@ -17,7 +17,7 @@ type testMeterProvider struct{ embedded.MeterProvider } var _ metric.MeterProvider = &testMeterProvider{} -func (*testMeterProvider) Meter(_ string, _ ...metric.MeterOption) metric.Meter { +func (*testMeterProvider) Meter(string, ...metric.MeterOption) metric.Meter { return noop.NewMeterProvider().Meter("") } diff --git a/propagation/propagation_test.go b/propagation/propagation_test.go index 47d49cfa3..8c7e9d80a 100644 --- a/propagation/propagation_test.go +++ b/propagation/propagation_test.go @@ -32,11 +32,11 @@ type propagator struct { Name string } -func (p propagator) Inject(ctx context.Context, carrier propagation.TextMapCarrier) { +func (p propagator) Inject(_ context.Context, carrier propagation.TextMapCarrier) { carrier.Set(p.Name, "") } -func (p propagator) Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context { +func (p propagator) Extract(ctx context.Context, _ propagation.TextMapCarrier) context.Context { v := ctx.Value(ctxKey) if v == nil { ctx = context.WithValue(ctx, ctxKey, []string{p.Name}) diff --git a/propagation/propagators_test.go b/propagation/propagators_test.go index ee9b7d6fa..b41ebf394 100644 --- a/propagation/propagators_test.go +++ b/propagation/propagators_test.go @@ -48,7 +48,7 @@ type outOfThinAirPropagator struct { var _ propagation.TextMapPropagator = outOfThinAirPropagator{} -func (p outOfThinAirPropagator) Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context { +func (p outOfThinAirPropagator) Extract(ctx context.Context, _ propagation.TextMapCarrier) context.Context { sc := trace.NewSpanContext(trace.SpanContextConfig{ TraceID: traceID, SpanID: spanID, @@ -72,11 +72,11 @@ func (nilCarrier) Keys() []string { return nil } -func (nilCarrier) Get(key string) string { +func (nilCarrier) Get(string) string { return "" } -func (nilCarrier) Set(key, value string) {} +func (nilCarrier) Set(string, string) {} func TestMultiplePropagators(t *testing.T) { ootaProp := outOfThinAirPropagator{t: t} diff --git a/sdk/log/bench_test.go b/sdk/log/bench_test.go index fb25c871d..e46715262 100644 --- a/sdk/log/bench_test.go +++ b/sdk/log/bench_test.go @@ -128,7 +128,7 @@ func BenchmarkProcessor(b *testing.B) { type timestampProcessor struct{} -func (p timestampProcessor) OnEmit(ctx context.Context, r *Record) error { +func (p timestampProcessor) OnEmit(_ context.Context, r *Record) error { r.SetObservedTimestamp(time.Date(1988, time.November, 17, 0, 0, 0, 0, time.UTC)) return nil } @@ -137,17 +137,17 @@ func (p timestampProcessor) Enabled(context.Context, Record) bool { return true } -func (p timestampProcessor) Shutdown(ctx context.Context) error { +func (p timestampProcessor) Shutdown(context.Context) error { return nil } -func (p timestampProcessor) ForceFlush(ctx context.Context) error { +func (p timestampProcessor) ForceFlush(context.Context) error { return nil } type attrAddProcessor struct{} -func (p attrAddProcessor) OnEmit(ctx context.Context, r *Record) error { +func (p attrAddProcessor) OnEmit(_ context.Context, r *Record) error { r.AddAttributes(log.String("add", "me")) return nil } @@ -156,17 +156,17 @@ func (p attrAddProcessor) Enabled(context.Context, Record) bool { return true } -func (p attrAddProcessor) Shutdown(ctx context.Context) error { +func (p attrAddProcessor) Shutdown(context.Context) error { return nil } -func (p attrAddProcessor) ForceFlush(ctx context.Context) error { +func (p attrAddProcessor) ForceFlush(context.Context) error { return nil } type attrSetDecorator struct{} -func (p attrSetDecorator) OnEmit(ctx context.Context, r *Record) error { +func (p attrSetDecorator) OnEmit(_ context.Context, r *Record) error { r.SetAttributes(log.String("replace", "me")) return nil } @@ -175,10 +175,10 @@ func (p attrSetDecorator) Enabled(context.Context, Record) bool { return true } -func (p attrSetDecorator) Shutdown(ctx context.Context) error { +func (p attrSetDecorator) Shutdown(context.Context) error { return nil } -func (p attrSetDecorator) ForceFlush(ctx context.Context) error { +func (p attrSetDecorator) ForceFlush(context.Context) error { return nil } diff --git a/sdk/log/example_test.go b/sdk/log/example_test.go index 5cfd75e4b..a8ac3f7f9 100644 --- a/sdk/log/example_test.go +++ b/sdk/log/example_test.go @@ -135,7 +135,7 @@ type RedactTokensProcessor struct{} // OnEmit redacts values from attributes containing "token" in the key // by replacing them with a REDACTED value. -func (p *RedactTokensProcessor) OnEmit(ctx context.Context, record *log.Record) error { +func (p *RedactTokensProcessor) OnEmit(_ context.Context, record *log.Record) error { record.WalkAttributes(func(kv logapi.KeyValue) bool { if strings.Contains(strings.ToLower(kv.Key), "token") { record.AddAttributes(logapi.String(kv.Key, "REDACTED")) @@ -146,11 +146,11 @@ func (p *RedactTokensProcessor) OnEmit(ctx context.Context, record *log.Record) } // Shutdown returns nil. -func (p *RedactTokensProcessor) Shutdown(ctx context.Context) error { +func (p *RedactTokensProcessor) Shutdown(context.Context) error { return nil } // ForceFlush returns nil. -func (p *RedactTokensProcessor) ForceFlush(ctx context.Context) error { +func (p *RedactTokensProcessor) ForceFlush(context.Context) error { return nil } diff --git a/sdk/log/exporter_test.go b/sdk/log/exporter_test.go index 54dd18b8e..7d3485742 100644 --- a/sdk/log/exporter_test.go +++ b/sdk/log/exporter_test.go @@ -112,7 +112,7 @@ func (e *testExporter) Stop() { <-e.done } -func (e *testExporter) Shutdown(ctx context.Context) error { +func (e *testExporter) Shutdown(context.Context) error { atomic.AddInt32(e.shutdownN, 1) return e.Err } @@ -121,7 +121,7 @@ func (e *testExporter) ShutdownN() int { return int(atomic.LoadInt32(e.shutdownN)) } -func (e *testExporter) ForceFlush(ctx context.Context) error { +func (e *testExporter) ForceFlush(context.Context) error { atomic.AddInt32(e.forceFlushN, 1) return e.Err } @@ -382,7 +382,7 @@ func TestBufferExporter(t *testing.T) { defer func(orig otel.ErrorHandler) { otel.SetErrorHandler(orig) }(otel.GetErrorHandler()) - handler := otel.ErrorHandlerFunc(func(err error) {}) + handler := otel.ErrorHandlerFunc(func(error) {}) otel.SetErrorHandler(handler) exp := newTestExporter(assert.AnError) diff --git a/sdk/log/logtest/example_test.go b/sdk/log/logtest/example_test.go index 7bfdb38df..ea8cf351f 100644 --- a/sdk/log/logtest/example_test.go +++ b/sdk/log/logtest/example_test.go @@ -40,7 +40,7 @@ var _ log.Exporter = exporter{} type exporter struct{ io.Writer } -func (e exporter) Export(ctx context.Context, records []log.Record) error { +func (e exporter) Export(_ context.Context, records []log.Record) error { for i, r := range records { if i != 0 { if _, err := e.Write([]byte("\n")); err != nil { diff --git a/sdk/log/provider_test.go b/sdk/log/provider_test.go index a28a21d4b..f9ca530ec 100644 --- a/sdk/log/provider_test.go +++ b/sdk/log/provider_test.go @@ -40,7 +40,7 @@ func newProcessor(name string) *processor { return &processor{Name: name} } -func (p *processor) OnEmit(ctx context.Context, r *Record) error { +func (p *processor) OnEmit(_ context.Context, r *Record) error { if p.Err != nil { return p.Err } @@ -248,7 +248,7 @@ func TestWithResource(t *testing.T) { } } -func TestLoggerProviderConcurrentSafe(t *testing.T) { +func TestLoggerProviderConcurrentSafe(*testing.T) { const goRoutineN = 10 var wg sync.WaitGroup diff --git a/sdk/log/simple_test.go b/sdk/log/simple_test.go index 86df4ff3d..b028c9c88 100644 --- a/sdk/log/simple_test.go +++ b/sdk/log/simple_test.go @@ -96,7 +96,7 @@ func TestSimpleProcessorEmpty(t *testing.T) { }) } -func TestSimpleProcessorConcurrentSafe(t *testing.T) { +func TestSimpleProcessorConcurrentSafe(*testing.T) { const goRoutineN = 10 var wg sync.WaitGroup diff --git a/sdk/metric/config_test.go b/sdk/metric/config_test.go index 483401ca3..ab7bebbe0 100644 --- a/sdk/metric/config_test.go +++ b/sdk/metric/config_test.go @@ -66,11 +66,11 @@ func TestConfigReaderSignalsEmpty(t *testing.T) { func TestConfigReaderSignalsForwarded(t *testing.T) { var flush, sdown int r := &reader{ - forceFlushFunc: func(ctx context.Context) error { + forceFlushFunc: func(context.Context) error { flush++ return nil }, - shutdownFunc: func(ctx context.Context) error { + shutdownFunc: func(context.Context) error { sdown++ return nil }, @@ -93,8 +93,8 @@ func TestConfigReaderSignalsForwarded(t *testing.T) { func TestConfigReaderSignalsForwardedErrors(t *testing.T) { r := &reader{ - forceFlushFunc: func(ctx context.Context) error { return assert.AnError }, - shutdownFunc: func(ctx context.Context) error { return assert.AnError }, + forceFlushFunc: func(context.Context) error { return assert.AnError }, + shutdownFunc: func(context.Context) error { return assert.AnError }, } c := newConfig([]Option{WithReader(r)}) f, s := c.readerSignals() @@ -115,9 +115,9 @@ func TestUnifyMultiError(t *testing.T) { e2 = errors.New("2") ) err := unify([]func(context.Context) error{ - func(ctx context.Context) error { return e0 }, - func(ctx context.Context) error { return e1 }, - func(ctx context.Context) error { return e2 }, + func(context.Context) error { return e0 }, + func(context.Context) error { return e1 }, + func(context.Context) error { return e2 }, })(context.Background()) assert.ErrorIs(t, err, e0) assert.ErrorIs(t, err, e1) diff --git a/sdk/metric/exemplar/filter.go b/sdk/metric/exemplar/filter.go index b595e2ace..b50f5c153 100644 --- a/sdk/metric/exemplar/filter.go +++ b/sdk/metric/exemplar/filter.go @@ -24,11 +24,11 @@ func TraceBasedFilter(ctx context.Context) bool { } // AlwaysOnFilter is a [Filter] that always offers measurements. -func AlwaysOnFilter(ctx context.Context) bool { +func AlwaysOnFilter(context.Context) bool { return true } // AlwaysOffFilter is a [Filter] that never offers measurements. -func AlwaysOffFilter(ctx context.Context) bool { +func AlwaysOffFilter(context.Context) bool { return false } diff --git a/sdk/metric/exemplar/fixed_size_reservoir.go b/sdk/metric/exemplar/fixed_size_reservoir.go index 08fdefbde..8625dca27 100644 --- a/sdk/metric/exemplar/fixed_size_reservoir.go +++ b/sdk/metric/exemplar/fixed_size_reservoir.go @@ -14,7 +14,7 @@ import ( // FixedSizeReservoirProvider returns a provider of [FixedSizeReservoir]. func FixedSizeReservoirProvider(k int) ReservoirProvider { - return func(_ attribute.Set) Reservoir { + return func(attribute.Set) Reservoir { return NewFixedSizeReservoir(k) } } diff --git a/sdk/metric/exemplar/histogram_reservoir.go b/sdk/metric/exemplar/histogram_reservoir.go index 3b76cf305..decab613e 100644 --- a/sdk/metric/exemplar/histogram_reservoir.go +++ b/sdk/metric/exemplar/histogram_reservoir.go @@ -16,7 +16,7 @@ import ( func HistogramReservoirProvider(bounds []float64) ReservoirProvider { cp := slices.Clone(bounds) slices.Sort(cp) - return func(_ attribute.Set) Reservoir { + return func(attribute.Set) Reservoir { return NewHistogramReservoir(cp) } } diff --git a/sdk/metric/instrument.go b/sdk/metric/instrument.go index 9d452074a..63cccc508 100644 --- a/sdk/metric/instrument.go +++ b/sdk/metric/instrument.go @@ -204,7 +204,7 @@ func (i *int64Inst) Record(ctx context.Context, val int64, opts ...metric.Record i.aggregate(ctx, val, c.Attributes()) } -func (i *int64Inst) Enabled(_ context.Context) bool { +func (i *int64Inst) Enabled(context.Context) bool { return len(i.measures) != 0 } @@ -245,7 +245,7 @@ func (i *float64Inst) Record(ctx context.Context, val float64, opts ...metric.Re i.aggregate(ctx, val, c.Attributes()) } -func (i *float64Inst) Enabled(_ context.Context) bool { +func (i *float64Inst) Enabled(context.Context) bool { return len(i.measures) != 0 } diff --git a/sdk/metric/manual_reader_test.go b/sdk/metric/manual_reader_test.go index 9583d0396..b6b196f72 100644 --- a/sdk/metric/manual_reader_test.go +++ b/sdk/metric/manual_reader_test.go @@ -102,7 +102,7 @@ func TestManualReaderCollect(t *testing.T) { // Ensure the pipeline has a callback setup testM, err := meter.Int64ObservableCounter("test") assert.NoError(t, err) - _, err = meter.RegisterCallback(func(_ context.Context, o metric.Observer) error { + _, err = meter.RegisterCallback(func(context.Context, metric.Observer) error { return nil }, testM) assert.NoError(t, err) diff --git a/sdk/metric/meter_test.go b/sdk/metric/meter_test.go index 89a43ce7f..10d7f26b3 100644 --- a/sdk/metric/meter_test.go +++ b/sdk/metric/meter_test.go @@ -31,7 +31,7 @@ import ( ) // A meter should be able to make instruments concurrently. -func TestMeterInstrumentConcurrentSafe(t *testing.T) { +func TestMeterInstrumentConcurrentSafe(*testing.T) { wg := &sync.WaitGroup{} wg.Add(12) @@ -92,7 +92,7 @@ func TestMeterInstrumentConcurrentSafe(t *testing.T) { var emptyCallback metric.Callback = func(context.Context, metric.Observer) error { return nil } // A Meter Should be able register Callbacks Concurrently. -func TestMeterCallbackCreationConcurrency(t *testing.T) { +func TestMeterCallbackCreationConcurrency(*testing.T) { wg := &sync.WaitGroup{} wg.Add(2) @@ -1368,7 +1368,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) { }{ { name: "ObservableFloat64Counter", - register: func(t *testing.T, mtr metric.Meter) error { + register: func(_ *testing.T, mtr metric.Meter) error { ctr, err := mtr.Float64ObservableCounter("afcounter") if err != nil { return err @@ -1394,7 +1394,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) { }, { name: "ObservableFloat64UpDownCounter", - register: func(t *testing.T, mtr metric.Meter) error { + register: func(_ *testing.T, mtr metric.Meter) error { ctr, err := mtr.Float64ObservableUpDownCounter("afupdowncounter") if err != nil { return err @@ -1423,7 +1423,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) { }, { name: "ObservableFloat64Gauge", - register: func(t *testing.T, mtr metric.Meter) error { + register: func(_ *testing.T, mtr metric.Meter) error { ctr, err := mtr.Float64ObservableGauge("afgauge") if err != nil { return err @@ -1446,7 +1446,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) { }, { name: "ObservableInt64Counter", - register: func(t *testing.T, mtr metric.Meter) error { + register: func(_ *testing.T, mtr metric.Meter) error { ctr, err := mtr.Int64ObservableCounter("aicounter") if err != nil { return err @@ -1472,7 +1472,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) { }, { name: "ObservableInt64UpDownCounter", - register: func(t *testing.T, mtr metric.Meter) error { + register: func(_ *testing.T, mtr metric.Meter) error { ctr, err := mtr.Int64ObservableUpDownCounter("aiupdowncounter") if err != nil { return err @@ -1498,7 +1498,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) { }, { name: "ObservableInt64Gauge", - register: func(t *testing.T, mtr metric.Meter) error { + register: func(_ *testing.T, mtr metric.Meter) error { ctr, err := mtr.Int64ObservableGauge("aigauge") if err != nil { return err @@ -1521,7 +1521,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) { }, { name: "SyncFloat64Counter", - register: func(t *testing.T, mtr metric.Meter) error { + register: func(_ *testing.T, mtr metric.Meter) error { ctr, err := mtr.Float64Counter("sfcounter") if err != nil { return err @@ -1544,7 +1544,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) { }, { name: "SyncFloat64UpDownCounter", - register: func(t *testing.T, mtr metric.Meter) error { + register: func(_ *testing.T, mtr metric.Meter) error { ctr, err := mtr.Float64UpDownCounter("sfupdowncounter") if err != nil { return err @@ -1567,7 +1567,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) { }, { name: "SyncFloat64Histogram", - register: func(t *testing.T, mtr metric.Meter) error { + register: func(_ *testing.T, mtr metric.Meter) error { ctr, err := mtr.Float64Histogram("sfhistogram") if err != nil { return err @@ -1600,7 +1600,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) { }, { name: "SyncInt64Counter", - register: func(t *testing.T, mtr metric.Meter) error { + register: func(_ *testing.T, mtr metric.Meter) error { ctr, err := mtr.Int64Counter("sicounter") if err != nil { return err @@ -1623,7 +1623,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) { }, { name: "SyncInt64UpDownCounter", - register: func(t *testing.T, mtr metric.Meter) error { + register: func(_ *testing.T, mtr metric.Meter) error { ctr, err := mtr.Int64UpDownCounter("siupdowncounter") if err != nil { return err @@ -1646,7 +1646,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) { }, { name: "SyncInt64Histogram", - register: func(t *testing.T, mtr metric.Meter) error { + register: func(_ *testing.T, mtr metric.Meter) error { ctr, err := mtr.Int64Histogram("sihistogram") if err != nil { return err @@ -2127,7 +2127,7 @@ func TestMalformedSelectors(t *testing.T) { sfHistogram, err := meter.Float64Histogram("sync.float64.histogram") require.NoError(t, err) - callback := func(ctx context.Context, obs metric.Observer) error { + callback := func(_ context.Context, obs metric.Observer) error { obs.ObserveInt64(aiCounter, 1) obs.ObserveInt64(aiUpDownCounter, 1) obs.ObserveInt64(aiGauge, 1) @@ -2274,7 +2274,7 @@ func TestObservableDropAggregation(t *testing.T) { { name: "drop all metrics", views: []View{ - func(i Instrument) (Stream, bool) { + func(Instrument) (Stream, bool) { return Stream{Aggregation: AggregationDrop{}}, true }, }, @@ -2393,7 +2393,7 @@ func TestObservableDropAggregation(t *testing.T) { require.NoError(t, err) _, err = meter.RegisterCallback( - func(ctx context.Context, obs metric.Observer) error { + func(_ context.Context, obs metric.Observer) error { obs.ObserveInt64(intCnt, 1) obs.ObserveInt64(intUDCnt, 1) obs.ObserveInt64(intGaugeCnt, 1) @@ -2566,7 +2566,7 @@ func TestMeterProviderDelegation(t *testing.T) { require.NoError(t, err) floatGauge, err := meter.Float64ObservableGauge("observable.float.gauge") require.NoError(t, err) - _, err = meter.RegisterCallback(func(ctx context.Context, o metric.Observer) error { + _, err = meter.RegisterCallback(func(_ context.Context, o metric.Observer) error { o.ObserveInt64(int64Counter, int64(10)) o.ObserveInt64(int64UpDownCounter, int64(10)) o.ObserveInt64(int64Gauge, int64(10)) diff --git a/sdk/metric/periodic_reader_test.go b/sdk/metric/periodic_reader_test.go index be67b2b5a..c2a0fa56b 100644 --- a/sdk/metric/periodic_reader_test.go +++ b/sdk/metric/periodic_reader_test.go @@ -489,7 +489,7 @@ func TestPeriodicReaderCollect(t *testing.T) { // Ensure the pipeline has a callback setup testM, err := meter.Int64ObservableCounter("test") assert.NoError(t, err) - _, err = meter.RegisterCallback(func(_ context.Context, o metric.Observer) error { + _, err = meter.RegisterCallback(func(context.Context, metric.Observer) error { return nil }, testM) assert.NoError(t, err) diff --git a/sdk/metric/pipeline_registry_test.go b/sdk/metric/pipeline_registry_test.go index 175cd0a80..64bcf7078 100644 --- a/sdk/metric/pipeline_registry_test.go +++ b/sdk/metric/pipeline_registry_test.go @@ -184,7 +184,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) { { name: "Default/Drop", reader: NewManualReader( - WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDrop{} }), + WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDrop{} }), ), inst: instruments[InstrumentKindCounter], validate: func(t *testing.T, meas []aggregate.Measure[N], comps []aggregate.ComputeAggregation, err error) { @@ -326,7 +326,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) { { name: "Reader/Default/Cumulative/Sum/Monotonic", reader: NewManualReader( - WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }), + WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }), ), inst: instruments[InstrumentKindCounter], validate: assertSum[N](1, metricdata.CumulativeTemporality, true, [2]N{1, 4}), @@ -334,7 +334,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) { { name: "Reader/Default/Cumulative/Sum/NonMonotonic", reader: NewManualReader( - WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }), + WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }), ), inst: instruments[InstrumentKindUpDownCounter], validate: assertSum[N](1, metricdata.CumulativeTemporality, false, [2]N{1, 4}), @@ -342,7 +342,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) { { name: "Reader/Default/Cumulative/ExplicitBucketHistogram", reader: NewManualReader( - WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }), + WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }), ), inst: instruments[InstrumentKindHistogram], validate: assertHist[N](metricdata.CumulativeTemporality), @@ -350,7 +350,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) { { name: "Reader/Default/Cumulative/Gauge", reader: NewManualReader( - WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }), + WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }), ), inst: instruments[InstrumentKindGauge], validate: assertLastValue[N], @@ -358,7 +358,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) { { name: "Reader/Default/Cumulative/PrecomputedSum/Monotonic", reader: NewManualReader( - WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }), + WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }), ), inst: instruments[InstrumentKindObservableCounter], validate: assertSum[N](1, metricdata.CumulativeTemporality, true, [2]N{1, 3}), @@ -366,7 +366,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) { { name: "Reader/Default/Cumulative/PrecomputedSum/NonMonotonic", reader: NewManualReader( - WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }), + WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }), ), inst: instruments[InstrumentKindObservableUpDownCounter], validate: assertSum[N](1, metricdata.CumulativeTemporality, false, [2]N{1, 3}), @@ -374,7 +374,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) { { name: "Reader/Default/Gauge", reader: NewManualReader( - WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }), + WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }), ), inst: instruments[InstrumentKindObservableGauge], validate: assertLastValue[N], @@ -453,7 +453,7 @@ func TestPipelineRegistryCreateAggregators(t *testing.T) { renameView := NewView(Instrument{Name: "foo"}, Stream{Name: "bar"}) testRdr := NewManualReader() testRdrHistogram := NewManualReader( - WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationExplicitBucketHistogram{} }), + WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationExplicitBucketHistogram{} }), ) testCases := []struct { @@ -566,7 +566,7 @@ func TestPipelineRegistryResource(t *testing.T) { func TestPipelineRegistryCreateAggregatorsIncompatibleInstrument(t *testing.T) { testRdrHistogram := NewManualReader( - WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationSum{} }), + WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationSum{} }), ) readers := []Reader{testRdrHistogram} diff --git a/sdk/metric/pipeline_test.go b/sdk/metric/pipeline_test.go index 492626160..25eeda58b 100644 --- a/sdk/metric/pipeline_test.go +++ b/sdk/metric/pipeline_test.go @@ -76,7 +76,7 @@ func TestPipelineUsesResource(t *testing.T) { assert.Equal(t, res, output.Resource) } -func TestPipelineConcurrentSafe(t *testing.T) { +func TestPipelineConcurrentSafe(*testing.T) { pipe := newPipeline(nil, nil, nil, exemplar.AlwaysOffFilter, 0) ctx := context.Background() var output metricdata.ResourceMetrics @@ -511,7 +511,7 @@ func TestExemplars(t *testing.T) { t.Run("Custom reservoir", func(t *testing.T) { r := NewManualReader() - reservoirProviderSelector := func(agg Aggregation) exemplar.ReservoirProvider { + reservoirProviderSelector := func(Aggregation) exemplar.ReservoirProvider { return exemplar.FixedSizeReservoirProvider(2) } v1 := NewView(Instrument{Name: "int64-expo-histogram"}, Stream{ @@ -663,7 +663,7 @@ func TestPipelineProduceErrors(t *testing.T) { return nil }, // Callback 2: populates int64 observable data - func(ctx context.Context) error { + func(context.Context) error { callbackCounts[1]++ if shouldCancelContext { cancelCtx() @@ -671,7 +671,7 @@ func TestPipelineProduceErrors(t *testing.T) { return nil }, // Callback 3: return an error - func(ctx context.Context) error { + func(context.Context) error { callbackCounts[2]++ if shouldReturnError { return fmt.Errorf("test callback error") diff --git a/sdk/metric/provider_test.go b/sdk/metric/provider_test.go index 7e9361ee3..d60bac5e3 100644 --- a/sdk/metric/provider_test.go +++ b/sdk/metric/provider_test.go @@ -21,7 +21,7 @@ import ( "go.opentelemetry.io/otel/sdk/metric/metricdata" ) -func TestMeterConcurrentSafe(t *testing.T) { +func TestMeterConcurrentSafe(*testing.T) { const name = "TestMeterConcurrentSafe meter" mp := NewMeterProvider() @@ -35,7 +35,7 @@ func TestMeterConcurrentSafe(t *testing.T) { <-done } -func TestForceFlushConcurrentSafe(t *testing.T) { +func TestForceFlushConcurrentSafe(*testing.T) { mp := NewMeterProvider() done := make(chan struct{}) @@ -48,7 +48,7 @@ func TestForceFlushConcurrentSafe(t *testing.T) { <-done } -func TestShutdownConcurrentSafe(t *testing.T) { +func TestShutdownConcurrentSafe(*testing.T) { mp := NewMeterProvider() done := make(chan struct{}) @@ -61,7 +61,7 @@ func TestShutdownConcurrentSafe(t *testing.T) { <-done } -func TestMeterAndShutdownConcurrentSafe(t *testing.T) { +func TestMeterAndShutdownConcurrentSafe(*testing.T) { const name = "TestMeterAndShutdownConcurrentSafe meter" mp := NewMeterProvider() diff --git a/sdk/metric/reader_test.go b/sdk/metric/reader_test.go index eca3275b4..6c6c61a4c 100644 --- a/sdk/metric/reader_test.go +++ b/sdk/metric/reader_test.go @@ -83,7 +83,7 @@ func (ts *readerTestSuite) TestShutdownTwice() { func (ts *readerTestSuite) TestMultipleRegister() { ts.Reader = ts.Factory() p0 := testSDKProducer{ - produceFunc: func(ctx context.Context, rm *metricdata.ResourceMetrics) error { + produceFunc: func(_ context.Context, rm *metricdata.ResourceMetrics) error { // Differentiate this producer from the second by returning an // error. *rm = testResourceMetricsA @@ -103,12 +103,12 @@ func (ts *readerTestSuite) TestMultipleRegister() { func (ts *readerTestSuite) TestExternalProducerPartialSuccess() { ts.Reader = ts.Factory( WithProducer(testExternalProducer{ - produceFunc: func(ctx context.Context) ([]metricdata.ScopeMetrics, error) { + produceFunc: func(context.Context) ([]metricdata.ScopeMetrics, error) { return []metricdata.ScopeMetrics{}, assert.AnError }, }), WithProducer(testExternalProducer{ - produceFunc: func(ctx context.Context) ([]metricdata.ScopeMetrics, error) { + produceFunc: func(context.Context) ([]metricdata.ScopeMetrics, error) { return []metricdata.ScopeMetrics{testScopeMetricsB}, nil }, }), @@ -124,7 +124,7 @@ func (ts *readerTestSuite) TestExternalProducerPartialSuccess() { func (ts *readerTestSuite) TestSDKFailureBlocksExternalProducer() { ts.Reader = ts.Factory(WithProducer(testExternalProducer{})) ts.Reader.register(testSDKProducer{ - produceFunc: func(ctx context.Context, rm *metricdata.ResourceMetrics) error { + produceFunc: func(_ context.Context, rm *metricdata.ResourceMetrics) error { *rm = metricdata.ResourceMetrics{} return assert.AnError }, diff --git a/sdk/metric/view_test.go b/sdk/metric/view_test.go index 37bf37b7a..e66b39346 100644 --- a/sdk/metric/view_test.go +++ b/sdk/metric/view_test.go @@ -400,7 +400,7 @@ func TestNewViewReplace(t *testing.T) { Unit: "1", Aggregation: AggregationLastValue{}, }, - want: func(i Instrument) Stream { + want: func(Instrument) Stream { return Stream{ Name: alt, Description: alt, diff --git a/sdk/resource/builtin.go b/sdk/resource/builtin.go index cefe4ab91..b34dc16ea 100644 --- a/sdk/resource/builtin.go +++ b/sdk/resource/builtin.go @@ -72,7 +72,7 @@ func StringDetector(schemaURL string, k attribute.Key, f func() (string, error)) // Detect returns a *Resource that describes the string as a value // corresponding to attribute.Key as well as the specific schemaURL. -func (sd stringDetector) Detect(ctx context.Context) (*Resource, error) { +func (sd stringDetector) Detect(context.Context) (*Resource, error) { value, err := sd.F() if err != nil { return nil, fmt.Errorf("%s: %w", string(sd.K), err) diff --git a/sdk/resource/container.go b/sdk/resource/container.go index 0d8619715..fe36e43cb 100644 --- a/sdk/resource/container.go +++ b/sdk/resource/container.go @@ -27,7 +27,7 @@ const cgroupPath = "/proc/self/cgroup" // Detect returns a *Resource that describes the id of the container. // If no container id found, an empty resource will be returned. -func (cgroupContainerIDDetector) Detect(ctx context.Context) (*Resource, error) { +func (cgroupContainerIDDetector) Detect(context.Context) (*Resource, error) { containerID, err := containerID() if err != nil { return nil, err diff --git a/sdk/resource/container_test.go b/sdk/resource/container_test.go index d46f178b3..832cb24cc 100644 --- a/sdk/resource/container_test.go +++ b/sdk/resource/container_test.go @@ -141,14 +141,14 @@ func TestGetContainerIDFromCGroup(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - osStat = func(name string) (os.FileInfo, error) { + osStat = func(string) (os.FileInfo, error) { if tc.cgroupFileNotExist { return nil, os.ErrNotExist } return nil, nil } - osOpen = func(name string) (io.ReadCloser, error) { + osOpen = func(string) (io.ReadCloser, error) { if tc.openFileError != nil { return nil, tc.openFileError } diff --git a/sdk/resource/host_id.go b/sdk/resource/host_id.go index 781903923..1cf3afa59 100644 --- a/sdk/resource/host_id.go +++ b/sdk/resource/host_id.go @@ -96,7 +96,7 @@ func (r *hostIDReaderLinux) read() (string, error) { type hostIDDetector struct{} // Detect returns a *Resource containing the platform specific host id. -func (hostIDDetector) Detect(ctx context.Context) (*Resource, error) { +func (hostIDDetector) Detect(context.Context) (*Resource, error) { hostID, err := hostID() if err != nil { return nil, err diff --git a/sdk/resource/host_id_test.go b/sdk/resource/host_id_test.go index 07c835288..b200bdbdb 100644 --- a/sdk/resource/host_id_test.go +++ b/sdk/resource/host_id_test.go @@ -13,11 +13,11 @@ import ( var ( expectedHostID = "f2c668b579780554f70f72a063dc0864" - readFileNoError = func(filename string) (string, error) { + readFileNoError = func(string) (string, error) { return expectedHostID + "\n", nil } - readFileError = func(filename string) (string, error) { + readFileError = func(string) (string, error) { return "", errors.New("not found") } diff --git a/sdk/resource/os.go b/sdk/resource/os.go index 01b4d27a0..9255bbf9c 100644 --- a/sdk/resource/os.go +++ b/sdk/resource/os.go @@ -32,7 +32,7 @@ type ( // Detect returns a *Resource that describes the operating system type the // service is running on. -func (osTypeDetector) Detect(ctx context.Context) (*Resource, error) { +func (osTypeDetector) Detect(context.Context) (*Resource, error) { osType := runtimeOS() osTypeAttribute := mapRuntimeOSToSemconvOSType(osType) @@ -45,7 +45,7 @@ func (osTypeDetector) Detect(ctx context.Context) (*Resource, error) { // Detect returns a *Resource that describes the operating system the // service is running on. -func (osDescriptionDetector) Detect(ctx context.Context) (*Resource, error) { +func (osDescriptionDetector) Detect(context.Context) (*Resource, error) { description, err := osDescription() if err != nil { return nil, err diff --git a/sdk/resource/os_unix_test.go b/sdk/resource/os_unix_test.go index d63e4cd5d..f9ae12638 100644 --- a/sdk/resource/os_unix_test.go +++ b/sdk/resource/os_unix_test.go @@ -27,7 +27,7 @@ func fakeUnameProvider(buf *unix.Utsname) error { return nil } -func fakeUnameProviderWithError(buf *unix.Utsname) error { +func fakeUnameProviderWithError(*unix.Utsname) error { return fmt.Errorf("error invoking uname(2)") } diff --git a/sdk/resource/process.go b/sdk/resource/process.go index 6712ce80d..848e9931a 100644 --- a/sdk/resource/process.go +++ b/sdk/resource/process.go @@ -112,19 +112,19 @@ type ( // Detect returns a *Resource that describes the process identifier (PID) of the // executing process. -func (processPIDDetector) Detect(ctx context.Context) (*Resource, error) { +func (processPIDDetector) Detect(context.Context) (*Resource, error) { return NewWithAttributes(semconv.SchemaURL, semconv.ProcessPID(pid())), nil } // Detect returns a *Resource that describes the name of the process executable. -func (processExecutableNameDetector) Detect(ctx context.Context) (*Resource, error) { +func (processExecutableNameDetector) Detect(context.Context) (*Resource, error) { executableName := filepath.Base(commandArgs()[0]) return NewWithAttributes(semconv.SchemaURL, semconv.ProcessExecutableName(executableName)), nil } // Detect returns a *Resource that describes the full path of the process executable. -func (processExecutablePathDetector) Detect(ctx context.Context) (*Resource, error) { +func (processExecutablePathDetector) Detect(context.Context) (*Resource, error) { executablePath, err := executablePath() if err != nil { return nil, err @@ -135,13 +135,13 @@ func (processExecutablePathDetector) Detect(ctx context.Context) (*Resource, err // Detect returns a *Resource that describes all the command arguments as received // by the process. -func (processCommandArgsDetector) Detect(ctx context.Context) (*Resource, error) { +func (processCommandArgsDetector) Detect(context.Context) (*Resource, error) { return NewWithAttributes(semconv.SchemaURL, semconv.ProcessCommandArgs(commandArgs()...)), nil } // Detect returns a *Resource that describes the username of the user that owns the // process. -func (processOwnerDetector) Detect(ctx context.Context) (*Resource, error) { +func (processOwnerDetector) Detect(context.Context) (*Resource, error) { owner, err := owner() if err != nil { return nil, err @@ -152,17 +152,17 @@ func (processOwnerDetector) Detect(ctx context.Context) (*Resource, error) { // Detect returns a *Resource that describes the name of the compiler used to compile // this process image. -func (processRuntimeNameDetector) Detect(ctx context.Context) (*Resource, error) { +func (processRuntimeNameDetector) Detect(context.Context) (*Resource, error) { return NewWithAttributes(semconv.SchemaURL, semconv.ProcessRuntimeName(runtimeName())), nil } // Detect returns a *Resource that describes the version of the runtime of this process. -func (processRuntimeVersionDetector) Detect(ctx context.Context) (*Resource, error) { +func (processRuntimeVersionDetector) Detect(context.Context) (*Resource, error) { return NewWithAttributes(semconv.SchemaURL, semconv.ProcessRuntimeVersion(runtimeVersion())), nil } // Detect returns a *Resource that describes the runtime of this process. -func (processRuntimeDescriptionDetector) Detect(ctx context.Context) (*Resource, error) { +func (processRuntimeDescriptionDetector) Detect(context.Context) (*Resource, error) { runtimeDescription := fmt.Sprintf( "go version %s %s/%s", runtimeVersion(), runtimeOS(), runtimeArch()) diff --git a/sdk/resource/resource_test.go b/sdk/resource/resource_test.go index 43b5ca90f..471c4dcfd 100644 --- a/sdk/resource/resource_test.go +++ b/sdk/resource/resource_test.go @@ -796,7 +796,7 @@ func TestResourceConcurrentSafe(t *testing.T) { type fakeDetector struct{} -func (f fakeDetector) Detect(_ context.Context) (*resource.Resource, error) { +func (f fakeDetector) Detect(context.Context) (*resource.Resource, error) { // A bit pedantic, but resource.NewWithAttributes returns an empty Resource when // no attributes specified. We want to make sure that this is concurrent-safe. return resource.NewWithAttributes("https://opentelemetry.io/schemas/1.21.0"), nil diff --git a/sdk/trace/batch_span_processor.go b/sdk/trace/batch_span_processor.go index 9e192b572..a6e35919b 100644 --- a/sdk/trace/batch_span_processor.go +++ b/sdk/trace/batch_span_processor.go @@ -121,7 +121,7 @@ func NewBatchSpanProcessor(exporter SpanExporter, options ...BatchSpanProcessorO } // OnStart method does nothing. -func (bsp *batchSpanProcessor) OnStart(parent context.Context, s ReadWriteSpan) {} +func (bsp *batchSpanProcessor) OnStart(context.Context, ReadWriteSpan) {} // OnEnd method enqueues a ReadOnlySpan for later processing. func (bsp *batchSpanProcessor) OnEnd(s ReadOnlySpan) { diff --git a/sdk/trace/benchmark_test.go b/sdk/trace/benchmark_test.go index 8a78e7a2e..efed51349 100644 --- a/sdk/trace/benchmark_test.go +++ b/sdk/trace/benchmark_test.go @@ -367,7 +367,7 @@ func BenchmarkSpanProcessorVerboseLogging(b *testing.B) { b.Cleanup(func(l logr.Logger) func() { return func() { global.SetLogger(l) } }(global.GetLogger())) - global.SetLogger(funcr.New(func(prefix, args string) {}, funcr.Options{Verbosity: 5})) + global.SetLogger(funcr.New(func(string, string) {}, funcr.Options{Verbosity: 5})) tp := sdktrace.NewTracerProvider( sdktrace.WithBatcher( tracetest.NewNoopExporter(), diff --git a/sdk/trace/evictedqueue_test.go b/sdk/trace/evictedqueue_test.go index 662693958..f395659a2 100644 --- a/sdk/trace/evictedqueue_test.go +++ b/sdk/trace/evictedqueue_test.go @@ -45,7 +45,7 @@ func TestDropCount(t *testing.T) { t.Cleanup(func(l logr.Logger) func() { return func() { global.SetLogger(l) } }(global.GetLogger())) - global.SetLogger(funcr.New(func(prefix, args string) { + global.SetLogger(funcr.New(func(string, string) { called++ }, funcr.Options{Verbosity: 1})) diff --git a/sdk/trace/id_generator.go b/sdk/trace/id_generator.go index c8d3fb7e3..2164ec00d 100644 --- a/sdk/trace/id_generator.go +++ b/sdk/trace/id_generator.go @@ -32,7 +32,7 @@ type randomIDGenerator struct{} var _ IDGenerator = &randomIDGenerator{} // NewSpanID returns a non-zero span ID from a randomly-chosen sequence. -func (gen *randomIDGenerator) NewSpanID(ctx context.Context, traceID trace.TraceID) trace.SpanID { +func (gen *randomIDGenerator) NewSpanID(context.Context, trace.TraceID) trace.SpanID { sid := trace.SpanID{} for { binary.NativeEndian.PutUint64(sid[:], rand.Uint64()) @@ -45,7 +45,7 @@ func (gen *randomIDGenerator) NewSpanID(ctx context.Context, traceID trace.Trace // NewIDs returns a non-zero trace ID and a non-zero span ID from a // randomly-chosen sequence. -func (gen *randomIDGenerator) NewIDs(ctx context.Context) (trace.TraceID, trace.SpanID) { +func (gen *randomIDGenerator) NewIDs(context.Context) (trace.TraceID, trace.SpanID) { tid := trace.TraceID{} sid := trace.SpanID{} for { diff --git a/sdk/trace/provider_test.go b/sdk/trace/provider_test.go index f4a0a9e49..d0bd1e64e 100644 --- a/sdk/trace/provider_test.go +++ b/sdk/trace/provider_test.go @@ -57,7 +57,7 @@ func (t *shutdownSpanProcessor) ForceFlush(context.Context) error { func TestShutdownCallsTracerMethod(t *testing.T) { stp := NewTracerProvider() sp := &shutdownSpanProcessor{ - shutdown: func(ctx context.Context) error { + shutdown: func(context.Context) error { _ = stp.Tracer("abc") // must not deadlock return nil }, diff --git a/sdk/trace/simple_span_processor_test.go b/sdk/trace/simple_span_processor_test.go index 137a37b3f..4aa4ea39c 100644 --- a/sdk/trace/simple_span_processor_test.go +++ b/sdk/trace/simple_span_processor_test.go @@ -18,7 +18,7 @@ type simpleTestExporter struct { shutdown bool } -func (t *simpleTestExporter) ExportSpans(ctx context.Context, spans []ReadOnlySpan) error { +func (t *simpleTestExporter) ExportSpans(_ context.Context, spans []ReadOnlySpan) error { t.spans = append(t.spans, spans...) return nil } diff --git a/sdk/trace/span_processor_test.go b/sdk/trace/span_processor_test.go index 4bff69727..81aec7541 100644 --- a/sdk/trace/span_processor_test.go +++ b/sdk/trace/span_processor_test.go @@ -52,7 +52,7 @@ func (t *testSpanProcessor) OnEnd(s ReadOnlySpan) { t.spansEnded = append(t.spansEnded, s) } -func (t *testSpanProcessor) Shutdown(_ context.Context) error { +func (t *testSpanProcessor) Shutdown(context.Context) error { if t == nil { return nil } diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index e336ac0d3..6bff7f2a3 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -1148,7 +1148,7 @@ func TestChildSpanCount(t *testing.T) { } } -func TestNilSpanEnd(t *testing.T) { +func TestNilSpanEnd(*testing.T) { var span *recordingSpan span.End() } @@ -1824,7 +1824,7 @@ func TestSamplerTraceState(t *testing.T) { clearer := func(prefix string) Sampler { return &stateSampler{ prefix: prefix, - f: func(t trace.TraceState) trace.TraceState { return trace.TraceState{} }, + f: func(trace.TraceState) trace.TraceState { return trace.TraceState{} }, } } @@ -1943,7 +1943,7 @@ func (gen *testIDGenerator) NewIDs(ctx context.Context) (trace.TraceID, trace.Sp return traceID, spanID } -func (gen *testIDGenerator) NewSpanID(ctx context.Context, traceID trace.TraceID) trace.SpanID { +func (gen *testIDGenerator) NewSpanID(context.Context, trace.TraceID) trace.SpanID { spanIDHex := fmt.Sprintf("%016x", gen.spanID) spanID, _ := trace.SpanIDFromHex(spanIDHex) gen.spanID++ diff --git a/trace/noop.go b/trace/noop.go index 0f56e4dbb..eeb23c9eb 100644 --- a/trace/noop.go +++ b/trace/noop.go @@ -37,7 +37,7 @@ var _ Tracer = noopTracer{} // Start carries forward a non-recording Span, if one is present in the context, otherwise it // creates a no-op Span. -func (t noopTracer) Start(ctx context.Context, name string, _ ...SpanStartOption) (context.Context, Span) { +func (t noopTracer) Start(ctx context.Context, _ string, _ ...SpanStartOption) (context.Context, Span) { span := SpanFromContext(ctx) if _, ok := span.(nonRecordingSpan); !ok { // span is likely already a noopSpan, but let's be sure diff --git a/trace_test.go b/trace_test.go index 9aa1ba428..21d73421d 100644 --- a/trace_test.go +++ b/trace_test.go @@ -17,7 +17,7 @@ type testTracerProvider struct{ embedded.TracerProvider } var _ trace.TracerProvider = &testTracerProvider{} -func (*testTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer { +func (*testTracerProvider) Tracer(string, ...trace.TracerOption) trace.Tracer { return noop.NewTracerProvider().Tracer("") }