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 semantics for process.executable.name #306

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
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
}
20 changes: 19 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,30 @@ 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 {
return r == '.'
}) {
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
Loading