Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch SpanEvent times to use time.Time #1101

Merged
merged 4 commits into from
Sep 18, 2024
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
5 changes: 3 additions & 2 deletions internal/pkg/instrumentation/bpf/database/sql/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"go.opentelemetry.io/auto/internal/pkg/instrumentation/context"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/probe"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/utils"
)

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -target amd64,arm64 -cc clang -cflags $CFLAGS bpf ./bpf/probe.bpf.c
Expand Down Expand Up @@ -96,8 +97,8 @@ func convertEvent(e *event) []*probe.SpanEvent {
return []*probe.SpanEvent{
{
SpanName: "DB",
StartTime: int64(e.StartTime),
EndTime: int64(e.EndTime),
StartTime: utils.BootOffsetToTime(e.StartTime),
EndTime: utils.BootOffsetToTime(e.EndTime),
SpanContext: &sc,
Attributes: []attribute.KeyValue{
semconv.DBQueryText(query),
Expand Down
14 changes: 9 additions & 5 deletions internal/pkg/instrumentation/bpf/database/sql/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ import (

"go.opentelemetry.io/auto/internal/pkg/instrumentation/context"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/probe"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/utils"
)

func TestProbeConvertEvent(t *testing.T) {
start := time.Now()
start := time.Unix(0, time.Now().UnixNano()) // No wall clock.
end := start.Add(1 * time.Second)

startOffset := utils.TimeToBootOffset(start)
endOffset := utils.TimeToBootOffset(end)

traceID := trace.TraceID{1}
spanID := trace.SpanID{1}

got := convertEvent(&event{
BaseSpanProperties: context.BaseSpanProperties{
StartTime: uint64(start.UnixNano()),
EndTime: uint64(end.UnixNano()),
StartTime: startOffset,
EndTime: endOffset,
SpanContext: context.EBPFSpanContext{TraceID: traceID, SpanID: spanID},
},
// "SELECT * FROM foo"
Expand All @@ -41,8 +45,8 @@ func TestProbeConvertEvent(t *testing.T) {
})
want := &probe.SpanEvent{
SpanName: "DB",
StartTime: int64(start.UnixNano()),
EndTime: int64(end.UnixNano()),
StartTime: start,
EndTime: end,
SpanContext: &sc,
Attributes: []attribute.KeyValue{
semconv.DBQueryText("SELECT * FROM foo"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"go.opentelemetry.io/auto/internal/pkg/instrumentation/context"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/probe"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/utils"
"go.opentelemetry.io/auto/internal/pkg/structfield"
)

Expand Down Expand Up @@ -122,8 +123,8 @@ func convertEvent(e *event) []*probe.SpanEvent {
return []*probe.SpanEvent{
{
SpanName: kafkaConsumerSpanName(topic),
StartTime: int64(e.StartTime),
EndTime: int64(e.EndTime),
StartTime: utils.BootOffsetToTime(e.StartTime),
EndTime: utils.BootOffsetToTime(e.EndTime),
SpanContext: &sc,
ParentSpanContext: pscPtr,
Attributes: attributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ import (

"go.opentelemetry.io/auto/internal/pkg/instrumentation/context"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/probe"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/utils"
)

func TestProbeConvertEvent(t *testing.T) {
start := time.Now()
start := time.Unix(0, time.Now().UnixNano()) // No wall clock.
end := start.Add(1 * time.Second)

startOffset := utils.TimeToBootOffset(start)
endOffset := utils.TimeToBootOffset(end)

traceID := trace.TraceID{1}
spanID := trace.SpanID{1}

got := convertEvent(&event{
BaseSpanProperties: context.BaseSpanProperties{
StartTime: uint64(start.UnixNano()),
EndTime: uint64(end.UnixNano()),
StartTime: startOffset,
EndTime: endOffset,
SpanContext: context.EBPFSpanContext{TraceID: traceID, SpanID: spanID},
},
// topic1
Expand All @@ -47,8 +51,8 @@ func TestProbeConvertEvent(t *testing.T) {
})
want := &probe.SpanEvent{
SpanName: kafkaConsumerSpanName("topic1"),
StartTime: int64(start.UnixNano()),
EndTime: int64(end.UnixNano()),
StartTime: start,
EndTime: end,
SpanContext: &sc,
Attributes: []attribute.KeyValue{
semconv.MessagingSystemKafka,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"go.opentelemetry.io/auto/internal/pkg/instrumentation/context"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/probe"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/utils"
"go.opentelemetry.io/auto/internal/pkg/structfield"
)

Expand Down Expand Up @@ -138,8 +139,8 @@ func convertEvent(e *event) []*probe.SpanEvent {

res = append(res, &probe.SpanEvent{
SpanName: kafkaProducerSpanName(msgTopic),
StartTime: int64(e.StartTime),
EndTime: int64(e.EndTime),
StartTime: utils.BootOffsetToTime(e.StartTime),
EndTime: utils.BootOffsetToTime(e.EndTime),
SpanContext: &sc,
Attributes: msgAttrs,
ParentSpanContext: pscPtr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ import (

"go.opentelemetry.io/auto/internal/pkg/instrumentation/context"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/probe"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/utils"
)

func TestProbeConvertEvent(t *testing.T) {
start := time.Now()
start := time.Unix(0, time.Now().UnixNano()) // No wall clock.
end := start.Add(1 * time.Second)

startOffset := utils.TimeToBootOffset(start)
endOffset := utils.TimeToBootOffset(end)

traceID := trace.TraceID{1}

got := convertEvent(&event{
StartTime: uint64(start.UnixNano()),
EndTime: uint64(end.UnixNano()),
StartTime: startOffset,
EndTime: endOffset,
Messages: [10]messageAttributes{
{
// topic1
Expand Down Expand Up @@ -63,8 +67,8 @@ func TestProbeConvertEvent(t *testing.T) {
})
want1 := &probe.SpanEvent{
SpanName: kafkaProducerSpanName("topic1"),
StartTime: int64(start.UnixNano()),
EndTime: int64(end.UnixNano()),
StartTime: start,
EndTime: end,
SpanContext: &sc1,
Attributes: []attribute.KeyValue{
semconv.MessagingKafkaMessageKey("key1"),
Expand All @@ -78,8 +82,8 @@ func TestProbeConvertEvent(t *testing.T) {

want2 := &probe.SpanEvent{
SpanName: kafkaProducerSpanName("topic2"),
StartTime: int64(start.UnixNano()),
EndTime: int64(end.UnixNano()),
StartTime: start,
EndTime: end,
SpanContext: &sc2,
Attributes: []attribute.KeyValue{
semconv.MessagingKafkaMessageKey("key2"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"go.opentelemetry.io/auto/internal/pkg/inject"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/probe"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/utils"
"go.opentelemetry.io/auto/internal/pkg/process"
"go.opentelemetry.io/auto/internal/pkg/structfield"

Expand Down Expand Up @@ -207,8 +208,8 @@ func convertEvent(e *event) []*probe.SpanEvent {
return []*probe.SpanEvent{
{
SpanName: spanName,
StartTime: int64(e.StartTime),
EndTime: int64(e.EndTime),
StartTime: utils.BootOffsetToTime(e.StartTime),
EndTime: utils.BootOffsetToTime(e.EndTime),
Attributes: convertAttributes(e.Attributes),
SpanContext: &sc,
ParentSpanContext: pscPtr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ import (

"go.opentelemetry.io/auto/internal/pkg/instrumentation/context"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/probe"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/utils"
)

func TestProbeConvertEvent(t *testing.T) {
start := time.Now()
start := time.Unix(0, time.Now().UnixNano()) // No wall clock.
end := start.Add(1 * time.Second)

startOffset := utils.TimeToBootOffset(start)
endOffset := utils.TimeToBootOffset(end)

traceID := trace.TraceID{1}
spanID := trace.SpanID{1}

Expand All @@ -30,8 +34,8 @@ func TestProbeConvertEvent(t *testing.T) {

got := convertEvent(&event{
BaseSpanProperties: context.BaseSpanProperties{
StartTime: uint64(start.UnixNano()),
EndTime: uint64(end.UnixNano()),
StartTime: startOffset,
EndTime: endOffset,
SpanContext: context.EBPFSpanContext{TraceID: traceID, SpanID: spanID},
},
// span name: "Foo"
Expand Down Expand Up @@ -104,8 +108,8 @@ func TestProbeConvertEvent(t *testing.T) {
})
want := &probe.SpanEvent{
SpanName: "Foo",
StartTime: int64(start.UnixNano()),
EndTime: int64(end.UnixNano()),
StartTime: start,
EndTime: end,
SpanContext: &sc,
Attributes: []attribute.KeyValue{
attribute.Bool("bool_key", true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ func convertEvent(e *event) []*probe.SpanEvent {

event := &probe.SpanEvent{
SpanName: method,
StartTime: int64(e.StartTime),
EndTime: int64(e.EndTime),
StartTime: utils.BootOffsetToTime(e.StartTime),
EndTime: utils.BootOffsetToTime(e.EndTime),
Attributes: attrs,
SpanContext: &sc,
ParentSpanContext: pscPtr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"go.opentelemetry.io/auto/internal/pkg/inject"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/context"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/probe"
"go.opentelemetry.io/auto/internal/pkg/instrumentation/utils"
"go.opentelemetry.io/auto/internal/pkg/process"
"go.opentelemetry.io/auto/internal/pkg/structfield"
)
Expand Down Expand Up @@ -127,8 +128,8 @@ func convertEvent(e *event) []*probe.SpanEvent {
return []*probe.SpanEvent{
{
SpanName: method,
StartTime: int64(e.StartTime),
EndTime: int64(e.EndTime),
StartTime: utils.BootOffsetToTime(e.StartTime),
EndTime: utils.BootOffsetToTime(e.EndTime),
Attributes: []attribute.KeyValue{
semconv.RPCSystemKey.String("grpc"),
semconv.RPCServiceKey.String(method),
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/instrumentation/bpf/net/http/client/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ func convertEvent(e *event) []*probe.SpanEvent {

spanEvent := &probe.SpanEvent{
SpanName: method,
StartTime: int64(e.StartTime),
EndTime: int64(e.EndTime),
StartTime: utils.BootOffsetToTime(e.StartTime),
EndTime: utils.BootOffsetToTime(e.EndTime),
SpanContext: &sc,
Attributes: attrs,
ParentSpanContext: pscPtr,
Expand Down
Loading
Loading