1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-08-10 22:31:50 +02:00

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 <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL
2025-08-04 21:48:04 +02:00
committed by GitHub
parent d5b5b05984
commit d464abf1f3
75 changed files with 239 additions and 239 deletions

View File

@@ -181,6 +181,7 @@ linters:
- fmt.Print
- fmt.Printf
- fmt.Println
- name: unused-parameter
- name: unnecessary-stmt
- name: use-any
- name: useless-break

View File

@@ -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))

View File

@@ -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,
},

View File

@@ -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{

View File

@@ -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(),
}

View File

@@ -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.
}

View File

@@ -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
}

View File

@@ -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")),
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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(),

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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.

View File

@@ -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"))

View File

@@ -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()

View File

@@ -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
}

View File

@@ -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,

View File

@@ -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)

View File

@@ -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,

View File

@@ -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)

View File

@@ -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()

View File

@@ -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("")
},
})

View File

@@ -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{})

View File

@@ -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

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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),

View File

@@ -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("")
}

View File

@@ -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})

View File

@@ -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}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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)
}
}

View File

@@ -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)
}
}

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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))

View File

@@ -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)

View File

@@ -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}

View File

@@ -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")

View File

@@ -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()

View File

@@ -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
},

View File

@@ -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,

View File

@@ -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)

View File

@@ -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

View File

@@ -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
}

View File

@@ -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

View File

@@ -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")
}

View File

@@ -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

View File

@@ -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)")
}

View File

@@ -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())

View File

@@ -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

View File

@@ -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) {

View File

@@ -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(),

View File

@@ -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}))

View File

@@ -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 {

View File

@@ -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
},

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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++

View File

@@ -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

View File

@@ -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("")
}