Skip to content

Commit 0a1eab7

Browse files
committed
Add the golines formatter to golangci-lint
1 parent d4ca770 commit 0a1eab7

File tree

37 files changed

+731
-137
lines changed

37 files changed

+731
-137
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ formatters:
257257
enable:
258258
- gofumpt
259259
- goimports
260+
- golines
260261
settings:
261262
goimports:
262263
local-prefixes:

cli/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ func main() {
9999
var targetPID int
100100
var targetExe string
101101

102-
flag.BoolVar(&globalImpl, "global-impl", false, "Record telemetry from the OpenTelemetry default global implementation")
102+
flag.BoolVar(
103+
&globalImpl,
104+
"global-impl",
105+
false,
106+
"Record telemetry from the OpenTelemetry default global implementation",
107+
)
103108
flag.StringVar(&logLevel, "log-level", "", `Logging level ("debug", "info", "warn", "error")`)
104109
flag.IntVar(&targetPID, "target-pid", -1, `PID of target process`)
105110
flag.StringVar(&targetExe, "target-exe", "", `Executable path run by the target process`)

examples/httpPlusdb/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,15 @@ func (s *Server) queryDb(w http.ResponseWriter, req *http.Request) {
9898
if err != nil {
9999
panic(err)
100100
}
101-
fmt.Fprintf(w, "ID: %d, firstName: %s, lastName: %s, email: %s, phone: %s\n", id, firstName, lastName, email, phone)
101+
fmt.Fprintf(
102+
w,
103+
"ID: %d, firstName: %s, lastName: %s, email: %s, phone: %s\n",
104+
id,
105+
firstName,
106+
lastName,
107+
email,
108+
phone,
109+
)
102110
}
103111
}
104112

examples/kafka-go/consumer/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ func reader(ctx context.Context) {
5252
attribute.Int64("partition", int64(m.Partition)),
5353
attribute.Int64("offset", m.Offset),
5454
)
55-
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))
55+
fmt.Printf(
56+
"consumed message at topic:%v partition:%v offset:%v %s = %s\n",
57+
m.Topic,
58+
m.Partition,
59+
m.Offset,
60+
string(m.Key),
61+
string(m.Value),
62+
)
5663
span.End()
5764
}
5865
}

