Skip to content

Commit

Permalink
Switch semantics for process.executable.name
Browse files Browse the repository at this point in the history
Is now the base executable name, instead of process name.
  • Loading branch information
christos68k committed Jan 14, 2025
1 parent fae9351 commit 227cdf3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 0 deletions libpf/generics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 23 additions & 1 deletion reporter/internal/pdata/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 == '.' {

Check failure on line 186 in reporter/internal/pdata/generate.go

View workflow job for this annotation

GitHub Actions / Lint (amd64)

S1008: should use 'return r == '.'' instead of 'if r == '.' { return true }; return false' (gosimple)
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(),
Expand Down

0 comments on commit 227cdf3

Please sign in to comment.