diff --git a/client/doc_test.go b/client/doc_test.go index 6b01ac8777c..96de7bc85ab 100644 --- a/client/doc_test.go +++ b/client/doc_test.go @@ -15,7 +15,12 @@ import ( func Example_receiver() { // Your receiver get a next consumer when it's constructed - var next consumer.Traces + next, err := consumer.NewTraces(func(ctx context.Context, td ptrace.Traces) error { + return nil + }) + if err != nil { + panic(err) + } // You'll convert the incoming data into pipeline data td := ptrace.NewTraces() @@ -30,13 +35,16 @@ func Example_receiver() { // Extract the client information based on your original context and set it // to Addr - cl.Addr = &net.IPAddr{ // nolint + // nolint + cl.Addr = &net.IPAddr{ IP: net.IPv4(1, 2, 3, 4), } // When you are done, propagate the context down the pipeline to the next - // consumer - next.ConsumeTraces(ctx, td) // nolint + // consumer and handle error. + if err = next.ConsumeTraces(ctx, td); err != nil { + panic(err) + } } func Example_processor() { diff --git a/exporter/exporterhelper/logs_test.go b/exporter/exporterhelper/logs_test.go index db527e1be80..71a9035393f 100644 --- a/exporter/exporterhelper/logs_test.go +++ b/exporter/exporterhelper/logs_test.go @@ -284,7 +284,7 @@ func TestLogs_WithSpan(t *testing.T) { le, err := NewLogs(context.Background(), set, &fakeLogsConfig, newPushLogsData(nil)) require.NoError(t, err) require.NotNil(t, le) - checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, nil, 1) + checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, nil) } func TestLogsRequest_WithSpan(t *testing.T) { @@ -297,7 +297,7 @@ func TestLogsRequest_WithSpan(t *testing.T) { le, err := NewLogsRequest(context.Background(), set, internal.RequestFromLogsFunc(nil)) require.NoError(t, err) require.NotNil(t, le) - checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, nil, 1) + checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, nil) } func TestLogs_WithSpan_ReturnError(t *testing.T) { @@ -311,7 +311,7 @@ func TestLogs_WithSpan_ReturnError(t *testing.T) { le, err := NewLogs(context.Background(), set, &fakeLogsConfig, newPushLogsData(want)) require.NoError(t, err) require.NotNil(t, le) - checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, want, 1) + checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, want) } func TestLogsRequest_WithSpan_ReturnError(t *testing.T) { @@ -325,7 +325,7 @@ func TestLogsRequest_WithSpan_ReturnError(t *testing.T) { le, err := NewLogsRequest(context.Background(), set, internal.RequestFromLogsFunc(want)) require.NoError(t, err) require.NotNil(t, le) - checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, want, 1) + checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, want) } func TestLogs_WithShutdown(t *testing.T) { @@ -413,10 +413,7 @@ func generateLogsTraffic(t *testing.T, tracer trace.Tracer, le exporter.Logs, nu } } -// nolint: unparam -func checkWrapSpanForLogs(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le exporter.Logs, - wantError error, numLogRecords int64, -) { +func checkWrapSpanForLogs(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le exporter.Logs, wantError error) { const numRequests = 5 generateLogsTraffic(t, tracer, le, numRequests, wantError) @@ -430,11 +427,11 @@ func checkWrapSpanForLogs(t *testing.T, sr *tracetest.SpanRecorder, tracer trace require.Equalf(t, parentSpan.SpanContext(), sd.Parent(), "Exporter span not a child\nSpanData %v", sd) internal.CheckStatus(t, sd, wantError) - sentLogRecords := numLogRecords - var failedToSendLogRecords int64 + sentLogRecords := int64(1) + failedToSendLogRecords := int64(0) if wantError != nil { sentLogRecords = 0 - failedToSendLogRecords = numLogRecords + failedToSendLogRecords = 1 } require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.SentLogRecordsKey, Value: attribute.Int64Value(sentLogRecords)}, "SpanData %v", sd) require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.FailedToSendLogRecordsKey, Value: attribute.Int64Value(failedToSendLogRecords)}, "SpanData %v", sd) diff --git a/exporter/exporterhelper/metrics_test.go b/exporter/exporterhelper/metrics_test.go index d6d38e9a3b8..34c108e4dd4 100644 --- a/exporter/exporterhelper/metrics_test.go +++ b/exporter/exporterhelper/metrics_test.go @@ -286,7 +286,7 @@ func TestMetrics_WithSpan(t *testing.T) { me, err := NewMetrics(context.Background(), set, &fakeMetricsConfig, newPushMetricsData(nil)) require.NoError(t, err) require.NotNil(t, me) - checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, nil, 2) + checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, nil) } func TestMetricsRequest_WithSpan(t *testing.T) { @@ -299,7 +299,7 @@ func TestMetricsRequest_WithSpan(t *testing.T) { me, err := NewMetricsRequest(context.Background(), set, internal.RequestFromMetricsFunc(nil)) require.NoError(t, err) require.NotNil(t, me) - checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, nil, 2) + checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, nil) } func TestMetrics_WithSpan_ReturnError(t *testing.T) { @@ -313,7 +313,7 @@ func TestMetrics_WithSpan_ReturnError(t *testing.T) { me, err := NewMetrics(context.Background(), set, &fakeMetricsConfig, newPushMetricsData(want)) require.NoError(t, err) require.NotNil(t, me) - checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, want, 2) + checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, want) } func TestMetricsRequest_WithSpan_ExportError(t *testing.T) { @@ -327,7 +327,7 @@ func TestMetricsRequest_WithSpan_ExportError(t *testing.T) { me, err := NewMetricsRequest(context.Background(), set, internal.RequestFromMetricsFunc(want)) require.NoError(t, err) require.NotNil(t, me) - checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, want, 2) + checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, want) } func TestMetrics_WithShutdown(t *testing.T) { @@ -420,10 +420,7 @@ func generateMetricsTraffic(t *testing.T, tracer trace.Tracer, me exporter.Metri } } -// nolint: unparam -func checkWrapSpanForMetrics(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, - me exporter.Metrics, wantError error, numMetricPoints int64, -) { +func checkWrapSpanForMetrics(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, me exporter.Metrics, wantError error) { const numRequests = 5 generateMetricsTraffic(t, tracer, me, numRequests, wantError) @@ -437,11 +434,11 @@ func checkWrapSpanForMetrics(t *testing.T, sr *tracetest.SpanRecorder, tracer tr require.Equalf(t, parentSpan.SpanContext(), sd.Parent(), "Exporter span not a child\nSpanData %v", sd) internal.CheckStatus(t, sd, wantError) - sentMetricPoints := numMetricPoints - var failedToSendMetricPoints int64 + sentMetricPoints := int64(2) + failedToSendMetricPoints := int64(0) if wantError != nil { sentMetricPoints = 0 - failedToSendMetricPoints = numMetricPoints + failedToSendMetricPoints = 2 } require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.SentMetricPointsKey, Value: attribute.Int64Value(sentMetricPoints)}, "SpanData %v", sd) require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.FailedToSendMetricPointsKey, Value: attribute.Int64Value(failedToSendMetricPoints)}, "SpanData %v", sd) diff --git a/exporter/exporterhelper/traces_test.go b/exporter/exporterhelper/traces_test.go index fe1d1390e60..563b49db5a9 100644 --- a/exporter/exporterhelper/traces_test.go +++ b/exporter/exporterhelper/traces_test.go @@ -284,7 +284,7 @@ func TestTraces_WithSpan(t *testing.T) { require.NoError(t, err) require.NotNil(t, te) - checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, nil, 1) + checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, nil) } func TestTracesRequest_WithSpan(t *testing.T) { @@ -298,7 +298,7 @@ func TestTracesRequest_WithSpan(t *testing.T) { require.NoError(t, err) require.NotNil(t, te) - checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, nil, 1) + checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, nil) } func TestTraces_WithSpan_ReturnError(t *testing.T) { @@ -313,7 +313,7 @@ func TestTraces_WithSpan_ReturnError(t *testing.T) { require.NoError(t, err) require.NotNil(t, te) - checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, want, 1) + checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, want) } func TestTracesRequest_WithSpan_ExportError(t *testing.T) { @@ -328,7 +328,7 @@ func TestTracesRequest_WithSpan_ExportError(t *testing.T) { require.NoError(t, err) require.NotNil(t, te) - checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, want, 1) + checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, want) } func TestTraces_WithShutdown(t *testing.T) { @@ -421,10 +421,7 @@ func generateTraceTraffic(t *testing.T, tracer trace.Tracer, te exporter.Traces, } } -// nolint: unparam -func checkWrapSpanForTraces(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, - te exporter.Traces, wantError error, numSpans int64, -) { +func checkWrapSpanForTraces(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, te exporter.Traces, wantError error) { const numRequests = 5 generateTraceTraffic(t, tracer, te, numRequests, wantError) @@ -439,11 +436,11 @@ func checkWrapSpanForTraces(t *testing.T, sr *tracetest.SpanRecorder, tracer tra require.Equalf(t, parentSpan.SpanContext(), sd.Parent(), "Exporter span not a child\nSpanData %v", sd) internal.CheckStatus(t, sd, wantError) - sentSpans := numSpans - var failedToSendSpans int64 + sentSpans := int64(1) + failedToSendSpans := int64(0) if wantError != nil { sentSpans = 0 - failedToSendSpans = numSpans + failedToSendSpans = 1 } require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.SentSpansKey, Value: attribute.Int64Value(sentSpans)}, "SpanData %v", sd) require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.FailedToSendSpansKey, Value: attribute.Int64Value(failedToSendSpans)}, "SpanData %v", sd) diff --git a/exporter/exporterhelper/xexporterhelper/profiles_test.go b/exporter/exporterhelper/xexporterhelper/profiles_test.go index 43ce7d84d13..ee02744165d 100644 --- a/exporter/exporterhelper/xexporterhelper/profiles_test.go +++ b/exporter/exporterhelper/xexporterhelper/profiles_test.go @@ -192,7 +192,7 @@ func TestProfilesExporter_WithSpan(t *testing.T) { le, err := NewProfilesExporter(context.Background(), set, &fakeProfilesExporterConfig, newPushProfilesData(nil)) require.NoError(t, err) require.NotNil(t, le) - checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, nil, 1) + checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, nil) } func TestProfilesRequestExporter_WithSpan(t *testing.T) { @@ -205,7 +205,7 @@ func TestProfilesRequestExporter_WithSpan(t *testing.T) { le, err := NewProfilesRequestExporter(context.Background(), set, internal.RequestFromProfilesFunc(nil)) require.NoError(t, err) require.NotNil(t, le) - checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, nil, 1) + checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, nil) } func TestProfilesExporter_WithSpan_ReturnError(t *testing.T) { @@ -219,7 +219,7 @@ func TestProfilesExporter_WithSpan_ReturnError(t *testing.T) { le, err := NewProfilesExporter(context.Background(), set, &fakeProfilesExporterConfig, newPushProfilesData(want)) require.NoError(t, err) require.NotNil(t, le) - checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, want, 1) + checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, want) } func TestProfilesRequestExporter_WithSpan_ReturnError(t *testing.T) { @@ -233,7 +233,7 @@ func TestProfilesRequestExporter_WithSpan_ReturnError(t *testing.T) { le, err := NewProfilesRequestExporter(context.Background(), set, internal.RequestFromProfilesFunc(want)) require.NoError(t, err) require.NotNil(t, le) - checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, want, 1) + checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, want) } func TestProfilesExporter_WithShutdown(t *testing.T) { @@ -299,10 +299,7 @@ func generateProfilesTraffic(t *testing.T, tracer trace.Tracer, le xexporter.Pro } } -// nolint: unparam -func checkWrapSpanForProfilesExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le xexporter.Profiles, - wantError error, numSampleRecords int64, -) { +func checkWrapSpanForProfilesExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le xexporter.Profiles, wantError error) { const numRequests = 5 generateProfilesTraffic(t, tracer, le, numRequests, wantError) @@ -316,11 +313,11 @@ func checkWrapSpanForProfilesExporter(t *testing.T, sr *tracetest.SpanRecorder, require.Equalf(t, parentSpan.SpanContext(), sd.Parent(), "Exporter span not a child\nSpanData %v", sd) internal.CheckStatus(t, sd, wantError) - sentSampleRecords := numSampleRecords - var failedToSendSampleRecords int64 + sentSampleRecords := int64(1) + failedToSendSampleRecords := int64(0) if wantError != nil { sentSampleRecords = 0 - failedToSendSampleRecords = numSampleRecords + failedToSendSampleRecords = 1 } require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.SentSamplesKey, Value: attribute.Int64Value(sentSampleRecords)}, "SpanData %v", sd) require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.FailedToSendSamplesKey, Value: attribute.Int64Value(failedToSendSampleRecords)}, "SpanData %v", sd) diff --git a/exporter/otlphttpexporter/otlp.go b/exporter/otlphttpexporter/otlp.go index 0decd18315a..5f8ef580ebe 100644 --- a/exporter/otlphttpexporter/otlp.go +++ b/exporter/otlphttpexporter/otlp.go @@ -198,7 +198,7 @@ func (e *baseExporter) export(ctx context.Context, url string, request []byte, p defer func() { // Discard any remaining response body when we are done reading. - io.CopyN(io.Discard, resp.Body, maxHTTPResponseReadBytes) // nolint:errcheck + _, _ = io.CopyN(io.Discard, resp.Body, maxHTTPResponseReadBytes) resp.Body.Close() }() diff --git a/otelcol/collector.go b/otelcol/collector.go index 13ac5986ee5..dac8c860ec3 100644 --- a/otelcol/collector.go +++ b/otelcol/collector.go @@ -148,7 +148,7 @@ func (col *Collector) Shutdown() { state := col.GetState() if state == StateRunning || state == StateStarting { defer func() { - recover() // nolint:errcheck + _ = recover() }() close(col.shutdownChan) } diff --git a/pdata/pmetric/fuzz_test.go b/pdata/pmetric/fuzz_test.go index f6e5f3a043b..8b27db4c496 100644 --- a/pdata/pmetric/fuzz_test.go +++ b/pdata/pmetric/fuzz_test.go @@ -10,7 +10,6 @@ import ( func FuzzUnmarshalMetrics(f *testing.F) { f.Fuzz(func(_ *testing.T, data []byte) { u := &JSONUnmarshaler{} - //nolint: errcheck _, _ = u.UnmarshalMetrics(data) }) } diff --git a/pdata/pmetric/pmetricotlp/fuzz_test.go b/pdata/pmetric/pmetricotlp/fuzz_test.go index 137b98b61b2..1e5e9381dc8 100644 --- a/pdata/pmetric/pmetricotlp/fuzz_test.go +++ b/pdata/pmetric/pmetricotlp/fuzz_test.go @@ -10,31 +10,27 @@ import ( func FuzzRequestUnmarshalJSON(f *testing.F) { f.Fuzz(func(_ *testing.T, data []byte) { er := NewExportRequest() - //nolint: errcheck - er.UnmarshalJSON(data) + _ = er.UnmarshalJSON(data) }) } func FuzzResponseUnmarshalJSON(f *testing.F) { f.Fuzz(func(_ *testing.T, data []byte) { er := NewExportResponse() - //nolint: errcheck - er.UnmarshalJSON(data) + _ = er.UnmarshalJSON(data) }) } func FuzzRequestUnmarshalProto(f *testing.F) { f.Fuzz(func(_ *testing.T, data []byte) { er := NewExportRequest() - //nolint: errcheck - er.UnmarshalProto(data) + _ = er.UnmarshalJSON(data) }) } func FuzzResponseUnmarshalProto(f *testing.F) { f.Fuzz(func(_ *testing.T, data []byte) { er := NewExportResponse() - //nolint: errcheck - er.UnmarshalProto(data) + _ = er.UnmarshalJSON(data) }) } diff --git a/receiver/otlpreceiver/otlp_test.go b/receiver/otlpreceiver/otlp_test.go index 237ccc854d8..a928895a1b6 100644 --- a/receiver/otlpreceiver/otlp_test.go +++ b/receiver/otlpreceiver/otlp_test.go @@ -674,8 +674,7 @@ func TestOTLPReceiverHTTPTracesIngestTest(t *testing.T) { errStatus := &spb.Status{} require.NoError(t, proto.Unmarshal(respBytes, errStatus)) assert.Equal(t, ingestionState.expectedStatusCode, resp.StatusCode) - // nolint:gosec - assert.Equal(t, ingestionState.expectedCode, codes.Code(errStatus.Code)) + assert.EqualValues(t, ingestionState.expectedCode, errStatus.Code) } } diff --git a/service/internal/graph/host.go b/service/internal/graph/host.go index fd81f7dcca8..3aaef5e055f 100644 --- a/service/internal/graph/host.go +++ b/service/internal/graph/host.go @@ -21,8 +21,6 @@ import ( ) // TODO: remove as part of https://github.com/open-telemetry/opentelemetry-collector/issues/7370 for service 1.0 -// -// nolint type getExporters interface { GetExporters() map[pipeline.Signal]map[component.ID]component.Component }