instrumentation.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ type Instrumentation struct {
6666
//
6767
// If conflicting or duplicate options are provided, the last one will have
6868
// precedence and be used.
69-
func NewInstrumentation(ctx context.Context, opts ...InstrumentationOption) (*Instrumentation, error) {
69+
func NewInstrumentation(
70+
ctx context.Context,
71+
opts ...InstrumentationOption,
72+
) (*Instrumentation, error) {
7073
c, err := newInstConfig(ctx, opts)
7174
if err != nil {
7275
return nil, err

instrumentation_test.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,13 @@ func TestWithResourceAttributes(t *testing.T) {
148148
attr2 := semconv.K8SPodName("test_pod_name")
149149
attr3 := semconv.K8SNamespaceName("test_namespace_name")
150150

151-
c, err := newInstConfig(context.Background(), []InstrumentationOption{WithResourceAttributes(attr1, attr2), WithResourceAttributes(attr3)})
151+
c, err := newInstConfig(
152+
context.Background(),
153+
[]InstrumentationOption{
154+
WithResourceAttributes(attr1, attr2),
155+
WithResourceAttributes(attr3),
156+
},
157+
)
152158
require.NoError(t, err)
153159
assert.Equal(t, []attribute.KeyValue{attr1, attr2, attr3}, c.additionalResAttrs)
154160
})
@@ -159,7 +165,15 @@ func TestWithResourceAttributes(t *testing.T) {
159165
attr3 := semconv.K8SNamespaceName("test_namespace_name")
160166

161167
mockEnv(t, map[string]string{
162-
"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()),
168+
"OTEL_RESOURCE_ATTRIBUTES": fmt.Sprintf(
169+
"%s=%s,%s=%s,%s=%s",
170+
nameAttr.Key,
171+
nameAttr.Value.AsString(),
172+
attr2.Key,
173+
attr2.Value.AsString(),
174+
attr3.Key,
175+
attr3.Value.AsString(),
176+
),
163177
})
164178

165179
c, err := newInstConfig(context.Background(), []InstrumentationOption{WithEnv()})
@@ -174,11 +188,20 @@ func TestWithResourceAttributes(t *testing.T) {
174188
attr3 := semconv.K8SNamespaceName("test_namespace_name")
175189

176190
mockEnv(t, map[string]string{
177-
"OTEL_RESOURCE_ATTRIBUTES": fmt.Sprintf("%s=%s,%s=%s", nameAttr.Key, nameAttr.Value.AsString(), attr2.Key, attr2.Value.AsString()),
191+
"OTEL_RESOURCE_ATTRIBUTES": fmt.Sprintf(
192+
"%s=%s,%s=%s",
193+
nameAttr.Key,
194+
nameAttr.Value.AsString(),
195+
attr2.Key,
196+
attr2.Value.AsString(),
197+
),
178198
})
179199

180200
// Use WithResourceAttributes to config the additional resource attributes
181-
c, err := newInstConfig(context.Background(), []InstrumentationOption{WithEnv(), WithResourceAttributes(attr3)})
201+
c, err := newInstConfig(
202+
context.Background(),
203+
[]InstrumentationOption{WithEnv(), WithResourceAttributes(attr3)},
204+
)
182205
require.NoError(t, err)
183206
assert.Equal(t, nameAttr.Value.AsString(), c.serviceName)
184207
assert.Equal(t, []attribute.KeyValue{attr2, attr3}, c.additionalResAttrs)

internal/pkg/instrumentation/bpf/database/sql/probe_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ func TestProbeConvertEvent(t *testing.T) {
8888
SpanContext: context.EBPFSpanContext{TraceID: traceID, SpanID: spanID},
8989
},
9090
// "SELECT * FROM foo"
91-
Query: [256]byte{0x53, 0x45, 0x4c, 0x45, 0x43, 0x54, 0x20, 0x2a, 0x20, 0x46, 0x52, 0x4f, 0x4d, 0x20, 0x66, 0x6f, 0x6f},
91+
Query: [256]byte{
92+
0x53, 0x45, 0x4c, 0x45, 0x43, 0x54, 0x20, 0x2a, 0x20,
93+
0x46, 0x52, 0x4f, 0x4d, 0x20, 0x66, 0x6f, 0x6f,
94+
},
9295
})
9396

9497
want := func() ptrace.SpanSlice {
@@ -101,7 +104,12 @@ func TestProbeConvertEvent(t *testing.T) {
101104
span.SetTraceID(pcommon.TraceID(traceID))
102105
span.SetSpanID(pcommon.SpanID(spanID))
103106
span.SetFlags(uint32(trace.FlagsSampled))
104-
utils.Attributes(span.Attributes(), semconv.DBQueryText("SELECT * FROM foo"), semconv.DBOperationName("SELECT"), semconv.DBCollectionName("foo"))
107+
utils.Attributes(
108+
span.Attributes(),
109+
semconv.DBQueryText("SELECT * FROM foo"),
110+
semconv.DBOperationName("SELECT"),
111+
semconv.DBCollectionName("foo"),
112+
)
105113
return spans
106114
}()
107115
assert.Equal(t, want, got)

internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/consumer/probe.go

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,66 @@ func New(logger *slog.Logger, version string) probe.Probe {
4242
probe.AllocationConst{},
4343
probe.StructFieldConst{
4444
Key: "message_headers_pos",
45-
ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Headers"),
45+
ID: structfield.NewID(
46+
"github.com/segmentio/kafka-go",
47+
"github.com/segmentio/kafka-go",
48+
"Message",
49+
"Headers",
50+
),
4651
},
4752
probe.StructFieldConst{
4853
Key: "message_key_pos",
49-
ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Key"),
54+
ID: structfield.NewID(
55+
"github.com/segmentio/kafka-go",
56+
"github.com/segmentio/kafka-go",
57+
"Message",
58+
"Key",
59+
),
5060
},
5161
probe.StructFieldConst{
5262
Key: "message_topic_pos",
53-
ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Topic"),
63+
ID: structfield.NewID(
64+
"github.com/segmentio/kafka-go",
65+
"github.com/segmentio/kafka-go",
66+
"Message",
67+
"Topic",
68+
),
5469
},
5570
probe.StructFieldConst{
5671
Key: "message_partition_pos",
57-
ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Partition"),
72+
ID: structfield.NewID(
73+
"github.com/segmentio/kafka-go",
74+
"github.com/segmentio/kafka-go",
75+
"Message",
76+
"Partition",
77+
),
5878
},
5979
probe.StructFieldConst{
6080
Key: "message_offset_pos",
61-
ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Offset"),
81+
ID: structfield.NewID(
82+
"github.com/segmentio/kafka-go",
83+
"github.com/segmentio/kafka-go",
84+
"Message",
85+
"Offset",
86+
),
6287
},
6388
probe.StructFieldConst{
6489
Key: "reader_config_pos",
65-
ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Reader", "config"),
90+
ID: structfield.NewID(
91+
"github.com/segmentio/kafka-go",
92+
"github.com/segmentio/kafka-go",
93+
"Reader",
94+
"config",
95+
),
6696
},
6797
probe.StructFieldConst{
6898
Key: "reader_config_group_id_pos",
69-
ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "ReaderConfig", "GroupID"),
99+
ID: structfield.NewID(
100+
"github.com/segmentio/kafka-go",
101+
"github.com/segmentio/kafka-go",
102+
"ReaderConfig",
103+
"GroupID",
104+
),
70105
},
71106
},
72107
Uprobes: []*probe.Uprobe{

internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/consumer/probe_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ func TestProbeConvertEvent(t *testing.T) {
3939
// key1
4040
Key: [256]byte{0x6b, 0x65, 0x79, 0x31},
4141
// test consumer group
42-
ConsumerGroup: [128]byte{0x74, 0x65, 0x73, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70},
43-
Offset: 42,
44-
Partition: 12,
42+
ConsumerGroup: [128]byte{
43+
0x74, 0x65, 0x73, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x75,
44+
0x6d, 0x65, 0x72, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70,
45+
},
46+
Offset: 42,
47+
Partition: 12,
4548
})
4649

4750
want := func() ptrace.SpanSlice {

internal/pkg/instrumentation/bpf/github.com/segmentio/kafka-go/producer/probe.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,39 @@ func New(logger *slog.Logger, version string) probe.Probe {
4343
probe.AllocationConst{},
4444
probe.StructFieldConst{
4545
Key: "writer_topic_pos",
46-
ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Writer", "Topic"),
46+
ID: structfield.NewID(
47+
"github.com/segmentio/kafka-go",
48+
"github.com/segmentio/kafka-go",
49+
"Writer",
50+
"Topic",
51+
),
4752
},
4853
probe.StructFieldConst{
4954
Key: "message_headers_pos",
50-
ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Headers"),
55+
ID: structfield.NewID(
56+
"github.com/segmentio/kafka-go",
57+
"github.com/segmentio/kafka-go",
58+
"Message",
59+
"Headers",
60+
),
5161
},
5262
probe.StructFieldConst{
5363
Key: "message_key_pos",
54-
ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Key"),
64+
ID: structfield.NewID(
65+
"github.com/segmentio/kafka-go",
66+
"github.com/segmentio/kafka-go",
67+
"Message",
68+
"Key",
69+
),
5570
},
5671
probe.StructFieldConst{
5772
Key: "message_time_pos",
58-
ID: structfield.NewID("github.com/segmentio/kafka-go", "github.com/segmentio/kafka-go", "Message", "Time"),
73+
ID: structfield.NewID(
74+
"github.com/segmentio/kafka-go",
75+
"github.com/segmentio/kafka-go",
76+
"Message",
77+
"Time",
78+
),
5979
},
6080
},
6181
Uprobes: []*probe.Uprobe{
@@ -102,7 +122,10 @@ func processFn(e *event) ptrace.SpanSlice {
102122

103123
if e.ValidMessages > 0 {
104124
e.ValidMessages = min(e.ValidMessages, math.MaxInt)
105-
attrs = append(attrs, semconv.MessagingBatchMessageCount(int(e.ValidMessages))) // nolint: gosec // Bounded.
125+
attrs = append(
126+
attrs,
127+
semconv.MessagingBatchMessageCount(int(e.ValidMessages)), // nolint: gosec // Bounded.
128+
)
106129
}
107130

108131
traceID := pcommon.TraceID(e.Messages[0].SpanContext.TraceID)

0 commit comments

Comments
 (0)