Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ formatters:
enable:
- gofumpt
- goimports
- golines
settings:
goimports:
local-prefixes:
Expand Down
7 changes: 6 additions & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
10 changes: 9 additions & 1 deletion examples/httpPlusdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}

Expand Down
9 changes: 8 additions & 1 deletion examples/kafka-go/consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
5 changes: 4 additions & 1 deletion instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 27 additions & 4 deletions instrumentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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()})
Expand All @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions internal/pkg/instrumentation/bpf/database/sql/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading
Loading