Skip to content

Commit

Permalink
Make sure we ignore invalid spans (#761)
Browse files Browse the repository at this point in the history
* make sure we ignore invalid spans

* update grpc bpfs
  • Loading branch information
grcevski authored Apr 19, 2024
1 parent 4f9d076 commit 94aae99
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bpf/go_grpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ int uprobe_server_handleStream_return(struct pt_regs *ctx) {
trace->type = EVENT_GRPC_REQUEST;
trace->start_monotime_ns = invocation->start_monotime_ns;
trace->status = *status;
trace->content_length = 0;
trace->method[0] = 0;

goroutine_metadata *g_metadata = bpf_map_lookup_elem(&ongoing_goroutines, &goroutine_addr);
if (g_metadata) {
Expand Down Expand Up @@ -374,7 +376,9 @@ int uprobe_ClientConn_Invoke_return(struct pt_regs *ctx) {
trace->start_monotime_ns = invocation->start_monotime_ns;
trace->go_start_monotime_ns = invocation->start_monotime_ns;
trace->end_monotime_ns = bpf_ktime_get_ns();

trace->content_length = 0;
trace->method[0] = 0;

// Read arguments from the original set of registers

// Get client request value pointers
Expand Down
4 changes: 4 additions & 0 deletions pkg/internal/ebpf/common/ringbuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ func (rbf *ringBufForwarder) processAndForward(record ringbuf.Record, spansChan
if ignore {
return
}
if !s.IsValid() {
rbf.logger.Debug("invalid span", "span", s)
return
}
rbf.spans[rbf.spansLen] = s
// we need to decorate each span with the tracer's service name
// if this information is not forwarded from eBPF
Expand Down
Binary file modified pkg/internal/ebpf/grpc/bpf_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_debug_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_debug_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_tp_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_tp_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_tp_debug_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_tp_debug_bpfel_x86.o
Binary file not shown.
14 changes: 14 additions & 0 deletions pkg/internal/request/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package request

import (
"time"
"unicode/utf8"

"github.com/gavv/monotime"
trace2 "go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -94,3 +95,16 @@ func (s *Span) Timings() Timings {
End: now.Add(-endDelta),
}
}

func (s *Span) IsValid() bool {
if (len(s.Method) > 0 && !utf8.ValidString(s.Method)) ||
(len(s.Path) > 0 && !utf8.ValidString(s.Path)) {
return false
}

if s.End < s.Start {
return false
}

return true
}

0 comments on commit 94aae99

Please sign in to comment.