From 5dff273a1ee5b260a81767968d3dd5c6ddf17e55 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Mon, 16 Oct 2023 10:02:21 -0700 Subject: [PATCH] Use gofumpt instead of gofmt (#4623) * Use gofumpt instead of gofmt in golangci-lint conf * Run gofumpt fixes * Format generated templates --------- Co-authored-by: Chester Cheung --- .golangci.yml | 2 +- attribute/key_test.go | 4 +- .../internal/ocmetric/metric_test.go | 28 +++++---- bridge/opentracing/bridge.go | 12 ++-- bridge/opentracing/bridge_test.go | 8 +-- bridge/opentracing/internal/mock.go | 12 ++-- bridge/opentracing/test/bridge_grpc_test.go | 3 + bridge/opentracing/wrapper.go | 6 +- example/namedtracer/foo/foo.go | 4 +- .../otlpmetric/otlpmetricgrpc/client_test.go | 2 + .../internal/oconf/options_test.go | 2 +- .../otlpmetricgrpc/internal/otest/client.go | 2 +- .../internal/transform/metricdata_test.go | 2 +- .../otlpmetric/otlpmetrichttp/client_test.go | 2 + .../internal/oconf/options_test.go | 2 +- .../otlpmetrichttp/internal/otest/client.go | 2 +- .../internal/transform/metricdata_test.go | 2 +- exporters/otlp/otlptrace/exporter.go | 6 +- .../internal/tracetransform/span_test.go | 6 +- .../internal/otlpconfig/options_test.go | 2 +- .../otlptrace/otlptracehttp/example_test.go | 10 ++-- .../internal/otlpconfig/options_test.go | 2 +- exporters/prometheus/exporter_test.go | 2 +- exporters/stdout/stdoutmetric/example_test.go | 4 +- exporters/stdout/stdoutmetric/exporter.go | 4 +- exporters/stdout/stdouttrace/example_test.go | 10 ++-- .../zipkin/internal/internaltest/harness.go | 4 +- .../internaltest/text_map_carrier_test.go | 4 +- .../zipkin/internal/matchers/expectation.go | 4 +- internal/attribute/attribute_test.go | 12 ++-- internal/global/instruments.go | 60 +++++++++++-------- internal/global/instruments_test.go | 4 ++ internal/internaltest/harness.go | 4 +- .../internaltest/text_map_carrier_test.go | 4 +- internal/matchers/expectation.go | 4 +- internal/shared/internaltest/harness.go.tmpl | 4 +- .../text_map_carrier_test.go.tmpl | 4 +- internal/shared/matchers/expectation.go.tmpl | 4 +- .../otlpmetric/oconf/options_test.go.tmpl | 2 +- .../otlp/otlpmetric/otest/client.go.tmpl | 2 +- .../transform/metricdata_test.go.tmpl | 2 +- .../otlptrace/otlpconfig/options_test.go.tmpl | 2 +- propagation/propagation_test.go | 4 +- propagation/trace_context.go | 6 +- sdk/internal/internaltest/harness.go | 4 +- .../internaltest/text_map_carrier_test.go | 4 +- sdk/internal/matchers/expectation.go | 4 +- sdk/metric/config_test.go | 1 + sdk/metric/instrument.go | 32 ++++++---- .../aggregate/exponential_histogram.go | 2 +- sdk/metric/manual_reader_test.go | 6 +- sdk/metric/meter.go | 10 ++-- sdk/metric/meter_test.go | 3 + .../metricdata/metricdatatest/comparisons.go | 1 + sdk/metric/periodic_reader.go | 3 +- sdk/metric/periodic_reader_test.go | 6 +- sdk/metric/pipeline_registry_test.go | 3 +- sdk/metric/reader_test.go | 3 +- sdk/resource/auto.go | 10 ++-- sdk/resource/benchmark_test.go | 6 ++ sdk/resource/env.go | 6 +- sdk/resource/export_test.go | 4 +- sdk/resource/os.go | 7 ++- sdk/resource/process.go | 36 ++++++----- sdk/trace/benchmark_test.go | 1 + sdk/trace/span.go | 6 +- .../span_processor_filter_example_test.go | 1 + sdk/trace/trace_test.go | 3 +- sdk/trace/tracetest/span.go | 1 + trace/config.go | 1 + trace/trace.go | 12 ++-- trace/trace_test.go | 14 ++--- trace/tracestate_test.go | 3 +- 73 files changed, 255 insertions(+), 209 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6e8eeec00..7121593d5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,7 +12,7 @@ linters: - depguard - errcheck - godot - - gofmt + - gofumpt - goimports - gosimple - govet diff --git a/attribute/key_test.go b/attribute/key_test.go index 6d9f0fedd..1c739714e 100644 --- a/attribute/key_test.go +++ b/attribute/key_test.go @@ -41,7 +41,7 @@ func TestDefined(t *testing.T) { }, } { t.Run(testcase.name, func(t *testing.T) { - //func (k attribute.Key) Defined() bool { + // func (k attribute.Key) Defined() bool { have := testcase.k.Defined() if have != testcase.want { t.Errorf("Want: %v, but have: %v", testcase.want, have) @@ -91,7 +91,7 @@ func TestEmit(t *testing.T) { }, } { t.Run(testcase.name, func(t *testing.T) { - //proto: func (v attribute.Value) Emit() string { + // proto: func (v attribute.Value) Emit() string { have := testcase.v.Emit() if have != testcase.want { t.Errorf("Want: %s, but have: %s", testcase.want, have) diff --git a/bridge/opencensus/internal/ocmetric/metric_test.go b/bridge/opencensus/internal/ocmetric/metric_test.go index 76acbc800..a3258c6b1 100644 --- a/bridge/opencensus/internal/ocmetric/metric_test.go +++ b/bridge/opencensus/internal/ocmetric/metric_test.go @@ -56,7 +56,6 @@ func TestConvertMetrics(t *testing.T) { }, TimeSeries: []*ocmetricdata.TimeSeries{ { - LabelValues: []ocmetricdata.LabelValue{ { Value: "hello", @@ -370,7 +369,8 @@ func TestConvertMetrics(t *testing.T) { }, }, }, - }, { + }, + { desc: "histogram without data points", input: []*ocmetricdata.Metric{ { @@ -393,7 +393,8 @@ func TestConvertMetrics(t *testing.T) { }, }, }, - }, { + }, + { desc: "sum without data points", input: []*ocmetricdata.Metric{ { @@ -417,7 +418,8 @@ func TestConvertMetrics(t *testing.T) { }, }, }, - }, { + }, + { desc: "gauge without data points", input: []*ocmetricdata.Metric{ { @@ -439,7 +441,8 @@ func TestConvertMetrics(t *testing.T) { }, }, }, - }, { + }, + { desc: "histogram with negative count", input: []*ocmetricdata.Metric{ { @@ -462,7 +465,8 @@ func TestConvertMetrics(t *testing.T) { }, }, expectedErr: errNegativeDistributionCount, - }, { + }, + { desc: "histogram with negative bucket count", input: []*ocmetricdata.Metric{ { @@ -489,7 +493,8 @@ func TestConvertMetrics(t *testing.T) { }, }, expectedErr: errNegativeBucketCount, - }, { + }, + { desc: "histogram with non-histogram datapoint type", input: []*ocmetricdata.Metric{ { @@ -510,7 +515,8 @@ func TestConvertMetrics(t *testing.T) { }, }, expectedErr: errMismatchedValueTypes, - }, { + }, + { desc: "sum with non-sum datapoint type", input: []*ocmetricdata.Metric{ { @@ -531,7 +537,8 @@ func TestConvertMetrics(t *testing.T) { }, }, expectedErr: errMismatchedValueTypes, - }, { + }, + { desc: "gauge with non-gauge datapoint type", input: []*ocmetricdata.Metric{ { @@ -552,7 +559,8 @@ func TestConvertMetrics(t *testing.T) { }, }, expectedErr: errMismatchedValueTypes, - }, { + }, + { desc: "unsupported Gauge Distribution type", input: []*ocmetricdata.Metric{ { diff --git a/bridge/opentracing/bridge.go b/bridge/opentracing/bridge.go index 50ff21a19..7dc81f56a 100644 --- a/bridge/opentracing/bridge.go +++ b/bridge/opentracing/bridge.go @@ -317,8 +317,10 @@ type BridgeTracer struct { propagator propagation.TextMapPropagator } -var _ ot.Tracer = &BridgeTracer{} -var _ ot.TracerContextWithSpanExtension = &BridgeTracer{} +var ( + _ ot.Tracer = &BridgeTracer{} + _ ot.TracerContextWithSpanExtension = &BridgeTracer{} +) // NewBridgeTracer creates a new BridgeTracer. The new tracer forwards // the calls to the OpenTelemetry Noop tracer, so it should be @@ -829,15 +831,13 @@ func newTextMapWrapperForInject(carrier interface{}) (*textMapWrapper, error) { return t, nil } -type textMapWriter struct { -} +type textMapWriter struct{} func (t *textMapWriter) Set(key string, value string) { // maybe print a warning log. } -type textMapReader struct { -} +type textMapReader struct{} func (t *textMapReader) ForeachKey(handler func(key, val string) error) error { return nil // maybe print a warning log. diff --git a/bridge/opentracing/bridge_test.go b/bridge/opentracing/bridge_test.go index 47d26916a..bbeb3f9fb 100644 --- a/bridge/opentracing/bridge_test.go +++ b/bridge/opentracing/bridge_test.go @@ -35,8 +35,7 @@ import ( "go.opentelemetry.io/otel/trace" ) -type testOnlyTextMapReader struct { -} +type testOnlyTextMapReader struct{} func newTestOnlyTextMapReader() *testOnlyTextMapReader { return &testOnlyTextMapReader{} @@ -144,8 +143,7 @@ var ( spanID trace.SpanID = [8]byte{byte(11)} ) -type testTextMapPropagator struct { -} +type testTextMapPropagator struct{} func (t testTextMapPropagator) Inject(ctx context.Context, carrier propagation.TextMapCarrier) { carrier.Set(testHeader, strings.Join([]string{traceID.String(), spanID.String()}, ":")) @@ -163,7 +161,7 @@ func (t testTextMapPropagator) Extract(ctx context.Context, carrier propagation. return ctx } - var exist = false + exist := false for _, key := range carrier.Keys() { if strings.EqualFold(testHeader, key) { diff --git a/bridge/opentracing/internal/mock.go b/bridge/opentracing/internal/mock.go index 64e956042..e9d90750a 100644 --- a/bridge/opentracing/internal/mock.go +++ b/bridge/opentracing/internal/mock.go @@ -54,8 +54,10 @@ type MockTracer struct { rand *rand.Rand } -var _ trace.Tracer = &MockTracer{} -var _ migration.DeferredContextSetupTracerExtension = &MockTracer{} +var ( + _ trace.Tracer = &MockTracer{} + _ migration.DeferredContextSetupTracerExtension = &MockTracer{} +) func NewMockTracer() *MockTracer { return &MockTracer{ @@ -195,8 +197,10 @@ type MockSpan struct { Events []MockEvent } -var _ trace.Span = &MockSpan{} -var _ migration.OverrideTracerSpanExtension = &MockSpan{} +var ( + _ trace.Span = &MockSpan{} + _ migration.OverrideTracerSpanExtension = &MockSpan{} +) func (s *MockSpan) SpanContext() trace.SpanContext { return s.spanContext diff --git a/bridge/opentracing/test/bridge_grpc_test.go b/bridge/opentracing/test/bridge_grpc_test.go index 4843cbfd2..6b2208f6d 100644 --- a/bridge/opentracing/test/bridge_grpc_test.go +++ b/bridge/opentracing/test/bridge_grpc_test.go @@ -38,12 +38,15 @@ type testGRPCServer struct{} func (*testGRPCServer) UnaryCall(ctx context.Context, r *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { return &testpb.SimpleResponse{Payload: r.Payload * 2}, nil } + func (*testGRPCServer) StreamingOutputCall(*testpb.SimpleRequest, testpb.TestService_StreamingOutputCallServer) error { return nil } + func (*testGRPCServer) StreamingInputCall(testpb.TestService_StreamingInputCallServer) error { return nil } + func (*testGRPCServer) StreamingBidirectionalCall(testpb.TestService_StreamingBidirectionalCallServer) error { return nil } diff --git a/bridge/opentracing/wrapper.go b/bridge/opentracing/wrapper.go index 3e348c455..c251f8e2c 100644 --- a/bridge/opentracing/wrapper.go +++ b/bridge/opentracing/wrapper.go @@ -60,8 +60,10 @@ type WrapperTracer struct { tracer trace.Tracer } -var _ trace.Tracer = &WrapperTracer{} -var _ migration.DeferredContextSetupTracerExtension = &WrapperTracer{} +var ( + _ trace.Tracer = &WrapperTracer{} + _ migration.DeferredContextSetupTracerExtension = &WrapperTracer{} +) // NewWrapperTracer wraps the passed tracer and also talks to the // passed bridge tracer when setting up the context with the new diff --git a/example/namedtracer/foo/foo.go b/example/namedtracer/foo/foo.go index 1193f8ad0..074912e26 100644 --- a/example/namedtracer/foo/foo.go +++ b/example/namedtracer/foo/foo.go @@ -22,9 +22,7 @@ import ( "go.opentelemetry.io/otel/trace" ) -var ( - lemonsKey = attribute.Key("ex.com/lemons") -) +var lemonsKey = attribute.Key("ex.com/lemons") // SubOperation is an example to demonstrate the use of named tracer. // It creates a named tracer with its package path. diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/client_test.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/client_test.go index 1de64a772..bc766f5a2 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/client_test.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/client_test.go @@ -136,9 +136,11 @@ type clientShim struct { func (clientShim) Temporality(metric.InstrumentKind) metricdata.Temporality { return metricdata.CumulativeTemporality } + func (clientShim) Aggregation(metric.InstrumentKind) metric.Aggregation { return nil } + func (clientShim) ForceFlush(ctx context.Context) error { return ctx.Err() } diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go index 8687acabc..64457efbf 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go @@ -203,7 +203,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { if grpcOption { - //TODO: make sure gRPC's credentials actually works + // TODO: make sure gRPC's credentials actually works assert.NotNil(t, c.Metrics.GRPCCredentials) } else { // nolint:staticcheck // ignoring tlsCert.RootCAs.Subjects is deprecated ERR because cert does not come from SystemCertPool. diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/otest/client.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/otest/client.go index 3bb415e44..154d4dd3c 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/otest/client.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/otest/client.go @@ -38,7 +38,7 @@ import ( var ( // Sat Jan 01 2000 00:00:00 GMT+0000. - start = time.Date(2000, time.January, 01, 0, 0, 0, 0, time.FixedZone("GMT", 0)) + start = time.Date(2000, time.January, 0o1, 0, 0, 0, 0, time.FixedZone("GMT", 0)) end = start.Add(30 * time.Second) kvAlice = &cpb.KeyValue{Key: "user", Value: &cpb.AnyValue{ diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata_test.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata_test.go index b94c48dae..676e57856 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata_test.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata_test.go @@ -40,7 +40,7 @@ type unknownAggT struct { var ( // Sat Jan 01 2000 00:00:00 GMT+0000. - start = time.Date(2000, time.January, 01, 0, 0, 0, 0, time.FixedZone("GMT", 0)) + start = time.Date(2000, time.January, 0o1, 0, 0, 0, 0, time.FixedZone("GMT", 0)) end = start.Add(30 * time.Second) alice = attribute.NewSet(attribute.String("user", "alice")) diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go index 36075c19e..ff06fcf5e 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go @@ -40,9 +40,11 @@ type clientShim struct { func (clientShim) Temporality(metric.InstrumentKind) metricdata.Temporality { return metricdata.CumulativeTemporality } + func (clientShim) Aggregation(metric.InstrumentKind) metric.Aggregation { return nil } + func (clientShim) ForceFlush(ctx context.Context) error { return ctx.Err() } diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go index bb34337a1..1da4a6f2f 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go @@ -203,7 +203,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { if grpcOption { - //TODO: make sure gRPC's credentials actually works + // TODO: make sure gRPC's credentials actually works assert.NotNil(t, c.Metrics.GRPCCredentials) } else { // nolint:staticcheck // ignoring tlsCert.RootCAs.Subjects is deprecated ERR because cert does not come from SystemCertPool. diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/otest/client.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/otest/client.go index 4169c9d96..41374b956 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/otest/client.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/otest/client.go @@ -38,7 +38,7 @@ import ( var ( // Sat Jan 01 2000 00:00:00 GMT+0000. - start = time.Date(2000, time.January, 01, 0, 0, 0, 0, time.FixedZone("GMT", 0)) + start = time.Date(2000, time.January, 0o1, 0, 0, 0, 0, time.FixedZone("GMT", 0)) end = start.Add(30 * time.Second) kvAlice = &cpb.KeyValue{Key: "user", Value: &cpb.AnyValue{ diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata_test.go index b94c48dae..676e57856 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata_test.go @@ -40,7 +40,7 @@ type unknownAggT struct { var ( // Sat Jan 01 2000 00:00:00 GMT+0000. - start = time.Date(2000, time.January, 01, 0, 0, 0, 0, time.FixedZone("GMT", 0)) + start = time.Date(2000, time.January, 0o1, 0, 0, 0, 0, time.FixedZone("GMT", 0)) end = start.Add(30 * time.Second) alice = attribute.NewSet(attribute.String("user", "alice")) diff --git a/exporters/otlp/otlptrace/exporter.go b/exporters/otlp/otlptrace/exporter.go index 0dbe15555..b46a38d60 100644 --- a/exporters/otlp/otlptrace/exporter.go +++ b/exporters/otlp/otlptrace/exporter.go @@ -24,9 +24,7 @@ import ( tracesdk "go.opentelemetry.io/otel/sdk/trace" ) -var ( - errAlreadyStarted = errors.New("already started") -) +var errAlreadyStarted = errors.New("already started") // Exporter exports trace data in the OTLP wire format. type Exporter struct { @@ -55,7 +53,7 @@ func (e *Exporter) ExportSpans(ctx context.Context, ss []tracesdk.ReadOnlySpan) // Start establishes a connection to the receiving endpoint. func (e *Exporter) Start(ctx context.Context) error { - var err = errAlreadyStarted + err := errAlreadyStarted e.startOnce.Do(func() { e.mu.Lock() e.started = true diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go index 7e0be6cab..7a4fa1e91 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go @@ -213,12 +213,14 @@ func TestSpanData(t *testing.T) { StartTime: startTime, EndTime: endTime, Events: []tracesdk.Event{ - {Time: startTime, + { + Time: startTime, Attributes: []attribute.KeyValue{ attribute.Int64("CompressedByteSize", 512), }, }, - {Time: endTime, + { + Time: endTime, Attributes: []attribute.KeyValue{ attribute.String("EventType", "Recv"), }, diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go index e947cdcb8..567f12f10 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go @@ -201,7 +201,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { if grpcOption { - //TODO: make sure gRPC's credentials actually works + // TODO: make sure gRPC's credentials actually works assert.NotNil(t, c.Traces.GRPCCredentials) } else { // nolint:staticcheck // ignoring tlsCert.RootCAs.Subjects is deprecated ERR because cert does not come from SystemCertPool. diff --git a/exporters/otlp/otlptrace/otlptracehttp/example_test.go b/exporters/otlp/otlptrace/otlptracehttp/example_test.go index 489d6400e..d6bf4b0ab 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/example_test.go +++ b/exporters/otlp/otlptrace/otlptracehttp/example_test.go @@ -32,12 +32,10 @@ const ( instrumentationVersion = "0.1.0" ) -var ( - tracer = otel.GetTracerProvider().Tracer( - instrumentationName, - trace.WithInstrumentationVersion(instrumentationVersion), - trace.WithSchemaURL(semconv.SchemaURL), - ) +var tracer = otel.GetTracerProvider().Tracer( + instrumentationName, + trace.WithInstrumentationVersion(instrumentationVersion), + trace.WithSchemaURL(semconv.SchemaURL), ) func add(ctx context.Context, x, y int64) int64 { diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go index 5fbda6d46..4c7a525a9 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go @@ -201,7 +201,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { if grpcOption { - //TODO: make sure gRPC's credentials actually works + // TODO: make sure gRPC's credentials actually works assert.NotNil(t, c.Traces.GRPCCredentials) } else { // nolint:staticcheck // ignoring tlsCert.RootCAs.Subjects is deprecated ERR because cert does not come from SystemCertPool. diff --git a/exporters/prometheus/exporter_test.go b/exporters/prometheus/exporter_test.go index 89fc87df3..0f211d831 100644 --- a/exporters/prometheus/exporter_test.go +++ b/exporters/prometheus/exporter_test.go @@ -746,7 +746,7 @@ func TestDuplicateMetrics(t *testing.T) { tc.recordMetrics(ctx, meterA, meterB) - var match = false + match := false for _, filename := range tc.possibleExpectedFiles { file, ferr := os.Open(filename) require.NoError(t, ferr) diff --git a/exporters/stdout/stdoutmetric/example_test.go b/exporters/stdout/stdoutmetric/example_test.go index c0e250f4e..6cc978ebb 100644 --- a/exporters/stdout/stdoutmetric/example_test.go +++ b/exporters/stdout/stdoutmetric/example_test.go @@ -31,7 +31,7 @@ import ( var ( // Sat Jan 01 2000 00:00:00 GMT+0000. - now = time.Date(2000, time.January, 01, 0, 0, 0, 0, time.FixedZone("GMT", 0)) + now = time.Date(2000, time.January, 0o1, 0, 0, 0, 0, time.FixedZone("GMT", 0)) res = resource.NewSchemaless( semconv.ServiceName("stdoutmetric-example"), @@ -158,7 +158,7 @@ func Example() { // Ensure the periodic reader is cleaned up by shutting down the sdk. _ = sdk.Shutdown(ctx) - //Output: + // Output: // { // "Resource": [ // { diff --git a/exporters/stdout/stdoutmetric/exporter.go b/exporters/stdout/stdoutmetric/exporter.go index c223a84da..faedf9a91 100644 --- a/exporters/stdout/stdoutmetric/exporter.go +++ b/exporters/stdout/stdoutmetric/exporter.go @@ -106,9 +106,7 @@ func redactTimestamps(orig *metricdata.ResourceMetrics) { } } -var ( - errUnknownAggType = errors.New("unknown aggregation type") -) +var errUnknownAggType = errors.New("unknown aggregation type") func redactAggregationTimestamps(orig metricdata.Aggregation) metricdata.Aggregation { switch a := orig.(type) { diff --git a/exporters/stdout/stdouttrace/example_test.go b/exporters/stdout/stdouttrace/example_test.go index a3634296e..0abd72d10 100644 --- a/exporters/stdout/stdouttrace/example_test.go +++ b/exporters/stdout/stdouttrace/example_test.go @@ -32,12 +32,10 @@ const ( instrumentationVersion = "0.1.0" ) -var ( - tracer = otel.GetTracerProvider().Tracer( - instrumentationName, - trace.WithInstrumentationVersion(instrumentationVersion), - trace.WithSchemaURL(semconv.SchemaURL), - ) +var tracer = otel.GetTracerProvider().Tracer( + instrumentationName, + trace.WithInstrumentationVersion(instrumentationVersion), + trace.WithSchemaURL(semconv.SchemaURL), ) func add(ctx context.Context, x, y int64) int64 { diff --git a/exporters/zipkin/internal/internaltest/harness.go b/exporters/zipkin/internal/internaltest/harness.go index d8118d4f3..53e8b3bf1 100644 --- a/exporters/zipkin/internal/internaltest/harness.go +++ b/exporters/zipkin/internal/internaltest/harness.go @@ -263,7 +263,7 @@ func (h *Harness) TestTracer(subjectFactory func() trace.Tracer) { } func (h *Harness) testSpan(tracerFactory func() trace.Tracer) { - var methods = map[string]func(span trace.Span){ + methods := map[string]func(span trace.Span){ "#End": func(span trace.Span) { span.End() }, @@ -283,7 +283,7 @@ func (h *Harness) testSpan(tracerFactory func() trace.Tracer) { span.SetAttributes(attribute.String("key1", "value"), attribute.Int("key2", 123)) }, } - var mechanisms = map[string]func() trace.Span{ + mechanisms := map[string]func() trace.Span{ "Span created via Tracer#Start": func() trace.Span { tracer := tracerFactory() _, subject := tracer.Start(context.Background(), "test") diff --git a/exporters/zipkin/internal/internaltest/text_map_carrier_test.go b/exporters/zipkin/internal/internaltest/text_map_carrier_test.go index faf713cc2..086c8af26 100644 --- a/exporters/zipkin/internal/internaltest/text_map_carrier_test.go +++ b/exporters/zipkin/internal/internaltest/text_map_carrier_test.go @@ -22,9 +22,7 @@ import ( "testing" ) -var ( - key, value = "test", "true" -) +var key, value = "test", "true" func TestTextMapCarrierKeys(t *testing.T) { tmc := NewTextMapCarrier(map[string]string{key: value}) diff --git a/exporters/zipkin/internal/matchers/expectation.go b/exporters/zipkin/internal/matchers/expectation.go index 411300d58..f890ca927 100644 --- a/exporters/zipkin/internal/matchers/expectation.go +++ b/exporters/zipkin/internal/matchers/expectation.go @@ -27,9 +27,7 @@ import ( "time" ) -var ( - stackTracePruneRE = regexp.MustCompile(`runtime\/debug|testing|internal\/matchers`) -) +var stackTracePruneRE = regexp.MustCompile(`runtime\/debug|testing|internal\/matchers`) type Expectation struct { t *testing.T diff --git a/internal/attribute/attribute_test.go b/internal/attribute/attribute_test.go index 3cba91173..05f4a0a53 100644 --- a/internal/attribute/attribute_test.go +++ b/internal/attribute/attribute_test.go @@ -39,16 +39,20 @@ var wrapBoolSliceValue = func(v interface{}) interface{} { } return nil } + var wrapStringSliceValue = func(v interface{}) interface{} { if vi, ok := v.([]string); ok { return StringSliceValue(vi) } return nil } -var wrapAsBoolSlice = func(v interface{}) interface{} { return AsBoolSlice(v) } -var wrapAsInt64Slice = func(v interface{}) interface{} { return AsInt64Slice(v) } -var wrapAsFloat64Slice = func(v interface{}) interface{} { return AsFloat64Slice(v) } -var wrapAsStringSlice = func(v interface{}) interface{} { return AsStringSlice(v) } + +var ( + wrapAsBoolSlice = func(v interface{}) interface{} { return AsBoolSlice(v) } + wrapAsInt64Slice = func(v interface{}) interface{} { return AsInt64Slice(v) } + wrapAsFloat64Slice = func(v interface{}) interface{} { return AsFloat64Slice(v) } + wrapAsStringSlice = func(v interface{}) interface{} { return AsStringSlice(v) } +) func TestSliceValue(t *testing.T) { type args struct { diff --git a/internal/global/instruments.go b/internal/global/instruments.go index a33eded87..ebb13c206 100644 --- a/internal/global/instruments.go +++ b/internal/global/instruments.go @@ -34,11 +34,13 @@ type afCounter struct { name string opts []metric.Float64ObservableCounterOption - delegate atomic.Value //metric.Float64ObservableCounter + delegate atomic.Value // metric.Float64ObservableCounter } -var _ unwrapper = (*afCounter)(nil) -var _ metric.Float64ObservableCounter = (*afCounter)(nil) +var ( + _ unwrapper = (*afCounter)(nil) + _ metric.Float64ObservableCounter = (*afCounter)(nil) +) func (i *afCounter) setDelegate(m metric.Meter) { ctr, err := m.Float64ObservableCounter(i.name, i.opts...) @@ -63,11 +65,13 @@ type afUpDownCounter struct { name string opts []metric.Float64ObservableUpDownCounterOption - delegate atomic.Value //metric.Float64ObservableUpDownCounter + delegate atomic.Value // metric.Float64ObservableUpDownCounter } -var _ unwrapper = (*afUpDownCounter)(nil) -var _ metric.Float64ObservableUpDownCounter = (*afUpDownCounter)(nil) +var ( + _ unwrapper = (*afUpDownCounter)(nil) + _ metric.Float64ObservableUpDownCounter = (*afUpDownCounter)(nil) +) func (i *afUpDownCounter) setDelegate(m metric.Meter) { ctr, err := m.Float64ObservableUpDownCounter(i.name, i.opts...) @@ -92,11 +96,13 @@ type afGauge struct { name string opts []metric.Float64ObservableGaugeOption - delegate atomic.Value //metric.Float64ObservableGauge + delegate atomic.Value // metric.Float64ObservableGauge } -var _ unwrapper = (*afGauge)(nil) -var _ metric.Float64ObservableGauge = (*afGauge)(nil) +var ( + _ unwrapper = (*afGauge)(nil) + _ metric.Float64ObservableGauge = (*afGauge)(nil) +) func (i *afGauge) setDelegate(m metric.Meter) { ctr, err := m.Float64ObservableGauge(i.name, i.opts...) @@ -121,11 +127,13 @@ type aiCounter struct { name string opts []metric.Int64ObservableCounterOption - delegate atomic.Value //metric.Int64ObservableCounter + delegate atomic.Value // metric.Int64ObservableCounter } -var _ unwrapper = (*aiCounter)(nil) -var _ metric.Int64ObservableCounter = (*aiCounter)(nil) +var ( + _ unwrapper = (*aiCounter)(nil) + _ metric.Int64ObservableCounter = (*aiCounter)(nil) +) func (i *aiCounter) setDelegate(m metric.Meter) { ctr, err := m.Int64ObservableCounter(i.name, i.opts...) @@ -150,11 +158,13 @@ type aiUpDownCounter struct { name string opts []metric.Int64ObservableUpDownCounterOption - delegate atomic.Value //metric.Int64ObservableUpDownCounter + delegate atomic.Value // metric.Int64ObservableUpDownCounter } -var _ unwrapper = (*aiUpDownCounter)(nil) -var _ metric.Int64ObservableUpDownCounter = (*aiUpDownCounter)(nil) +var ( + _ unwrapper = (*aiUpDownCounter)(nil) + _ metric.Int64ObservableUpDownCounter = (*aiUpDownCounter)(nil) +) func (i *aiUpDownCounter) setDelegate(m metric.Meter) { ctr, err := m.Int64ObservableUpDownCounter(i.name, i.opts...) @@ -179,11 +189,13 @@ type aiGauge struct { name string opts []metric.Int64ObservableGaugeOption - delegate atomic.Value //metric.Int64ObservableGauge + delegate atomic.Value // metric.Int64ObservableGauge } -var _ unwrapper = (*aiGauge)(nil) -var _ metric.Int64ObservableGauge = (*aiGauge)(nil) +var ( + _ unwrapper = (*aiGauge)(nil) + _ metric.Int64ObservableGauge = (*aiGauge)(nil) +) func (i *aiGauge) setDelegate(m metric.Meter) { ctr, err := m.Int64ObservableGauge(i.name, i.opts...) @@ -208,7 +220,7 @@ type sfCounter struct { name string opts []metric.Float64CounterOption - delegate atomic.Value //metric.Float64Counter + delegate atomic.Value // metric.Float64Counter } var _ metric.Float64Counter = (*sfCounter)(nil) @@ -234,7 +246,7 @@ type sfUpDownCounter struct { name string opts []metric.Float64UpDownCounterOption - delegate atomic.Value //metric.Float64UpDownCounter + delegate atomic.Value // metric.Float64UpDownCounter } var _ metric.Float64UpDownCounter = (*sfUpDownCounter)(nil) @@ -260,7 +272,7 @@ type sfHistogram struct { name string opts []metric.Float64HistogramOption - delegate atomic.Value //metric.Float64Histogram + delegate atomic.Value // metric.Float64Histogram } var _ metric.Float64Histogram = (*sfHistogram)(nil) @@ -286,7 +298,7 @@ type siCounter struct { name string opts []metric.Int64CounterOption - delegate atomic.Value //metric.Int64Counter + delegate atomic.Value // metric.Int64Counter } var _ metric.Int64Counter = (*siCounter)(nil) @@ -312,7 +324,7 @@ type siUpDownCounter struct { name string opts []metric.Int64UpDownCounterOption - delegate atomic.Value //metric.Int64UpDownCounter + delegate atomic.Value // metric.Int64UpDownCounter } var _ metric.Int64UpDownCounter = (*siUpDownCounter)(nil) @@ -338,7 +350,7 @@ type siHistogram struct { name string opts []metric.Int64HistogramOption - delegate atomic.Value //metric.Int64Histogram + delegate atomic.Value // metric.Int64Histogram } var _ metric.Int64Histogram = (*siHistogram)(nil) diff --git a/internal/global/instruments_test.go b/internal/global/instruments_test.go index c0ab914b6..7808f77da 100644 --- a/internal/global/instruments_test.go +++ b/internal/global/instruments_test.go @@ -168,9 +168,11 @@ type testCountingFloatInstrument struct { func (i *testCountingFloatInstrument) observe() { i.count++ } + func (i *testCountingFloatInstrument) Add(context.Context, float64, ...metric.AddOption) { i.count++ } + func (i *testCountingFloatInstrument) Record(context.Context, float64, ...metric.RecordOption) { i.count++ } @@ -190,9 +192,11 @@ type testCountingIntInstrument struct { func (i *testCountingIntInstrument) observe() { i.count++ } + func (i *testCountingIntInstrument) Add(context.Context, int64, ...metric.AddOption) { i.count++ } + func (i *testCountingIntInstrument) Record(context.Context, int64, ...metric.RecordOption) { i.count++ } diff --git a/internal/internaltest/harness.go b/internal/internaltest/harness.go index e84eed9e7..ce8e2035f 100644 --- a/internal/internaltest/harness.go +++ b/internal/internaltest/harness.go @@ -263,7 +263,7 @@ func (h *Harness) TestTracer(subjectFactory func() trace.Tracer) { } func (h *Harness) testSpan(tracerFactory func() trace.Tracer) { - var methods = map[string]func(span trace.Span){ + methods := map[string]func(span trace.Span){ "#End": func(span trace.Span) { span.End() }, @@ -283,7 +283,7 @@ func (h *Harness) testSpan(tracerFactory func() trace.Tracer) { span.SetAttributes(attribute.String("key1", "value"), attribute.Int("key2", 123)) }, } - var mechanisms = map[string]func() trace.Span{ + mechanisms := map[string]func() trace.Span{ "Span created via Tracer#Start": func() trace.Span { tracer := tracerFactory() _, subject := tracer.Start(context.Background(), "test") diff --git a/internal/internaltest/text_map_carrier_test.go b/internal/internaltest/text_map_carrier_test.go index faf713cc2..086c8af26 100644 --- a/internal/internaltest/text_map_carrier_test.go +++ b/internal/internaltest/text_map_carrier_test.go @@ -22,9 +22,7 @@ import ( "testing" ) -var ( - key, value = "test", "true" -) +var key, value = "test", "true" func TestTextMapCarrierKeys(t *testing.T) { tmc := NewTextMapCarrier(map[string]string{key: value}) diff --git a/internal/matchers/expectation.go b/internal/matchers/expectation.go index 9cf408258..f54f63afb 100644 --- a/internal/matchers/expectation.go +++ b/internal/matchers/expectation.go @@ -27,9 +27,7 @@ import ( "time" ) -var ( - stackTracePruneRE = regexp.MustCompile(`runtime\/debug|testing|internal\/matchers`) -) +var stackTracePruneRE = regexp.MustCompile(`runtime\/debug|testing|internal\/matchers`) type Expectation struct { t *testing.T diff --git a/internal/shared/internaltest/harness.go.tmpl b/internal/shared/internaltest/harness.go.tmpl index da3e7f186..7223b9d21 100644 --- a/internal/shared/internaltest/harness.go.tmpl +++ b/internal/shared/internaltest/harness.go.tmpl @@ -263,7 +263,7 @@ func (h *Harness) TestTracer(subjectFactory func() trace.Tracer) { } func (h *Harness) testSpan(tracerFactory func() trace.Tracer) { - var methods = map[string]func(span trace.Span){ + methods := map[string]func(span trace.Span){ "#End": func(span trace.Span) { span.End() }, @@ -283,7 +283,7 @@ func (h *Harness) testSpan(tracerFactory func() trace.Tracer) { span.SetAttributes(attribute.String("key1", "value"), attribute.Int("key2", 123)) }, } - var mechanisms = map[string]func() trace.Span{ + mechanisms := map[string]func() trace.Span{ "Span created via Tracer#Start": func() trace.Span { tracer := tracerFactory() _, subject := tracer.Start(context.Background(), "test") diff --git a/internal/shared/internaltest/text_map_carrier_test.go.tmpl b/internal/shared/internaltest/text_map_carrier_test.go.tmpl index faf713cc2..086c8af26 100644 --- a/internal/shared/internaltest/text_map_carrier_test.go.tmpl +++ b/internal/shared/internaltest/text_map_carrier_test.go.tmpl @@ -22,9 +22,7 @@ import ( "testing" ) -var ( - key, value = "test", "true" -) +var key, value = "test", "true" func TestTextMapCarrierKeys(t *testing.T) { tmc := NewTextMapCarrier(map[string]string{key: value}) diff --git a/internal/shared/matchers/expectation.go.tmpl b/internal/shared/matchers/expectation.go.tmpl index bdde84ea7..4002fec51 100644 --- a/internal/shared/matchers/expectation.go.tmpl +++ b/internal/shared/matchers/expectation.go.tmpl @@ -27,9 +27,7 @@ import ( "time" ) -var ( - stackTracePruneRE = regexp.MustCompile(`runtime\/debug|testing|internal\/matchers`) -) +var stackTracePruneRE = regexp.MustCompile(`runtime\/debug|testing|internal\/matchers`) type Expectation struct { t *testing.T diff --git a/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl b/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl index 16ddfdb7b..7c52efc51 100644 --- a/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl +++ b/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl @@ -203,7 +203,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { if grpcOption { - //TODO: make sure gRPC's credentials actually works + // TODO: make sure gRPC's credentials actually works assert.NotNil(t, c.Metrics.GRPCCredentials) } else { // nolint:staticcheck // ignoring tlsCert.RootCAs.Subjects is deprecated ERR because cert does not come from SystemCertPool. diff --git a/internal/shared/otlp/otlpmetric/otest/client.go.tmpl b/internal/shared/otlp/otlpmetric/otest/client.go.tmpl index 6c8be4982..37f25c9b4 100644 --- a/internal/shared/otlp/otlpmetric/otest/client.go.tmpl +++ b/internal/shared/otlp/otlpmetric/otest/client.go.tmpl @@ -38,7 +38,7 @@ import ( var ( // Sat Jan 01 2000 00:00:00 GMT+0000. - start = time.Date(2000, time.January, 01, 0, 0, 0, 0, time.FixedZone("GMT", 0)) + start = time.Date(2000, time.January, 0o1, 0, 0, 0, 0, time.FixedZone("GMT", 0)) end = start.Add(30 * time.Second) kvAlice = &cpb.KeyValue{Key: "user", Value: &cpb.AnyValue{ diff --git a/internal/shared/otlp/otlpmetric/transform/metricdata_test.go.tmpl b/internal/shared/otlp/otlpmetric/transform/metricdata_test.go.tmpl index b94c48dae..676e57856 100644 --- a/internal/shared/otlp/otlpmetric/transform/metricdata_test.go.tmpl +++ b/internal/shared/otlp/otlpmetric/transform/metricdata_test.go.tmpl @@ -40,7 +40,7 @@ type unknownAggT struct { var ( // Sat Jan 01 2000 00:00:00 GMT+0000. - start = time.Date(2000, time.January, 01, 0, 0, 0, 0, time.FixedZone("GMT", 0)) + start = time.Date(2000, time.January, 0o1, 0, 0, 0, 0, time.FixedZone("GMT", 0)) end = start.Add(30 * time.Second) alice = attribute.NewSet(attribute.String("user", "alice")) diff --git a/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl b/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl index fcf99f0ad..b83891a89 100644 --- a/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl +++ b/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl @@ -201,7 +201,7 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { if grpcOption { - //TODO: make sure gRPC's credentials actually works + // TODO: make sure gRPC's credentials actually works assert.NotNil(t, c.Traces.GRPCCredentials) } else { // nolint:staticcheck // ignoring tlsCert.RootCAs.Subjects is deprecated ERR because cert does not come from SystemCertPool. diff --git a/propagation/propagation_test.go b/propagation/propagation_test.go index 488d6551d..03fca2ff2 100644 --- a/propagation/propagation_test.go +++ b/propagation/propagation_test.go @@ -27,9 +27,7 @@ import ( type ctxKeyType uint -var ( - ctxKey ctxKeyType -) +var ctxKey ctxKeyType type carrier []string diff --git a/propagation/trace_context.go b/propagation/trace_context.go index 902692da0..75a8f3435 100644 --- a/propagation/trace_context.go +++ b/propagation/trace_context.go @@ -40,8 +40,10 @@ const ( // their proprietary information. type TraceContext struct{} -var _ TextMapPropagator = TraceContext{} -var traceCtxRegExp = regexp.MustCompile("^(?P[0-9a-f]{2})-(?P[a-f0-9]{32})-(?P[a-f0-9]{16})-(?P[a-f0-9]{2})(?:-.*)?$") +var ( + _ TextMapPropagator = TraceContext{} + traceCtxRegExp = regexp.MustCompile("^(?P[0-9a-f]{2})-(?P[a-f0-9]{32})-(?P[a-f0-9]{16})-(?P[a-f0-9]{2})(?:-.*)?$") +) // Inject set tracecontext from the Context into the carrier. func (tc TraceContext) Inject(ctx context.Context, carrier TextMapCarrier) { diff --git a/sdk/internal/internaltest/harness.go b/sdk/internal/internaltest/harness.go index f177b0567..b2d461ea0 100644 --- a/sdk/internal/internaltest/harness.go +++ b/sdk/internal/internaltest/harness.go @@ -263,7 +263,7 @@ func (h *Harness) TestTracer(subjectFactory func() trace.Tracer) { } func (h *Harness) testSpan(tracerFactory func() trace.Tracer) { - var methods = map[string]func(span trace.Span){ + methods := map[string]func(span trace.Span){ "#End": func(span trace.Span) { span.End() }, @@ -283,7 +283,7 @@ func (h *Harness) testSpan(tracerFactory func() trace.Tracer) { span.SetAttributes(attribute.String("key1", "value"), attribute.Int("key2", 123)) }, } - var mechanisms = map[string]func() trace.Span{ + mechanisms := map[string]func() trace.Span{ "Span created via Tracer#Start": func() trace.Span { tracer := tracerFactory() _, subject := tracer.Start(context.Background(), "test") diff --git a/sdk/internal/internaltest/text_map_carrier_test.go b/sdk/internal/internaltest/text_map_carrier_test.go index faf713cc2..086c8af26 100644 --- a/sdk/internal/internaltest/text_map_carrier_test.go +++ b/sdk/internal/internaltest/text_map_carrier_test.go @@ -22,9 +22,7 @@ import ( "testing" ) -var ( - key, value = "test", "true" -) +var key, value = "test", "true" func TestTextMapCarrierKeys(t *testing.T) { tmc := NewTextMapCarrier(map[string]string{key: value}) diff --git a/sdk/internal/matchers/expectation.go b/sdk/internal/matchers/expectation.go index 847643086..c48aff036 100644 --- a/sdk/internal/matchers/expectation.go +++ b/sdk/internal/matchers/expectation.go @@ -27,9 +27,7 @@ import ( "time" ) -var ( - stackTracePruneRE = regexp.MustCompile(`runtime\/debug|testing|internal\/matchers`) -) +var stackTracePruneRE = regexp.MustCompile(`runtime\/debug|testing|internal\/matchers`) type Expectation struct { t *testing.T diff --git a/sdk/metric/config_test.go b/sdk/metric/config_test.go index ae7159f2d..42bf16a6a 100644 --- a/sdk/metric/config_test.go +++ b/sdk/metric/config_test.go @@ -47,6 +47,7 @@ func (r *reader) RegisterProducer(p Producer) { r.externalProducers = append(r.e func (r *reader) temporality(kind InstrumentKind) metricdata.Temporality { return r.temporalityFunc(kind) } + func (r *reader) Collect(ctx context.Context, rm *metricdata.ResourceMetrics) error { return r.collectFunc(ctx, rm) } diff --git a/sdk/metric/instrument.go b/sdk/metric/instrument.go index f7224d4b5..bb52f6ec7 100644 --- a/sdk/metric/instrument.go +++ b/sdk/metric/instrument.go @@ -188,9 +188,11 @@ type int64Inst struct { embedded.Int64Histogram } -var _ metric.Int64Counter = (*int64Inst)(nil) -var _ metric.Int64UpDownCounter = (*int64Inst)(nil) -var _ metric.Int64Histogram = (*int64Inst)(nil) +var ( + _ metric.Int64Counter = (*int64Inst)(nil) + _ metric.Int64UpDownCounter = (*int64Inst)(nil) + _ metric.Int64Histogram = (*int64Inst)(nil) +) func (i *int64Inst) Add(ctx context.Context, val int64, opts ...metric.AddOption) { c := metric.NewAddConfig(opts) @@ -219,9 +221,11 @@ type float64Inst struct { embedded.Float64Histogram } -var _ metric.Float64Counter = (*float64Inst)(nil) -var _ metric.Float64UpDownCounter = (*float64Inst)(nil) -var _ metric.Float64Histogram = (*float64Inst)(nil) +var ( + _ metric.Float64Counter = (*float64Inst)(nil) + _ metric.Float64UpDownCounter = (*float64Inst)(nil) + _ metric.Float64Histogram = (*float64Inst)(nil) +) func (i *float64Inst) Add(ctx context.Context, val float64, opts ...metric.AddOption) { c := metric.NewAddConfig(opts) @@ -260,9 +264,11 @@ type float64Observable struct { embedded.Float64ObservableGauge } -var _ metric.Float64ObservableCounter = float64Observable{} -var _ metric.Float64ObservableUpDownCounter = float64Observable{} -var _ metric.Float64ObservableGauge = float64Observable{} +var ( + _ metric.Float64ObservableCounter = float64Observable{} + _ metric.Float64ObservableUpDownCounter = float64Observable{} + _ metric.Float64ObservableGauge = float64Observable{} +) func newFloat64Observable(m *meter, kind InstrumentKind, name, desc, u string, meas []aggregate.Measure[float64]) float64Observable { return float64Observable{ @@ -279,9 +285,11 @@ type int64Observable struct { embedded.Int64ObservableGauge } -var _ metric.Int64ObservableCounter = int64Observable{} -var _ metric.Int64ObservableUpDownCounter = int64Observable{} -var _ metric.Int64ObservableGauge = int64Observable{} +var ( + _ metric.Int64ObservableCounter = int64Observable{} + _ metric.Int64ObservableUpDownCounter = int64Observable{} + _ metric.Int64ObservableGauge = int64Observable{} +) func newInt64Observable(m *meter, kind InstrumentKind, name, desc, u string, meas []aggregate.Measure[int64]) int64Observable { return int64Observable{ diff --git a/sdk/metric/internal/aggregate/exponential_histogram.go b/sdk/metric/internal/aggregate/exponential_histogram.go index 368f0027e..98b7dc1e0 100644 --- a/sdk/metric/internal/aggregate/exponential_histogram.go +++ b/sdk/metric/internal/aggregate/exponential_histogram.go @@ -113,7 +113,7 @@ func (p *expoHistogramDataPoint[N]) record(v N) { otel.Handle(errors.New("exponential histogram scale underflow")) return } - //Downscale + // Downscale p.scale -= scaleDelta p.posBuckets.downscale(scaleDelta) p.negBuckets.downscale(scaleDelta) diff --git a/sdk/metric/manual_reader_test.go b/sdk/metric/manual_reader_test.go index 210a66c1b..a2a1476fa 100644 --- a/sdk/metric/manual_reader_test.go +++ b/sdk/metric/manual_reader_test.go @@ -40,8 +40,10 @@ func BenchmarkManualReader(b *testing.B) { b.Run("Collect", benchReaderCollectFunc(NewManualReader())) } -var deltaTemporalitySelector = func(InstrumentKind) metricdata.Temporality { return metricdata.DeltaTemporality } -var cumulativeTemporalitySelector = func(InstrumentKind) metricdata.Temporality { return metricdata.CumulativeTemporality } +var ( + deltaTemporalitySelector = func(InstrumentKind) metricdata.Temporality { return metricdata.DeltaTemporality } + cumulativeTemporalitySelector = func(InstrumentKind) metricdata.Temporality { return metricdata.CumulativeTemporality } +) func TestManualReaderTemporality(t *testing.T) { tests := []struct { diff --git a/sdk/metric/meter.go b/sdk/metric/meter.go index e5ec1ad46..0c17dfb20 100644 --- a/sdk/metric/meter.go +++ b/sdk/metric/meter.go @@ -26,11 +26,9 @@ import ( "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" ) -var ( - // ErrInstrumentName indicates the created instrument has an invalid name. - // Valid names must consist of 255 or fewer characters including alphanumeric, _, ., -, / and start with a letter. - ErrInstrumentName = errors.New("invalid instrument name") -) +// ErrInstrumentName indicates the created instrument has an invalid name. +// Valid names must consist of 255 or fewer characters including alphanumeric, _, ., -, / and start with a letter. +var ErrInstrumentName = errors.New("invalid instrument name") // meter handles the creation and coordination of all metric instruments. A // meter represents a single instrumentation scope; all metric telemetry @@ -268,9 +266,11 @@ func validateInstrumentName(name string) error { } return nil } + func isAlpha(c rune) bool { return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') } + func isAlphanumeric(c rune) bool { return isAlpha(c) || ('0' <= c && c <= '9') } diff --git a/sdk/metric/meter_test.go b/sdk/metric/meter_test.go index 34a95ab70..e2b2a5938 100644 --- a/sdk/metric/meter_test.go +++ b/sdk/metric/meter_test.go @@ -1826,12 +1826,15 @@ func BenchmarkInstrumentCreation(b *testing.B) { func testNilAggregationSelector(InstrumentKind) Aggregation { return nil } + func testDefaultAggregationSelector(InstrumentKind) Aggregation { return AggregationDefault{} } + func testUndefinedTemporalitySelector(InstrumentKind) metricdata.Temporality { return metricdata.Temporality(0) } + func testInvalidTemporalitySelector(InstrumentKind) metricdata.Temporality { return metricdata.Temporality(255) } diff --git a/sdk/metric/metricdata/metricdatatest/comparisons.go b/sdk/metric/metricdata/metricdatatest/comparisons.go index 5cdca6fe2..bb74c4a12 100644 --- a/sdk/metric/metricdata/metricdatatest/comparisons.go +++ b/sdk/metric/metricdata/metricdatatest/comparisons.go @@ -741,6 +741,7 @@ func hasAttributesScopeMetrics(sm metricdata.ScopeMetrics, attrs ...attribute.Ke } return reasons } + func hasAttributesResourceMetrics(rm metricdata.ResourceMetrics, attrs ...attribute.KeyValue) (reasons []string) { for n, sm := range rm.ScopeMetrics { reas := hasAttributesScopeMetrics(sm, attrs...) diff --git a/sdk/metric/periodic_reader.go b/sdk/metric/periodic_reader.go index 2a8545610..ff86999c7 100644 --- a/sdk/metric/periodic_reader.go +++ b/sdk/metric/periodic_reader.go @@ -127,7 +127,8 @@ func NewPeriodicReader(exporter Exporter, options ...PeriodicReaderOption) *Peri rmPool: sync.Pool{ New: func() interface{} { return &metricdata.ResourceMetrics{} - }}, + }, + }, } r.externalProducers.Store(conf.producers) diff --git a/sdk/metric/periodic_reader_test.go b/sdk/metric/periodic_reader_test.go index 2f055796d..81cbd1149 100644 --- a/sdk/metric/periodic_reader_test.go +++ b/sdk/metric/periodic_reader_test.go @@ -344,7 +344,8 @@ func TestPeriodicReaderFlushesPending(t *testing.T) { return ctx.Err() } return nil - }}) + }, + }) assert.ErrorIs(t, r.ForceFlush(context.Background()), context.DeadlineExceeded) assert.False(t, *called, "exporter Export method called when it should have failed before export") @@ -396,7 +397,8 @@ func TestPeriodicReaderFlushesPending(t *testing.T) { return ctx.Err() } return nil - }}) + }, + }) assert.ErrorIs(t, r.Shutdown(context.Background()), context.DeadlineExceeded) assert.False(t, *called, "exporter Export method called when it should have failed before export") }) diff --git a/sdk/metric/pipeline_registry_test.go b/sdk/metric/pipeline_registry_test.go index 89293e679..b0832a87f 100644 --- a/sdk/metric/pipeline_registry_test.go +++ b/sdk/metric/pipeline_registry_test.go @@ -39,6 +39,7 @@ type invalidAggregation struct{} func (invalidAggregation) copy() Aggregation { return invalidAggregation{} } + func (invalidAggregation) err() error { return nil } @@ -155,7 +156,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) { ) instruments := []Instrument{ - {Name: "foo", Kind: InstrumentKind(0)}, //Unknown kind + {Name: "foo", Kind: InstrumentKind(0)}, // Unknown kind {Name: "foo", Kind: InstrumentKindCounter}, {Name: "foo", Kind: InstrumentKindUpDownCounter}, {Name: "foo", Kind: InstrumentKindHistogram}, diff --git a/sdk/metric/reader_test.go b/sdk/metric/reader_test.go index a1e9e507b..48d36155e 100644 --- a/sdk/metric/reader_test.go +++ b/sdk/metric/reader_test.go @@ -138,7 +138,8 @@ func (ts *readerTestSuite) TestSDKFailureBlocksExternalProducer() { produceFunc: func(ctx context.Context, rm *metricdata.ResourceMetrics) error { *rm = metricdata.ResourceMetrics{} return assert.AnError - }}) + }, + }) m := metricdata.ResourceMetrics{} err := ts.Reader.Collect(context.Background(), &m) diff --git a/sdk/resource/auto.go b/sdk/resource/auto.go index 324dd4baf..4279013be 100644 --- a/sdk/resource/auto.go +++ b/sdk/resource/auto.go @@ -21,12 +21,10 @@ import ( "strings" ) -var ( - // ErrPartialResource is returned by a detector when complete source - // information for a Resource is unavailable or the source information - // contains invalid values that are omitted from the returned Resource. - ErrPartialResource = errors.New("partial resource") -) +// ErrPartialResource is returned by a detector when complete source +// information for a Resource is unavailable or the source information +// contains invalid values that are omitted from the returned Resource. +var ErrPartialResource = errors.New("partial resource") // Detector detects OpenTelemetry resource information. type Detector interface { diff --git a/sdk/resource/benchmark_test.go b/sdk/resource/benchmark_test.go index ea72c5a21..c43e7a6b8 100644 --- a/sdk/resource/benchmark_test.go +++ b/sdk/resource/benchmark_test.go @@ -63,21 +63,27 @@ func benchmarkMergeResource(b *testing.B, size int) { func BenchmarkMergeResource_1(b *testing.B) { benchmarkMergeResource(b, 1) } + func BenchmarkMergeResource_2(b *testing.B) { benchmarkMergeResource(b, 2) } + func BenchmarkMergeResource_3(b *testing.B) { benchmarkMergeResource(b, 3) } + func BenchmarkMergeResource_4(b *testing.B) { benchmarkMergeResource(b, 4) } + func BenchmarkMergeResource_6(b *testing.B) { benchmarkMergeResource(b, 6) } + func BenchmarkMergeResource_8(b *testing.B) { benchmarkMergeResource(b, 8) } + func BenchmarkMergeResource_16(b *testing.B) { benchmarkMergeResource(b, 16) } diff --git a/sdk/resource/env.go b/sdk/resource/env.go index a847c5062..606d5500f 100644 --- a/sdk/resource/env.go +++ b/sdk/resource/env.go @@ -34,10 +34,8 @@ const ( svcNameKey = "OTEL_SERVICE_NAME" ) -var ( - // errMissingValue is returned when a resource value is missing. - errMissingValue = fmt.Errorf("%w: missing value", ErrPartialResource) -) +// errMissingValue is returned when a resource value is missing. +var errMissingValue = fmt.Errorf("%w: missing value", ErrPartialResource) // fromEnv is a Detector that implements the Detector and collects // resources from environment. This Detector is included as a diff --git a/sdk/resource/export_test.go b/sdk/resource/export_test.go index 6c767e595..8003e3ec9 100644 --- a/sdk/resource/export_test.go +++ b/sdk/resource/export_test.go @@ -34,6 +34,4 @@ var ( RuntimeArch = runtimeArch ) -var ( - MapRuntimeOSToSemconvOSType = mapRuntimeOSToSemconvOSType -) +var MapRuntimeOSToSemconvOSType = mapRuntimeOSToSemconvOSType diff --git a/sdk/resource/os.go b/sdk/resource/os.go index 84e1c5856..0cbd55973 100644 --- a/sdk/resource/os.go +++ b/sdk/resource/os.go @@ -36,8 +36,10 @@ func setOSDescriptionProvider(osDescriptionProvider osDescriptionProvider) { osDescription = osDescriptionProvider } -type osTypeDetector struct{} -type osDescriptionDetector struct{} +type ( + osTypeDetector struct{} + osDescriptionDetector struct{} +) // Detect returns a *Resource that describes the operating system type the // service is running on. @@ -56,7 +58,6 @@ func (osTypeDetector) Detect(ctx context.Context) (*Resource, error) { // service is running on. func (osDescriptionDetector) Detect(ctx context.Context) (*Resource, error) { description, err := osDescription() - if err != nil { return nil, err } diff --git a/sdk/resource/process.go b/sdk/resource/process.go index e67ff29e2..ecdd11dd7 100644 --- a/sdk/resource/process.go +++ b/sdk/resource/process.go @@ -25,14 +25,16 @@ import ( semconv "go.opentelemetry.io/otel/semconv/v1.21.0" ) -type pidProvider func() int -type executablePathProvider func() (string, error) -type commandArgsProvider func() []string -type ownerProvider func() (*user.User, error) -type runtimeNameProvider func() string -type runtimeVersionProvider func() string -type runtimeOSProvider func() string -type runtimeArchProvider func() string +type ( + pidProvider func() int + executablePathProvider func() (string, error) + commandArgsProvider func() []string + ownerProvider func() (*user.User, error) + runtimeNameProvider func() string + runtimeVersionProvider func() string + runtimeOSProvider func() string + runtimeArchProvider func() string +) var ( defaultPidProvider pidProvider = os.Getpid @@ -108,14 +110,16 @@ func setUserProviders(ownerProvider ownerProvider) { owner = ownerProvider } -type processPIDDetector struct{} -type processExecutableNameDetector struct{} -type processExecutablePathDetector struct{} -type processCommandArgsDetector struct{} -type processOwnerDetector struct{} -type processRuntimeNameDetector struct{} -type processRuntimeVersionDetector struct{} -type processRuntimeDescriptionDetector struct{} +type ( + processPIDDetector struct{} + processExecutableNameDetector struct{} + processExecutablePathDetector struct{} + processCommandArgsDetector struct{} + processOwnerDetector struct{} + processRuntimeNameDetector struct{} + processRuntimeVersionDetector struct{} + processRuntimeDescriptionDetector struct{} +) // Detect returns a *Resource that describes the process identifier (PID) of the // executing process. diff --git a/sdk/trace/benchmark_test.go b/sdk/trace/benchmark_test.go index b7dde8d96..e0172fd1d 100644 --- a/sdk/trace/benchmark_test.go +++ b/sdk/trace/benchmark_test.go @@ -285,6 +285,7 @@ func BenchmarkSpanWithEvents_WithStackTrace(b *testing.B) { } }) } + func BenchmarkSpanWithEvents_WithTimestamp(b *testing.B) { traceBenchmark(b, "Benchmark Start With 4 Attributes", func(b *testing.B, t trace.Tracer) { ctx := context.Background() diff --git a/sdk/trace/span.go b/sdk/trace/span.go index 37cdd4a69..68ac1b016 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -158,8 +158,10 @@ type recordingSpan struct { tracer *tracer } -var _ ReadWriteSpan = (*recordingSpan)(nil) -var _ runtimeTracer = (*recordingSpan)(nil) +var ( + _ ReadWriteSpan = (*recordingSpan)(nil) + _ runtimeTracer = (*recordingSpan)(nil) +) // SpanContext returns the SpanContext of this span. func (s *recordingSpan) SpanContext() trace.SpanContext { diff --git a/sdk/trace/span_processor_filter_example_test.go b/sdk/trace/span_processor_filter_example_test.go index f5dd84e47..e0ce9e0d8 100644 --- a/sdk/trace/span_processor_filter_example_test.go +++ b/sdk/trace/span_processor_filter_example_test.go @@ -66,6 +66,7 @@ func (f InstrumentationBlacklist) Shutdown(ctx context.Context) error { return f func (f InstrumentationBlacklist) ForceFlush(ctx context.Context) error { return f.Next.ForceFlush(ctx) } + func (f InstrumentationBlacklist) OnEnd(s ReadOnlySpan) { if f.Blacklist != nil && f.Blacklist[s.InstrumentationScope().Name] { // Drop spans from this instrumentation diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 56f53d4d2..5ad353141 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -1407,7 +1407,8 @@ func TestWithResource(t *testing.T) { name: "last resource wins", options: []TracerProviderOption{ WithResource(resource.NewSchemaless(attribute.String("rk1", "vk1"), attribute.Int64("rk2", 5))), - WithResource(resource.NewSchemaless(attribute.String("rk3", "rv3"), attribute.Int64("rk4", 10)))}, + WithResource(resource.NewSchemaless(attribute.String("rk3", "rv3"), attribute.Int64("rk4", 10))), + }, want: mergeResource(t, resource.Environment(), resource.NewSchemaless(attribute.String("rk3", "rv3"), attribute.Int64("rk4", 10))), }, { diff --git a/sdk/trace/tracetest/span.go b/sdk/trace/tracetest/span.go index bfe73de9c..ae8eae8e8 100644 --- a/sdk/trace/tracetest/span.go +++ b/sdk/trace/tracetest/span.go @@ -162,6 +162,7 @@ func (s spanSnapshot) Resource() *resource.Resource { return s.resource } func (s spanSnapshot) InstrumentationScope() instrumentation.Scope { return s.instrumentationScope } + func (s spanSnapshot) InstrumentationLibrary() instrumentation.Library { return s.instrumentationScope } diff --git a/trace/config.go b/trace/config.go index cb3efbb9a..3aadc66cf 100644 --- a/trace/config.go +++ b/trace/config.go @@ -268,6 +268,7 @@ func (o stackTraceOption) applyEvent(c EventConfig) EventConfig { c.stackTrace = bool(o) return c } + func (o stackTraceOption) applySpan(c SpanConfig) SpanConfig { c.stackTrace = bool(o) return c diff --git a/trace/trace.go b/trace/trace.go index 4aa94f79f..d31955587 100644 --- a/trace/trace.go +++ b/trace/trace.go @@ -48,8 +48,10 @@ func (e errorConst) Error() string { // nolint:revive // revive complains about stutter of `trace.TraceID`. type TraceID [16]byte -var nilTraceID TraceID -var _ json.Marshaler = nilTraceID +var ( + nilTraceID TraceID + _ json.Marshaler = nilTraceID +) // IsValid checks whether the trace TraceID is valid. A valid trace ID does // not consist of zeros only. @@ -71,8 +73,10 @@ func (t TraceID) String() string { // SpanID is a unique identity of a span in a trace. type SpanID [8]byte -var nilSpanID SpanID -var _ json.Marshaler = nilSpanID +var ( + nilSpanID SpanID + _ json.Marshaler = nilSpanID +) // IsValid checks whether the SpanID is valid. A valid SpanID does not consist // of zeros only. diff --git a/trace/trace_test.go b/trace/trace_test.go index 420038220..9bde9d8c7 100644 --- a/trace/trace_test.go +++ b/trace/trace_test.go @@ -309,7 +309,7 @@ func TestSpanContextHasTraceID(t *testing.T) { }, } { t.Run(testcase.name, func(t *testing.T) { - //proto: func (sc SpanContext) HasTraceID() bool{} + // proto: func (sc SpanContext) HasTraceID() bool{} sc := SpanContext{traceID: testcase.tid} have := sc.HasTraceID() if have != testcase.want { @@ -336,7 +336,7 @@ func TestSpanContextHasSpanID(t *testing.T) { }, } { t.Run(testcase.name, func(t *testing.T) { - //proto: func (sc SpanContext) HasSpanID() bool {} + // proto: func (sc SpanContext) HasSpanID() bool {} have := testcase.sc.HasSpanID() if have != testcase.want { t.Errorf("Want: %v, but have: %v", testcase.want, have) @@ -435,7 +435,7 @@ func TestStringTraceID(t *testing.T) { }, } { t.Run(testcase.name, func(t *testing.T) { - //proto: func (t TraceID) String() string {} + // proto: func (t TraceID) String() string {} have := testcase.tid.String() if have != testcase.want { t.Errorf("Want: %s, but have: %s", testcase.want, have) @@ -462,7 +462,7 @@ func TestStringSpanID(t *testing.T) { }, } { t.Run(testcase.name, func(t *testing.T) { - //proto: func (t TraceID) String() string {} + // proto: func (t TraceID) String() string {} have := testcase.sid.String() if have != testcase.want { t.Errorf("Want: %s, but have: %s", testcase.want, have) @@ -481,17 +481,14 @@ func TestValidateSpanKind(t *testing.T) { SpanKindInternal, }, { - SpanKindInternal, SpanKindInternal, }, { - SpanKindServer, SpanKindServer, }, { - SpanKindClient, SpanKindClient, }, @@ -521,17 +518,14 @@ func TestSpanKindString(t *testing.T) { "unspecified", }, { - SpanKindInternal, "internal", }, { - SpanKindServer, "server", }, { - SpanKindClient, "client", }, diff --git a/trace/tracestate_test.go b/trace/tracestate_test.go index 784c15892..cd6536e6a 100644 --- a/trace/tracestate_test.go +++ b/trace/tracestate_test.go @@ -495,7 +495,8 @@ func TestTraceStateInsert(t *testing.T) { ), } }(), - }} + }, + } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) {