From 0a1eab703eb02cc3ac2144f6dcbbb84c8cbe7ac1 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 26 Mar 2025 10:56:45 -0700 Subject: [PATCH] Add the golines formatter to golangci-lint --- .golangci.yml | 1 + cli/main.go | 7 +- examples/httpPlusdb/main.go | 10 +- examples/kafka-go/consumer/main.go | 9 +- instrumentation.go | 5 +- instrumentation_test.go | 31 ++- .../bpf/database/sql/probe_test.go | 12 +- .../segmentio/kafka-go/consumer/probe.go | 49 +++- .../segmentio/kafka-go/consumer/probe_test.go | 9 +- .../segmentio/kafka-go/producer/probe.go | 33 ++- .../otel/traceglobal/probe.go | 38 ++- .../otel/traceglobal/probe_test.go | 10 +- .../google.golang.org/grpc/client/probe.go | 60 ++++- .../google.golang.org/grpc/server/probe.go | 94 +++++-- .../bpf/net/http/client/probe.go | 9 +- .../bpf/net/http/server/probe.go | 4 +- .../bpf/net/http/server/probe_test.go | 40 ++- internal/pkg/instrumentation/manager.go | 31 ++- internal/pkg/instrumentation/manager_test.go | 5 +- internal/pkg/instrumentation/probe/probe.go | 18 +- .../probe/sampling/sampling.go | 6 +- .../instrumentation/probe/sampling/utils.go | 4 +- internal/pkg/instrumentation/utils/ebpf.go | 5 +- .../utils/kernel_linux_test.go | 12 +- .../pkg/process/binary/funcs_nonstripped.go | 17 +- internal/pkg/process/ptrace_linux.go | 20 +- internal/pkg/structfield/structfield_test.go | 4 +- internal/test/e2e/databasesql/main.go | 10 +- internal/test/e2e/nethttp_custom/main.go | 5 +- internal/tools/inspect/builder.go | 7 +- internal/tools/inspect/cmd/offsetgen/main.go | 231 +++++++++++++++--- provider.go | 5 +- .../telemetry/test/conversion_test.go | 4 +- sdk/limit_test.go | 7 +- sdk/span.go | 4 +- sdk/span_test.go | 40 ++- sdk/tracer.go | 12 +- 37 files changed, 731 insertions(+), 137 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c45fc1c421..c12839b260 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -257,6 +257,7 @@ formatters: enable: - gofumpt - goimports + - golines settings: goimports: local-prefixes: diff --git a/cli/main.go b/cli/main.go index c3475a0a54..cd6cb8ef07 100644 --- a/cli/main.go +++ b/cli/main.go @@ -99,7 +99,12 @@ func main() { var targetPID int var targetExe string - flag.BoolVar(&globalImpl, "global-impl", false, "Record telemetry from the OpenTelemetry default global implementation") + flag.BoolVar( + &globalImpl, + "global-impl", + false, + "Record telemetry from the OpenTelemetry default global implementation", + ) flag.StringVar(&logLevel, "log-level", "", `Logging level ("debug", "info", "warn", "error")`) flag.IntVar(&targetPID, "target-pid", -1, `PID of target process`) flag.StringVar(&targetExe, "target-exe", "", `Executable path run by the target process`) diff --git a/examples/httpPlusdb/main.go b/examples/httpPlusdb/main.go index 60ed328a63..3487a12b5a 100644 --- a/examples/httpPlusdb/main.go +++ b/examples/httpPlusdb/main.go @@ -98,7 +98,15 @@ func (s *Server) queryDb(w http.ResponseWriter, req *http.Request) { if err != nil { panic(err) } - fmt.Fprintf(w, "ID: %d, firstName: %s, lastName: %s, email: %s, phone: %s\n", id, firstName, lastName, email, phone) + fmt.Fprintf( + w, + "ID: %d, firstName: %s, lastName: %s, email: %s, phone: %s\n", + id, + firstName, + lastName, + email, + phone, + ) } } diff --git a/examples/kafka-go/consumer/main.go b/examples/kafka-go/consumer/main.go index 7e651c9325..b0d64085e1 100644 --- a/examples/kafka-go/consumer/main.go +++ b/examples/kafka-go/consumer/main.go @@ -52,7 +52,14 @@ func reader(ctx context.Context) { attribute.Int64("partition", int64(m.Partition)), attribute.Int64("offset", m.Offset), ) - fmt.Printf("consumed message at topic:%v partition:%v offset:%v %s = %s\n", m.Topic, m.Partition, m.Offset, string(m.Key), string(m.Value)) + fmt.Printf( + "consumed message at topic:%v partition:%v offset:%v %s = %s\n", + m.Topic, + m.Partition, + m.Offset, + string(m.Key), + string(m.Value), + ) span.End() } } diff --git a/instrumentation.go b/instrumentation.go index bdd7854fb4..5b5423c6b1 100644 --- a/instrumentation.go +++ b/instrumentation.go @@ -66,7 +66,10 @@ type Instrumentation struct { // // If conflicting or duplicate options are provided, the last one will have // precedence and be used. -func NewInstrumentation(ctx context.Context, opts ...InstrumentationOption) (*Instrumentation, error) { +func NewInstrumentation( + ctx context.Context, + opts ...InstrumentationOption, +) (*Instrumentation, error) { c, err := newInstConfig(ctx, opts) if err != nil { return nil, err diff --git a/instrumentation_test.go b/instrumentation_test.go index c2ae2bf747..d6f434216e 100644 --- a/instrumentation_test.go +++ b/instrumentation_test.go @@ -148,7 +148,13 @@ func TestWithResourceAttributes(t *testing.T) { attr2 := semconv.K8SPodName("test_pod_name") attr3 := semconv.K8SNamespaceName("test_namespace_name") - c, err := newInstConfig(context.Background(), []InstrumentationOption{WithResourceAttributes(attr1, attr2), WithResourceAttributes(attr3)}) + c, err := newInstConfig( + context.Background(), + []InstrumentationOption{ + WithResourceAttributes(attr1, attr2), + WithResourceAttributes(attr3), + }, + ) require.NoError(t, err) assert.Equal(t, []attribute.KeyValue{attr1, attr2, attr3}, c.additionalResAttrs) }) @@ -159,7 +165,15 @@ func TestWithResourceAttributes(t *testing.T) { attr3 := semconv.K8SNamespaceName("test_namespace_name") mockEnv(t, map[string]string{ - "OTEL_RESOURCE_ATTRIBUTES": fmt.Sprintf("%s=%s,%s=%s,%s=%s", nameAttr.Key, nameAttr.Value.AsString(), attr2.Key, attr2.Value.AsString(), attr3.Key, attr3.Value.AsString()), + "OTEL_RESOURCE_ATTRIBUTES": fmt.Sprintf( + "%s=%s,%s=%s,%s=%s", + nameAttr.Key, + nameAttr.Value.AsString(), + attr2.Key, + attr2.Value.AsString(), + attr3.Key, + attr3.Value.AsString(), + ), }) c, err := newInstConfig(context.Background(), []InstrumentationOption{WithEnv()}) @@ -174,11 +188,20 @@ func TestWithResourceAttributes(t *testing.T) { attr3 := semconv.K8SNamespaceName("test_namespace_name") mockEnv(t, map[string]string{ - "OTEL_RESOURCE_ATTRIBUTES": fmt.Sprintf("%s=%s,%s=%s", nameAttr.Key, nameAttr.Value.AsString(), attr2.Key, attr2.Value.AsString()), + "OTEL_RESOURCE_ATTRIBUTES": fmt.Sprintf( + "%s=%s,%s=%s", + nameAttr.Key, + nameAttr.Value.AsString(), + attr2.Key, + attr2.Value.AsString(), + ), }) // Use WithResourceAttributes to config the additional resource attributes - c, err := newInstConfig(context.Background(), []InstrumentationOption{WithEnv(), WithResourceAttributes(attr3)}) + c, err := newInstConfig( + context.Background(), + []InstrumentationOption{WithEnv(), WithResourceAttributes(attr3)}, + ) require.NoError(t, err) assert.Equal(t, nameAttr.Value.AsString(), c.serviceName) assert.Equal(t, []attribute.KeyValue{attr2, attr3}, c.additionalResAttrs) diff --git a/internal/pkg/instrumentation/bpf/database/sql/probe_test.go b/internal/pkg/instrumentation/bpf/database/sql/probe_test.go index 0ce7012b34..df0d4834bc 100644 --- a/internal/pkg/instrumentation/bpf/database/sql/probe_test.go +++ b/internal/pkg/instrumentation/bpf/database/sql/probe_test.go @@ -88,7 +88,10 @@ func TestProbeConvertEvent(t *testing.T) { SpanContext: context.EBPFSpanContext{TraceID: traceID, SpanID: spanID}, }, // "SELECT * FROM foo" - Query: [256]byte{0x53, 0x45, 0x4c, 0x45, 0x43, 0x54, 0x20, 0x2a, 0x20, 0x46, 0x52, 0x4f, 0x4d, 0x20, 0x66, 0x6f, 0x6f}, + Query: [256]byte{ + 0x53, 0x45, 0x4c, 0x45, 0x43, 0x54, 0x20, 0x2a, 0x20, + 0x46, 0x52, 0x4f, 0x4d, 0x20, 0x66, 0x6f, 0x6f, + }, }) want := func() ptrace.SpanSlice { @@ -101,7 +104,12 @@ func TestProbeConvertEvent(t *testing.T) { span.SetTraceID(pcommon.TraceID(traceID)) span.SetSpanID(pcommon.SpanID(spanID)) span.SetFlags(uint32(trace.FlagsSampled)) - utils.Attributes(span.Attributes(), semconv.DBQueryText("SELECT * FROM foo"), semconv.DBOperationName("SELECT"), semconv.DBCollectionName("foo")) + utils.Attributes( + span.Attributes(), + semconv.DBQueryText("SELECT * FROM foo"), + semconv.DBOperationName("SELECT"), + semconv.DBCollectionName("foo"), + ) return spans }() assert.Equal(t, want, got) diff --git a/internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/consumer/probe.go b/internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/consumer/probe.go index de82b3cb1f..1b90c89d09 100644 --- a/internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/consumer/probe.go +++ b/internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/consumer/probe.go @@ -42,31 +42,66 @@ func New(logger *slog.Logger, version string) probe.Probe { probe.AllocationConst{}, probe.StructFieldConst{ Key: "message_headers_pos", - ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Headers"), + ID: structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Headers", + ), }, probe.StructFieldConst{ Key: "message_key_pos", - ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Key"), + ID: structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Key", + ), }, probe.StructFieldConst{ Key: "message_topic_pos", - ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Topic"), + ID: structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Topic", + ), }, probe.StructFieldConst{ Key: "message_partition_pos", - ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Partition"), + ID: structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Partition", + ), }, probe.StructFieldConst{ Key: "message_offset_pos", - ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Offset"), + ID: structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Offset", + ), }, probe.StructFieldConst{ Key: "reader_config_pos", - ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Reader", "config"), + ID: structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Reader", + "config", + ), }, probe.StructFieldConst{ Key: "reader_config_group_id_pos", - ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "ReaderConfig", "GroupID"), + ID: structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "ReaderConfig", + "GroupID", + ), }, }, Uprobes: []*probe.Uprobe{ diff --git a/internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/consumer/probe_test.go b/internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/consumer/probe_test.go index 0bc701f72d..6c1d838702 100644 --- a/internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/consumer/probe_test.go +++ b/internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/consumer/probe_test.go @@ -39,9 +39,12 @@ func TestProbeConvertEvent(t *testing.T) { // key1 Key: [256]byte{0x6b, 0x65, 0x79, 0x31}, // test consumer group - ConsumerGroup: [128]byte{0x74, 0x65, 0x73, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70}, - Offset: 42, - Partition: 12, + ConsumerGroup: [128]byte{ + 0x74, 0x65, 0x73, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x75, + 0x6d, 0x65, 0x72, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, + }, + Offset: 42, + Partition: 12, }) want := func() ptrace.SpanSlice { diff --git a/internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/producer/probe.go b/internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/producer/probe.go index 3234f98d01..9049aa6661 100644 --- a/internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/producer/probe.go +++ b/internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/producer/probe.go @@ -43,19 +43,39 @@ func New(logger *slog.Logger, version string) probe.Probe { probe.AllocationConst{}, probe.StructFieldConst{ Key: "writer_topic_pos", - ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Writer", "Topic"), + ID: structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Writer", + "Topic", + ), }, probe.StructFieldConst{ Key: "message_headers_pos", - ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Headers"), + ID: structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Headers", + ), }, probe.StructFieldConst{ Key: "message_key_pos", - ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Key"), + ID: structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Key", + ), }, probe.StructFieldConst{ Key: "message_time_pos", - ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Time"), + ID: structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Time", + ), }, }, Uprobes: []*probe.Uprobe{ @@ -102,7 +122,10 @@ func processFn(e *event) ptrace.SpanSlice { if e.ValidMessages > 0 { e.ValidMessages = min(e.ValidMessages, math.MaxInt) - attrs = append(attrs, semconv.MessagingBatchMessageCount(int(e.ValidMessages))) // nolint: gosec // Bounded. + attrs = append( + attrs, + semconv.MessagingBatchMessageCount(int(e.ValidMessages)), // nolint: gosec // Bounded. + ) } traceID := pcommon.TraceID(e.Messages[0].SpanContext.TraceID) diff --git a/internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/traceglobal/probe.go b/internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/traceglobal/probe.go index b39400ec70..42f24dcda8 100644 --- a/internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/traceglobal/probe.go +++ b/internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/traceglobal/probe.go @@ -134,19 +134,39 @@ func New(logger *slog.Logger) probe.Probe { }, probe.StructFieldConst{ Key: "tracer_delegate_pos", - ID: structfield.NewID("go.opentelemetry.io/otel", "go.opentelemetry.io/otel/internal/global", "tracer", "delegate"), + ID: structfield.NewID( + "go.opentelemetry.io/otel", + "go.opentelemetry.io/otel/internal/global", + "tracer", + "delegate", + ), }, probe.StructFieldConst{ Key: "tracer_name_pos", - ID: structfield.NewID("go.opentelemetry.io/otel", "go.opentelemetry.io/otel/internal/global", "tracer", "name"), + ID: structfield.NewID( + "go.opentelemetry.io/otel", + "go.opentelemetry.io/otel/internal/global", + "tracer", + "name", + ), }, probe.StructFieldConst{ Key: "tracer_provider_pos", - ID: structfield.NewID("go.opentelemetry.io/otel", "go.opentelemetry.io/otel/internal/global", "tracer", "provider"), + ID: structfield.NewID( + "go.opentelemetry.io/otel", + "go.opentelemetry.io/otel/internal/global", + "tracer", + "provider", + ), }, probe.StructFieldConst{ Key: "tracer_provider_tracers_pos", - ID: structfield.NewID("go.opentelemetry.io/otel", "go.opentelemetry.io/otel/internal/global", "tracerProvider", "tracers"), + ID: structfield.NewID( + "go.opentelemetry.io/otel", + "go.opentelemetry.io/otel/internal/global", + "tracerProvider", + "tracers", + ), }, probe.StructFieldConstMaxVersion{ StructField: probe.StructFieldConst{ @@ -264,7 +284,10 @@ func (c tracerIDContainsSchemaURL) InjectOption(info *process.Info) (inject.Opti return nil, fmt.Errorf("unknown module version: %s", pkg) } - return inject.WithKeyValue("tracer_id_contains_schemaURL", ver.GreaterThanEqual(schemaAddedToTracerKeyVer)), nil + return inject.WithKeyValue( + "tracer_id_contains_schemaURL", + ver.GreaterThanEqual(schemaAddedToTracerKeyVer), + ), nil } // In v1.32.0 the tracer key was updated to include the scope attributes. @@ -280,7 +303,10 @@ func (c tracerIDContainsScopeAttributes) InjectOption(info *process.Info) (injec return nil, fmt.Errorf("unknown module version: %s", pkg) } - return inject.WithKeyValue("tracer_id_contains_scope_attributes", ver.GreaterThanEqual(scopeAttributesAddedToTracerKeyVer)), nil + return inject.WithKeyValue( + "tracer_id_contains_scope_attributes", + ver.GreaterThanEqual(scopeAttributesAddedToTracerKeyVer), + ), nil } type attributeKeyVal struct { diff --git a/internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/traceglobal/probe_test.go b/internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/traceglobal/probe_test.go index 4114f911c8..c7df0e1b09 100644 --- a/internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/traceglobal/probe_test.go +++ b/internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/traceglobal/probe_test.go @@ -60,7 +60,10 @@ func TestProbeConvertEvent(t *testing.T) { // "string_key1" Key: [32]byte{0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x6b, 0x65, 0x79, 0x31}, // "string value 1" - Value: [128]byte{0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x31}, + Value: [128]byte{ + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x31, + }, }, { ValLength: 0, @@ -87,7 +90,10 @@ func TestProbeConvertEvent(t *testing.T) { // "string_key2" Key: [32]byte{0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x6b, 0x65, 0x79, 0x32}, // "string value 2" - Value: [128]byte{0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x32}, + Value: [128]byte{ + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x20, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x32, + }, }, }, ValidAttrs: 5, diff --git a/internal/pkg/instrumentation/bpf/google.golang.org/grpc/client/probe.go b/internal/pkg/instrumentation/bpf/google.golang.org/grpc/client/probe.go index 4f85414e22..1518571eb3 100644 --- a/internal/pkg/instrumentation/bpf/google.golang.org/grpc/client/probe.go +++ b/internal/pkg/instrumentation/bpf/google.golang.org/grpc/client/probe.go @@ -69,45 +69,85 @@ func New(logger *slog.Logger, version string) probe.Probe { writeStatusConst{}, probe.StructFieldConst{ Key: "clientconn_target_ptr_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc", "ClientConn", "target"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc", + "ClientConn", + "target", + ), }, probe.StructFieldConst{ Key: "httpclient_nextid_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "http2Client", "nextID"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "http2Client", + "nextID", + ), }, probe.StructFieldConst{ Key: "headerFrame_hf_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "headerFrame", "hf"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "headerFrame", + "hf", + ), }, probe.StructFieldConst{ Key: "headerFrame_streamid_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "headerFrame", "streamID"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "headerFrame", + "streamID", + ), }, probe.StructFieldConstMinVersion{ StructField: probe.StructFieldConst{ Key: "error_status_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/status", "Error", "s"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/status", + "Error", + "s", + ), }, MinVersion: writeStatusMinVersion, }, probe.StructFieldConstMinVersion{ StructField: probe.StructFieldConst{ Key: "status_s_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/status", "Status", "s"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/status", + "Status", + "s", + ), }, MinVersion: writeStatusMinVersion, }, probe.StructFieldConstMinVersion{ StructField: probe.StructFieldConst{ Key: "status_code_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/genproto/googleapis/rpc/status", "Status", "Code"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/genproto/googleapis/rpc/status", + "Status", + "Code", + ), }, MinVersion: writeStatusMinVersion, }, probe.StructFieldConstMinVersion{ StructField: probe.StructFieldConst{ Key: "status_message_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/genproto/googleapis/rpc/status", "Status", "Message"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/genproto/googleapis/rpc/status", + "Status", + "Message", + ), }, MinVersion: writeStatusMinVersion, }, @@ -137,7 +177,9 @@ func New(logger *slog.Logger, version string) probe.Probe { func verifyAndLoadBpf() (*ebpf.CollectionSpec, error) { if !utils.SupportsContextPropagation() { - return nil, errors.New("the Linux Kernel doesn't support context propagation, please check if the kernel is in lockdown mode (/sys/kernel/security/lockdown)") + return nil, errors.New( + "the Linux Kernel doesn't support context propagation, please check if the kernel is in lockdown mode (/sys/kernel/security/lockdown)", + ) } return loadBpf() diff --git a/internal/pkg/instrumentation/bpf/google.golang.org/grpc/server/probe.go b/internal/pkg/instrumentation/bpf/google.golang.org/grpc/server/probe.go index 002fa39d10..9ead5b7690 100644 --- a/internal/pkg/instrumentation/bpf/google.golang.org/grpc/server/probe.go +++ b/internal/pkg/instrumentation/bpf/google.golang.org/grpc/server/probe.go @@ -58,56 +58,106 @@ func New(logger *slog.Logger, ver string) probe.Probe { serverAddrConst{}, probe.StructFieldConst{ Key: "stream_method_ptr_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "Stream", "method"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "Stream", + "method", + ), }, probe.StructFieldConst{ Key: "stream_id_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "Stream", "id"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "Stream", + "id", + ), }, probe.StructFieldConst{ Key: "stream_ctx_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "Stream", "ctx"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "Stream", + "ctx", + ), }, probe.StructFieldConstMinVersion{ StructField: probe.StructFieldConst{ Key: "server_stream_stream_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "ServerStream", "Stream"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "ServerStream", + "Stream", + ), }, MinVersion: serverStreamVersion, }, probe.StructFieldConst{ Key: "frame_fields_pos", - ID: structfield.NewID("golang.org/x/net", "golang.org/x/net/http2", "MetaHeadersFrame", "Fields"), + ID: structfield.NewID( + "golang.org/x/net", + "golang.org/x/net/http2", + "MetaHeadersFrame", + "Fields", + ), }, probe.StructFieldConst{ Key: "frame_stream_id_pod", - ID: structfield.NewID("golang.org/x/net", "golang.org/x/net/http2", "FrameHeader", "StreamID"), + ID: structfield.NewID( + "golang.org/x/net", + "golang.org/x/net/http2", + "FrameHeader", + "StreamID", + ), }, probe.StructFieldConstMinVersion{ StructField: probe.StructFieldConst{ Key: "status_s_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/status", "Status", "s"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/status", + "Status", + "s", + ), }, MinVersion: writeStatusMinVersion, }, probe.StructFieldConstMinVersion{ StructField: probe.StructFieldConst{ Key: "status_code_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/genproto/googleapis/rpc/status", "Status", "Code"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/genproto/googleapis/rpc/status", + "Status", + "Code", + ), }, MinVersion: writeStatusMinVersion, }, probe.StructFieldConstMinVersion{ StructField: probe.StructFieldConst{ Key: "http2server_peer_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "http2Server", "peer"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "http2Server", + "peer", + ), }, MinVersion: serverAddrMinVersion, }, probe.StructFieldConstMinVersion{ StructField: probe.StructFieldConst{ Key: "peer_local_addr_pos", - ID: structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/peer", "Peer", "LocalAddr"), + ID: structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/peer", + "Peer", + "LocalAddr", + ), }, MinVersion: serverAddrMinVersion, }, @@ -128,8 +178,10 @@ func New(logger *slog.Logger, ver string) probe.Probe { ReturnProbe: "uprobe_server_handleStream_Returns", PackageConstraints: []probe.PackageConstraints{ { - Package: "google.golang.org/grpc", - Constraints: must(semver.NewConstraint("< " + serverStreamVersion.String())), + Package: "google.golang.org/grpc", + Constraints: must( + semver.NewConstraint("< " + serverStreamVersion.String()), + ), FailureMode: probe.FailureModeIgnore, }, }, @@ -140,8 +192,10 @@ func New(logger *slog.Logger, ver string) probe.Probe { ReturnProbe: "uprobe_server_handleStream2_Returns", PackageConstraints: []probe.PackageConstraints{ { - Package: "google.golang.org/grpc", - Constraints: must(semver.NewConstraint(">= " + serverStreamVersion.String())), + Package: "google.golang.org/grpc", + Constraints: must( + semver.NewConstraint(">= " + serverStreamVersion.String()), + ), FailureMode: probe.FailureModeIgnore, }, }, @@ -157,7 +211,11 @@ func New(logger *slog.Logger, ver string) probe.Probe { { Package: "google.golang.org/grpc", Constraints: must(semver.NewConstraint( - fmt.Sprintf("> %s, < %s", writeStatusMinVersion, serverStreamVersion), + fmt.Sprintf( + "> %s, < %s", + writeStatusMinVersion, + serverStreamVersion, + ), )), FailureMode: probe.FailureModeIgnore, }, @@ -168,8 +226,10 @@ func New(logger *slog.Logger, ver string) probe.Probe { EntryProbe: "uprobe_http2Server_WriteStatus2", PackageConstraints: []probe.PackageConstraints{ { - Package: "google.golang.org/grpc", - Constraints: must(semver.NewConstraint(">= " + serverStreamVersion.String())), + Package: "google.golang.org/grpc", + Constraints: must( + semver.NewConstraint(">= " + serverStreamVersion.String()), + ), FailureMode: probe.FailureModeIgnore, }, }, diff --git a/internal/pkg/instrumentation/bpf/net/http/client/probe.go b/internal/pkg/instrumentation/bpf/net/http/client/probe.go index 15839eaad8..e02869e974 100644 --- a/internal/pkg/instrumentation/bpf/net/http/client/probe.go +++ b/internal/pkg/instrumentation/bpf/net/http/client/probe.go @@ -166,7 +166,10 @@ func New(logger *slog.Logger, version string) probe.Probe { func verifyAndLoadBpf() (*ebpf.CollectionSpec, error) { if !utils.SupportsContextPropagation() { - fmt.Fprintf(os.Stderr, "the Linux Kernel doesn't support context propagation, please check if the kernel is in lockdown mode (/sys/kernel/security/lockdown)") + fmt.Fprintf( + os.Stderr, + "the Linux Kernel doesn't support context propagation, please check if the kernel is in lockdown mode (/sys/kernel/security/lockdown)", + ) return loadBpf_no_tp() } @@ -219,7 +222,9 @@ func processFn(e *event) ptrace.SpanSlice { } attrs := []attribute.KeyValue{ semconv.HTTPRequestMethodKey.String(method), - semconv.HTTPResponseStatusCodeKey.Int(int(e.StatusCode)), // nolint: gosec // Bound checked. + semconv.HTTPResponseStatusCodeKey.Int( + int(e.StatusCode), + ), // nolint: gosec // Bound checked. } if path != "" { diff --git a/internal/pkg/instrumentation/bpf/net/http/server/probe.go b/internal/pkg/instrumentation/bpf/net/http/server/probe.go index 580f2d06f0..9838bbb4d2 100644 --- a/internal/pkg/instrumentation/bpf/net/http/server/probe.go +++ b/internal/pkg/instrumentation/bpf/net/http/server/probe.go @@ -198,7 +198,9 @@ func processFn(e *event) ptrace.SpanSlice { attrs := []attribute.KeyValue{ semconv.HTTPRequestMethodKey.String(method), semconv.URLPath(path), - semconv.HTTPResponseStatusCodeKey.Int(int(e.StatusCode)), // nolint: gosec // Bound checked. + semconv.HTTPResponseStatusCodeKey.Int( + int(e.StatusCode), + ), // nolint: gosec // Bound checked. } // Client address and port diff --git a/internal/pkg/instrumentation/bpf/net/http/server/probe_test.go b/internal/pkg/instrumentation/bpf/net/http/server/probe_test.go index 50188e14a2..a724365b00 100644 --- a/internal/pkg/instrumentation/bpf/net/http/server/probe_test.go +++ b/internal/pkg/instrumentation/bpf/net/http/server/probe_test.go @@ -47,9 +47,15 @@ func TestProbeConvertEvent(t *testing.T) { // "/foo/bar" Path: [128]byte{0x2f, 0x66, 0x6f, 0x6f, 0x2f, 0x62, 0x61, 0x72}, // "www.google.com:8080" - RemoteAddr: [256]byte{0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x0}, + RemoteAddr: [256]byte{ + 0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x63, 0x6f, 0x6d, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x0, + }, // "localhost:8080" - Host: [256]byte{0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x0}, + Host: [256]byte{ + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, + 0x38, 0x30, 0x38, 0x30, 0x0, + }, // "HTTP/1.1" Proto: [8]byte{0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31}, }, @@ -92,9 +98,15 @@ func TestProbeConvertEvent(t *testing.T) { // "/foo/bar" Path: [128]byte{0x2f, 0x66, 0x6f, 0x6f, 0x2f, 0x62, 0x61, 0x72}, // "www.google.com:8080" - RemoteAddr: [256]byte{0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x0}, + RemoteAddr: [256]byte{ + 0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x63, 0x6f, 0x6d, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x0, + }, // "localhost:8080" - Host: [256]byte{0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x0}, + Host: [256]byte{ + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, + 0x38, 0x30, 0x38, 0x30, 0x0, + }, // "FOO/2.2" Proto: [8]byte{0x46, 0x4f, 0x4f, 0x2f, 0x32, 0x2e, 0x32}, }, @@ -138,9 +150,15 @@ func TestProbeConvertEvent(t *testing.T) { // "/foo/bar" Path: [128]byte{0x2f, 0x66, 0x6f, 0x6f, 0x2f, 0x62, 0x61, 0x72}, // "www.google.com:8080" - RemoteAddr: [256]byte{0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x0}, + RemoteAddr: [256]byte{ + 0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x63, 0x6f, 0x6d, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x0, + }, // "localhost:8080" - Host: [256]byte{0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x0}, + Host: [256]byte{ + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, + 0x38, 0x30, 0x38, 0x30, 0x0, + }, // "HTTP/1.1" Proto: [8]byte{0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31}, }, @@ -183,9 +201,15 @@ func TestProbeConvertEvent(t *testing.T) { // "/foo/bar" Path: [128]byte{0x2f, 0x66, 0x6f, 0x6f, 0x2f, 0x62, 0x61, 0x72}, // "www.google.com:8080" - RemoteAddr: [256]byte{0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x0}, + RemoteAddr: [256]byte{ + 0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x63, 0x6f, 0x6d, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x0, + }, // "localhost:8080" - Host: [256]byte{0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x0}, + Host: [256]byte{ + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, + 0x38, 0x30, 0x38, 0x30, 0x0, + }, // "HTTP/1.1" Proto: [8]byte{0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31}, }, diff --git a/internal/pkg/instrumentation/manager.go b/internal/pkg/instrumentation/manager.go index 23ffad8a27..8bbbba32f1 100644 --- a/internal/pkg/instrumentation/manager.go +++ b/internal/pkg/instrumentation/manager.go @@ -57,7 +57,13 @@ type Manager struct { } // NewManager returns a new [Manager]. -func NewManager(logger *slog.Logger, otelController *opentelemetry.Controller, pid process.ID, cp ConfigProvider, probes ...probe.Probe) (*Manager, error) { +func NewManager( + logger *slog.Logger, + otelController *opentelemetry.Controller, + pid process.ID, + cp ConfigProvider, + probes ...probe.Probe, +) (*Manager, error) { m := &Manager{ logger: logger, probes: make(map[probe.ID]probe.Probe), @@ -99,7 +105,12 @@ func (m *Manager) validateProbeDependents(id probe.ID, symbols []probe.FunctionS for _, s := range symbols { for _, d := range s.DependsOn { if _, exists := funcsMap[d]; !exists { - return fmt.Errorf("library %s has declared a dependent function %s for probe %s which does not exist, aborting", id, d, s.Symbol) + return fmt.Errorf( + "library %s has declared a dependent function %s for probe %s which does not exist, aborting", + id, + d, + s.Symbol, + ) } } } @@ -230,7 +241,9 @@ func (m *Manager) ConfigLoop(ctx context.Context) { return case c, ok := <-m.cp.Watch(): if !ok { - m.logger.Info("Configuration provider closed, configuration updates will no longer be received") + m.logger.Info( + "Configuration provider closed, configuration updates will no longer be received", + ) return } err := m.applyConfig(c) @@ -251,7 +264,9 @@ func (m *Manager) Load(ctx context.Context) error { return errors.New("no config provider set") } if m.proc == nil { - return errors.New("target details not set - load is called on non-initialized instrumentation") + return errors.New( + "target details not set - load is called on non-initialized instrumentation", + ) } m.stateMu.Lock() defer m.stateMu.Unlock() @@ -367,7 +382,13 @@ func (m *Manager) loadProbes() error { m.logger.Info("loading probe", "name", name) err := i.Load(exe, m.proc, m.currentConfig.SamplingConfig) if err != nil { - m.logger.Error("error while loading probes, cleaning up", "error", err, "name", name) + m.logger.Error( + "error while loading probes, cleaning up", + "error", + err, + "name", + name, + ) return errors.Join(err, m.cleanup()) } } diff --git a/internal/pkg/instrumentation/manager_test.go b/internal/pkg/instrumentation/manager_test.go index 9d37ce7897..c07b0f9cf3 100644 --- a/internal/pkg/instrumentation/manager_test.go +++ b/internal/pkg/instrumentation/manager_test.go @@ -404,7 +404,10 @@ func (p *dummyProvider) sendConfig(c Config) { func TestConfigProvider(t *testing.T) { netHTTPClientProbeID := probe.ID{InstrumentedPkg: "net/http", SpanKind: trace.SpanKindClient} netHTTPServerProbeID := probe.ID{InstrumentedPkg: "net/http", SpanKind: trace.SpanKindServer} - somePackageProducerProbeID := probe.ID{InstrumentedPkg: "some/package", SpanKind: trace.SpanKindProducer} + somePackageProducerProbeID := probe.ID{ + InstrumentedPkg: "some/package", + SpanKind: trace.SpanKindProducer, + } netHTTPClientLibID := LibraryID{InstrumentedPkg: "net/http", SpanKind: trace.SpanKindClient} netHTTPLibID := LibraryID{InstrumentedPkg: "net/http"} diff --git a/internal/pkg/instrumentation/probe/probe.go b/internal/pkg/instrumentation/probe/probe.go index 2abf056afb..37ed8ec930 100644 --- a/internal/pkg/instrumentation/probe/probe.go +++ b/internal/pkg/instrumentation/probe/probe.go @@ -116,7 +116,11 @@ func (i *Base[BPFObj, BPFEvent]) Spec() (*ebpf.CollectionSpec, error) { } // Load loads all instrumentation offsets. -func (i *Base[BPFObj, BPFEvent]) Load(exec *link.Executable, info *process.Info, sampler *sampling.Config) error { +func (i *Base[BPFObj, BPFEvent]) Load( + exec *link.Executable, + info *process.Info, + sampler *sampling.Config, +) error { spec, err := i.SpecFn() if err != nil { return err @@ -189,7 +193,12 @@ func (i *Base[BPFObj, BPFEvent]) loadUprobes(exec *link.Executable, info *proces logFn = i.Logger.Warn default: // Unknown and FailureModeError. - return fmt.Errorf("uprobe %s package constraint (%s) not met, version %v", up.Sym, pc.Constraints.String(), info.Modules[pc.Package]) + return fmt.Errorf( + "uprobe %s package constraint (%s) not met, version %v", + up.Sym, + pc.Constraints.String(), + info.Modules[pc.Package], + ) } logFn( @@ -242,7 +251,10 @@ func (i *Base[BPFObj, BPFEvent]) initReader() error { return nil } -func (i *Base[BPFObj, BPFEvent]) buildEBPFCollection(info *process.Info, spec *ebpf.CollectionSpec) (*ebpf.Collection, error) { +func (i *Base[BPFObj, BPFEvent]) buildEBPFCollection( + info *process.Info, + spec *ebpf.CollectionSpec, +) (*ebpf.Collection, error) { obj := new(BPFObj) if c, ok := ((interface{})(obj)).(io.Closer); ok { i.closers = append(i.closers, c) diff --git a/internal/pkg/instrumentation/probe/sampling/sampling.go b/internal/pkg/instrumentation/probe/sampling/sampling.go index 7694dfa397..c08f5f78f1 100644 --- a/internal/pkg/instrumentation/probe/sampling/sampling.go +++ b/internal/pkg/instrumentation/probe/sampling/sampling.go @@ -240,7 +240,11 @@ func (m *Manager) applyConfig(conf *Config) error { return err } if len(b) != sampleConfigSize { - return fmt.Errorf("unexpected sampler config size, expected %d, got %d", sampleConfigSize, len(b)) + return fmt.Errorf( + "unexpected sampler config size, expected %d, got %d", + sampleConfigSize, + len(b), + ) } copy(configsBytes[i][:], b) } diff --git a/internal/pkg/instrumentation/probe/sampling/utils.go b/internal/pkg/instrumentation/probe/sampling/utils.go index 8a09016b64..f76cab4b5b 100644 --- a/internal/pkg/instrumentation/probe/sampling/utils.go +++ b/internal/pkg/instrumentation/probe/sampling/utils.go @@ -7,7 +7,9 @@ import "errors" var ( errInvalidFraction = errors.New("fraction must be a positive float between 0 and 1") - errPrecisionLoss = errors.New("the given float cannot be represented as a fraction with the current precision") + errPrecisionLoss = errors.New( + "the given float cannot be represented as a fraction with the current precision", + ) ) // floatToNumerator converts a float to a numerator of a fraction with the given denominator. diff --git a/internal/pkg/instrumentation/utils/ebpf.go b/internal/pkg/instrumentation/utils/ebpf.go index 6712460235..079ab92813 100644 --- a/internal/pkg/instrumentation/utils/ebpf.go +++ b/internal/pkg/instrumentation/utils/ebpf.go @@ -19,7 +19,10 @@ const ( // InitializeEBPFCollection loads eBPF objects from the given spec and returns a collection corresponding to the spec. // If the environment variable OTEL_GO_AUTO_SHOW_VERIFIER_LOG is set to true, the verifier log will be printed. -func InitializeEBPFCollection(spec *ebpf.CollectionSpec, opts *ebpf.CollectionOptions) (*ebpf.Collection, error) { +func InitializeEBPFCollection( + spec *ebpf.CollectionSpec, + opts *ebpf.CollectionOptions, +) (*ebpf.Collection, error) { // Getting full verifier log is expensive, so we only do it if the user explicitly asks for it. showVerifierLogs := ShouldShowVerifierLogs() if showVerifierLogs { diff --git a/internal/pkg/instrumentation/utils/kernel_linux_test.go b/internal/pkg/instrumentation/utils/kernel_linux_test.go index 47a63cc30c..c1aaa6be40 100644 --- a/internal/pkg/instrumentation/utils/kernel_linux_test.go +++ b/internal/pkg/instrumentation/utils/kernel_linux_test.go @@ -21,14 +21,22 @@ func TestGetLinuxKernelVersion(t *testing.T) { }{ "ubuntu-23.10": { unameFn: func(buf *syscall.Utsname) error { - buf.Release = [65]int8{54, 46, 53, 46, 48, 45, 57, 45, 103, 101, 110, 101, 114, 105, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + buf.Release = [65]int8{ + 54, 46, 53, 46, 48, 45, 57, 45, 103, 101, 110, 101, 114, 105, 99, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + } return nil }, want: semver.New(6, 5, 0, "", ""), }, "debian-12": { unameFn: func(buf *syscall.Utsname) error { - buf.Release = [65]int8{54, 46, 49, 46, 48, 45, 49, 50, 45, 99, 108, 111, 117, 100, 45, 97, 109, 100, 54, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + buf.Release = [65]int8{ + 54, 46, 49, 46, 48, 45, 49, 50, 45, 99, 108, 111, 117, 100, 45, 97, 109, + 100, 54, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + } return nil }, want: semver.New(6, 1, 0, "", ""), diff --git a/internal/pkg/process/binary/funcs_nonstripped.go b/internal/pkg/process/binary/funcs_nonstripped.go index a3cc13caa4..991e5645a1 100644 --- a/internal/pkg/process/binary/funcs_nonstripped.go +++ b/internal/pkg/process/binary/funcs_nonstripped.go @@ -10,7 +10,10 @@ import ( "math" ) -func FindFunctionsUnStripped(elfF *elf.File, relevantFuncs map[string]interface{}) ([]*Func, error) { +func FindFunctionsUnStripped( + elfF *elf.File, + relevantFuncs map[string]interface{}, +) ([]*Func, error) { symbols, err := elfF.Symbols() if err != nil { return nil, err @@ -72,7 +75,11 @@ func getFuncOffsetUnstripped(f *elf.File, symbol elf.Symbol) (uint64, error) { return symbol.Value - execSection.Addr + execSection.Offset, nil } -func findFuncReturnsUnstripped(elfFile *elf.File, sym elf.Symbol, functionOffset uint64) ([]uint64, error) { +func findFuncReturnsUnstripped( + elfFile *elf.File, + sym elf.Symbol, + functionOffset uint64, +) ([]uint64, error) { textSection := elfFile.Section(".text") if textSection == nil { return nil, errors.New("could not find .text section in binary") @@ -80,7 +87,11 @@ func findFuncReturnsUnstripped(elfFile *elf.File, sym elf.Symbol, functionOffset lowPC := sym.Value if textSection.Addr > lowPC { - return nil, fmt.Errorf("invalid .text section address: %d (symbol value %d)", textSection.Addr, lowPC) + return nil, fmt.Errorf( + "invalid .text section address: %d (symbol value %d)", + textSection.Addr, + lowPC, + ) } offset := lowPC - textSection.Addr if offset > math.MaxInt64 { diff --git a/internal/pkg/process/ptrace_linux.go b/internal/pkg/process/ptrace_linux.go index 8157885986..9b31fd5dd4 100644 --- a/internal/pkg/process/ptrace_linux.go +++ b/internal/pkg/process/ptrace_linux.go @@ -102,7 +102,15 @@ func newTracedProgram(id ID, logger *slog.Logger) (*tracedProgram, error) { retryCount[tid]++ } if retryCount[tid] < threadRetryLimit { - logger.Debug("retry attaching thread", "tid", tid, "retryCount", retryCount[tid], "limit", threadRetryLimit) + logger.Debug( + "retry attaching thread", + "tid", + tid, + "retryCount", + retryCount[tid], + "limit", + threadRetryLimit, + ) continue } @@ -221,7 +229,15 @@ func (p *tracedProgram) SetMemLockInfinity() error { // Mmap runs mmap syscall. func (p *tracedProgram) Mmap(length uint64, fd uint64) (uint64, error) { - return p.Syscall(syscall.SYS_MMAP, 0, length, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE|syscall.MAP_POPULATE|syscall.MAP_LOCKED, fd, 0) + return p.Syscall( + syscall.SYS_MMAP, + 0, + length, + syscall.PROT_READ|syscall.PROT_WRITE, + syscall.MAP_ANON|syscall.MAP_PRIVATE|syscall.MAP_POPULATE|syscall.MAP_LOCKED, + fd, + 0, + ) } // Madvise runs madvise syscall. diff --git a/internal/pkg/structfield/structfield_test.go b/internal/pkg/structfield/structfield_test.go index da0e8faf55..f6bc2bec3a 100644 --- a/internal/pkg/structfield/structfield_test.go +++ b/internal/pkg/structfield/structfield_test.go @@ -141,7 +141,9 @@ func TestGetLatestOffsetFromIndex(t *testing.T) { assert.Equal(t, v120, ver, "invalid version for Response.Status") assert.Equal(t, OffsetKey{Offset: 0, Valid: true}, off, "invalid value for Response.Status") - off, ver = index.GetLatestOffset(NewID("google.golang.org/grpc", "google.golang.org/grpc", "ClientConn", "target")) + off, ver = index.GetLatestOffset( + NewID("google.golang.org/grpc", "google.golang.org/grpc", "ClientConn", "target"), + ) assert.Equal(t, v120, ver, "invalid version for ClientConn.target") assert.Equal(t, OffsetKey{Offset: 0, Valid: true}, off, "invalid value for ClientConn.target") } diff --git a/internal/test/e2e/databasesql/main.go b/internal/test/e2e/databasesql/main.go index 071698174c..ef66f4a761 100644 --- a/internal/test/e2e/databasesql/main.go +++ b/internal/test/e2e/databasesql/main.go @@ -96,7 +96,15 @@ func (s *Server) query(w http.ResponseWriter, req *http.Request, query string) { if err != nil { panic(err) } - fmt.Fprintf(w, "ID: %d, firstName: %s, lastName: %s, email: %s, phone: %s\n", id, firstName, lastName, email, phone) + fmt.Fprintf( + w, + "ID: %d, firstName: %s, lastName: %s, email: %s, phone: %s\n", + id, + firstName, + lastName, + email, + phone, + ) } } diff --git a/internal/test/e2e/nethttp_custom/main.go b/internal/test/e2e/nethttp_custom/main.go index 3264dd4c0c..c86a212546 100644 --- a/internal/test/e2e/nethttp_custom/main.go +++ b/internal/test/e2e/nethttp_custom/main.go @@ -77,7 +77,10 @@ func (rt *MyRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { func main() { go func() { - _ = http.ListenAndServe(":8080", logStatus(http.HandlerFunc(hello))) // nolint: gosec // Testing server. + _ = http.ListenAndServe( // nolint: gosec // Testing server. + ":8080", + logStatus(http.HandlerFunc(hello)), + ) }() // give time for auto-instrumentation to start up diff --git a/internal/tools/inspect/builder.go b/internal/tools/inspect/builder.go index b545b1c9a0..abbbebe4fe 100644 --- a/internal/tools/inspect/builder.go +++ b/internal/tools/inspect/builder.go @@ -59,7 +59,12 @@ func newBuilder(l *slog.Logger, cli *client.Client, goVer *semver.Version) *buil } // Build builds the appV version of a Go application located in dir. -func (b *builder) Build(ctx context.Context, dir string, appV *semver.Version, modName string) (string, error) { +func (b *builder) Build( + ctx context.Context, + dir string, + appV *semver.Version, + modName string, +) (string, error) { b.log.Debug("building application...", "version", appV, "dir", dir, "image", b.GoImage) app := "app" + appV.Original() diff --git a/internal/tools/inspect/cmd/offsetgen/main.go b/internal/tools/inspect/cmd/offsetgen/main.go index 1c0379802c..63fc3043c1 100644 --- a/internal/tools/inspect/cmd/offsetgen/main.go +++ b/internal/tools/inspect/cmd/offsetgen/main.go @@ -133,20 +133,90 @@ func manifests() ([]inspect.Manifest, error) { Versions: grpcVers, }, StructFields: []structfield.ID{ - structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "Stream", "method"), - structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "Stream", "id"), - structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "Stream", "ctx"), - structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "ServerStream", "Stream"), - structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc", "ClientConn", "target"), - structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "http2Client", "nextID"), - structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "headerFrame", "streamID"), - structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "headerFrame", "hf"), - structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/status", "Error", "s"), - structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/status", "Status", "s"), - structfield.NewID("google.golang.org/grpc", "google.golang.org/genproto/googleapis/rpc/status", "Status", "Code"), - structfield.NewID("google.golang.org/grpc", "google.golang.org/genproto/googleapis/rpc/status", "Status", "Message"), - structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/internal/transport", "http2Server", "peer"), - structfield.NewID("google.golang.org/grpc", "google.golang.org/grpc/peer", "Peer", "LocalAddr"), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "Stream", + "method", + ), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "Stream", + "id", + ), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "Stream", + "ctx", + ), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "ServerStream", + "Stream", + ), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc", + "ClientConn", + "target", + ), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "http2Client", + "nextID", + ), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "headerFrame", + "streamID", + ), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "headerFrame", + "hf", + ), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/status", + "Error", + "s", + ), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/status", + "Status", + "s", + ), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/genproto/googleapis/rpc/status", + "Status", + "Code", + ), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/genproto/googleapis/rpc/status", + "Status", + "Message", + ), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/internal/transport", + "http2Server", + "peer", + ), + structfield.NewID( + "google.golang.org/grpc", + "google.golang.org/grpc/peer", + "Peer", + "LocalAddr", + ), }, }, { @@ -155,8 +225,18 @@ func manifests() ([]inspect.Manifest, error) { Versions: xNetVers, }, StructFields: []structfield.ID{ - structfield.NewID("golang.org/x/net", "golang.org/x/net/http2", "MetaHeadersFrame", "Fields"), - structfield.NewID("golang.org/x/net", "golang.org/x/net/http2", "FrameHeader", "StreamID"), + structfield.NewID( + "golang.org/x/net", + "golang.org/x/net/http2", + "MetaHeadersFrame", + "Fields", + ), + structfield.NewID( + "golang.org/x/net", + "golang.org/x/net/http2", + "FrameHeader", + "StreamID", + ), }, }, { @@ -165,13 +245,48 @@ func manifests() ([]inspect.Manifest, error) { Versions: goOtelVers, }, StructFields: []structfield.ID{ - structfield.NewID("go.opentelemetry.io/otel", "go.opentelemetry.io/otel/internal/global", "tracer", "delegate"), - structfield.NewID("go.opentelemetry.io/otel", "go.opentelemetry.io/otel/internal/global", "tracer", "name"), - structfield.NewID("go.opentelemetry.io/otel", "go.opentelemetry.io/otel/internal/global", "tracer", "provider"), - structfield.NewID("go.opentelemetry.io/otel", "go.opentelemetry.io/otel/internal/global", "tracerProvider", "tracers"), - structfield.NewID("go.opentelemetry.io/otel", "go.opentelemetry.io/otel/trace", "SpanContext", "traceID"), - structfield.NewID("go.opentelemetry.io/otel", "go.opentelemetry.io/otel/trace", "SpanContext", "spanID"), - structfield.NewID("go.opentelemetry.io/otel", "go.opentelemetry.io/otel/trace", "SpanContext", "traceFlags"), + structfield.NewID( + "go.opentelemetry.io/otel", + "go.opentelemetry.io/otel/internal/global", + "tracer", + "delegate", + ), + structfield.NewID( + "go.opentelemetry.io/otel", + "go.opentelemetry.io/otel/internal/global", + "tracer", + "name", + ), + structfield.NewID( + "go.opentelemetry.io/otel", + "go.opentelemetry.io/otel/internal/global", + "tracer", + "provider", + ), + structfield.NewID( + "go.opentelemetry.io/otel", + "go.opentelemetry.io/otel/internal/global", + "tracerProvider", + "tracers", + ), + structfield.NewID( + "go.opentelemetry.io/otel", + "go.opentelemetry.io/otel/trace", + "SpanContext", + "traceID", + ), + structfield.NewID( + "go.opentelemetry.io/otel", + "go.opentelemetry.io/otel/trace", + "SpanContext", + "spanID", + ), + structfield.NewID( + "go.opentelemetry.io/otel", + "go.opentelemetry.io/otel/trace", + "SpanContext", + "traceFlags", + ), }, }, { @@ -180,16 +295,66 @@ func manifests() ([]inspect.Manifest, error) { Versions: kafkaGoVers, }, StructFields: []structfield.ID{ - structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Topic"), - structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Partition"), - structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Offset"), - structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Key"), - structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Headers"), - structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Time"), - structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Writer", "Topic"), - structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Reader", "config"), - structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "ReaderConfig", "GroupID"), - structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Conn", "clientID"), + structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Topic", + ), + structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Partition", + ), + structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Offset", + ), + structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Key", + ), + structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Headers", + ), + structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Message", + "Time", + ), + structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Writer", + "Topic", + ), + structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Reader", + "config", + ), + structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "ReaderConfig", + "GroupID", + ), + structfield.NewID( + "github.com/segmentio/kafka-go", + "github.com/segmentio/kafka-go", + "Conn", + "clientID", + ), }, }, }, nil diff --git a/provider.go b/provider.go index 26d84c7787..fec3257f54 100644 --- a/provider.go +++ b/provider.go @@ -117,7 +117,10 @@ func (c *converter) instrumentationConfig(ic InstrumentationConfig) instrumentat out.DefaultTracesDisabled = ic.DefaultTracesDisabled if n := len(ic.InstrumentationLibraryConfigs); n > 0 { - out.InstrumentationLibraryConfigs = make(map[instrumentation.LibraryID]instrumentation.Library, len(ic.InstrumentationLibraryConfigs)) + out.InstrumentationLibraryConfigs = make( + map[instrumentation.LibraryID]instrumentation.Library, + len(ic.InstrumentationLibraryConfigs), + ) for k, v := range ic.InstrumentationLibraryConfigs { id := instrumentation.LibraryID{ InstrumentedPkg: k.InstrumentedPkg, diff --git a/sdk/internal/telemetry/test/conversion_test.go b/sdk/internal/telemetry/test/conversion_test.go index 2a7cf597a1..25d04cc170 100644 --- a/sdk/internal/telemetry/test/conversion_test.go +++ b/sdk/internal/telemetry/test/conversion_test.go @@ -233,7 +233,9 @@ func TestEncode(t *testing.T) { require.NoError(t, enc.Encode(traces)) data := buf.Bytes() - t.Log(string(data)) // This helps when test fails to understand what how the data has been encoded. + t.Log( + string(data), + ) // This helps when test fails to understand what how the data has been encoded. var dec ptrace.JSONUnmarshaler got, err := dec.UnmarshalTraces(data) diff --git a/sdk/limit_test.go b/sdk/limit_test.go index 448651f2ad..d3e635fbf1 100644 --- a/sdk/limit_test.go +++ b/sdk/limit_test.go @@ -95,7 +95,12 @@ func TestSpanLimit(t *testing.T) { var data map[string]any require.NoError(t, json.NewDecoder(&buf).Decode(&data)) - assert.Equal(t, "invalid limit environment variable", data["msg"], "log message") + assert.Equal( + t, + "invalid limit environment variable", + data["msg"], + "log message", + ) assert.Equal(t, "WARN", data["level"], "logged level") assert.Equal(t, key, data["key"], "logged key") assert.Equal(t, value, data["value"], "logged value") diff --git a/sdk/span.go b/sdk/span.go index 24ad7758b9..3aeeea2294 100644 --- a/sdk/span.go +++ b/sdk/span.go @@ -88,7 +88,9 @@ func (s *span) SetAttributes(attrs ...attribute.KeyValue) { // No attributes allowed. n := int64(len(attrs)) if n > 0 { - s.span.DroppedAttrs += uint32(min(n, math.MaxUint32)) // nolint: gosec // Bounds checked. + s.span.DroppedAttrs += uint32( // nolint: gosec // Bounds checked. + min(n, math.MaxUint32), + ) } return } diff --git a/sdk/span_test.go b/sdk/span_test.go index ad236e6dd1..33db54c4a7 100644 --- a/sdk/span_test.go +++ b/sdk/span_test.go @@ -698,15 +698,33 @@ func TestSpanAttributeValueLimits(t *testing.T) { s := builder.Build() s.SetAttributes(aStr, aStrSlice) - assert.Truef(t, eq(want, s.span.Attrs), "set span attributes: got %#v, want %#v", s.span.Attrs, want) + assert.Truef( + t, + eq(want, s.span.Attrs), + "set span attributes: got %#v, want %#v", + s.span.Attrs, + want, + ) s.AddEvent("test", trace.WithAttributes(aStr, aStrSlice)) - assert.Truef(t, eq(want, s.span.Events[0].Attrs), "span event attributes: got %#v, want %#v", s.span.Events[0].Attrs, want) + assert.Truef( + t, + eq(want, s.span.Events[0].Attrs), + "span event attributes: got %#v, want %#v", + s.span.Events[0].Attrs, + want, + ) s.AddLink(trace.Link{ Attributes: []attribute.KeyValue{aStr, aStrSlice}, }) - assert.Truef(t, eq(want, s.span.Links[0].Attrs), "span link attributes: got %#v, want %#v", s.span.Links[0].Attrs, want) + assert.Truef( + t, + eq(want, s.span.Links[0].Attrs), + "span link attributes: got %#v, want %#v", + s.span.Links[0].Attrs, + want, + ) builder.Options = []trace.SpanStartOption{ trace.WithAttributes(aStr, aStrSlice), @@ -715,8 +733,20 @@ func TestSpanAttributeValueLimits(t *testing.T) { }), } s = builder.Build() - assert.Truef(t, eq(want, s.span.Attrs), "new span attributes: got %#v, want %#v", s.span.Attrs, want) - assert.Truef(t, eq(want, s.span.Links[0].Attrs), "new span link attributes: got %#v, want %#v", s.span.Attrs, want) + assert.Truef( + t, + eq(want, s.span.Attrs), + "new span attributes: got %#v, want %#v", + s.span.Attrs, + want, + ) + assert.Truef( + t, + eq(want, s.span.Links[0].Attrs), + "new span link attributes: got %#v, want %#v", + s.span.Attrs, + want, + ) }) } } diff --git a/sdk/tracer.go b/sdk/tracer.go index d147e4121e..056a321cb8 100644 --- a/sdk/tracer.go +++ b/sdk/tracer.go @@ -22,7 +22,11 @@ type tracer struct { var _ trace.Tracer = tracer{} -func (t tracer) Start(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { +func (t tracer) Start( + ctx context.Context, + name string, + opts ...trace.SpanStartOption, +) (context.Context, trace.Span) { var psc, sc trace.SpanContext sampled := true span := new(span) @@ -60,7 +64,11 @@ func (t *tracer) start( // start is used for testing. var start = func(context.Context, *span, *trace.SpanContext, *bool, *trace.SpanContext) {} -func (t tracer) traces(name string, cfg trace.SpanConfig, sc, psc trace.SpanContext) (*telemetry.Traces, *telemetry.Span) { +func (t tracer) traces( + name string, + cfg trace.SpanConfig, + sc, psc trace.SpanContext, +) (*telemetry.Traces, *telemetry.Span) { span := &telemetry.Span{ TraceID: telemetry.TraceID(sc.TraceID()), SpanID: telemetry.SpanID(sc.SpanID()),