From 227cdf3ccdca776985aa0e402253f5c09b49f9d6 Mon Sep 17 00:00:00 2001 From: Christos Kalkanis Date: Tue, 14 Jan 2025 16:29:19 -0500 Subject: [PATCH] Switch semantics for process.executable.name Is now the base executable name, instead of process name. --- libpf/generics.go | 10 ++++++++++ reporter/internal/pdata/generate.go | 24 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/libpf/generics.go b/libpf/generics.go index 6a57009d..bbbf0692 100644 --- a/libpf/generics.go +++ b/libpf/generics.go @@ -74,3 +74,13 @@ func MapSlice[T, V any](in []T, mapf func(T) V) []V { } return ret } + +// Every returns true if test is true for every element in slice +func Every[T any](in []T, test func(T) bool) bool { + for _, v := range in { + if !test(v) { + return false + } + } + return true +} diff --git a/reporter/internal/pdata/generate.go b/reporter/internal/pdata/generate.go index 15e47c4b..e5a19416 100644 --- a/reporter/internal/pdata/generate.go +++ b/reporter/internal/pdata/generate.go @@ -5,7 +5,9 @@ package pdata // import "go.opentelemetry.io/ebpf-profiler/reporter/internal/pda import ( "crypto/rand" + "path/filepath" "slices" + "strings" "time" log "github.com/sirupsen/logrus" @@ -173,14 +175,34 @@ func (p *Pdata) setProfile( } } + exeName := traceKey.ExecutablePath + if exeName != "" { + // Remove separator characters which filepath.Base may produce + exeName = strings.Trim(filepath.Base(exeName), + ""+string(filepath.Separator)) + // Strip '.' if it's the only rune in the string + if libpf.Every([]rune(exeName), + func(r rune) bool { + if r == '.' { + return true + } + return false + }) { + exeName = "" + } + } + attrMgr.AppendOptionalString(sample.AttributeIndices(), semconv.ContainerIDKey, traceKey.ContainerID) attrMgr.AppendOptionalString(sample.AttributeIndices(), semconv.ThreadNameKey, traceKey.Comm) + + // TODO: Add traceKey.ProcessName via process.name key attrMgr.AppendOptionalString(sample.AttributeIndices(), - semconv.ProcessExecutableNameKey, traceKey.ProcessName) + semconv.ProcessExecutableNameKey, exeName) attrMgr.AppendOptionalString(sample.AttributeIndices(), semconv.ProcessExecutablePathKey, traceKey.ExecutablePath) + attrMgr.AppendOptionalString(sample.AttributeIndices(), semconv.ServiceNameKey, traceKey.ApmServiceName) attrMgr.AppendInt(sample.AttributeIndices(),