diff --git a/pkg/internal/discover/typer.go b/pkg/internal/discover/typer.go index 11b87740e..91b9c2ccc 100644 --- a/pkg/internal/discover/typer.go +++ b/pkg/internal/discover/typer.go @@ -150,7 +150,7 @@ func (t *typer) asInstrumentable(execElf *exec.FileInfo) Instrumentable { parent, ok = t.currentPids[parent.Ppid] } - detectedType := exec.FindProcLanguage(execElf.Pid, execElf.ELF) + detectedType := exec.FindProcLanguage(execElf.Pid, execElf.ELF, execElf.CmdExePath) log.Debug("instrumented", "comm", execElf.CmdExePath, "pid", execElf.Pid, "child", child, "language", detectedType.String()) diff --git a/pkg/internal/ebpf/common/pids.go b/pkg/internal/ebpf/common/pids.go index 941fca896..fbc76dae5 100644 --- a/pkg/internal/ebpf/common/pids.go +++ b/pkg/internal/ebpf/common/pids.go @@ -213,7 +213,7 @@ func serviceInfo(pid uint32) svc.ID { } name := commName(pid) - lang := exec.FindProcLanguage(int32(pid), nil) + lang := exec.FindProcLanguage(int32(pid), nil, name) result := svc.ID{Name: name, SDKLanguage: lang, ProcPID: int32(pid)} activePids.Add(pid, result) diff --git a/pkg/internal/exec/proclang.go b/pkg/internal/exec/proclang.go index 368e34f22..e8ce7c5ce 100644 --- a/pkg/internal/exec/proclang.go +++ b/pkg/internal/exec/proclang.go @@ -47,3 +47,10 @@ func instrumentableFromSymbolName(symbol string) svc.InstrumentableType { return svc.InstrumentableGeneric } + +func instrumentableFromPath(path string) svc.InstrumentableType { + if strings.Contains(path, "php") { + return svc.InstrumentablePHP + } + return svc.InstrumentableGeneric +} diff --git a/pkg/internal/exec/proclang_linux.go b/pkg/internal/exec/proclang_linux.go index 0b4f5bf72..f1a4a37a1 100644 --- a/pkg/internal/exec/proclang_linux.go +++ b/pkg/internal/exec/proclang_linux.go @@ -9,7 +9,7 @@ import ( "github.com/grafana/beyla/pkg/internal/svc" ) -func FindProcLanguage(pid int32, elfF *elf.File) svc.InstrumentableType { +func FindProcLanguage(pid int32, elfF *elf.File, path string) svc.InstrumentableType { maps, err := FindLibMaps(pid) if err != nil { @@ -37,6 +37,11 @@ func FindProcLanguage(pid int32, elfF *elf.File) svc.InstrumentableType { return t } + t = instrumentableFromPath(path) + if t != svc.InstrumentableGeneric { + return t + } + bytes, err := os.ReadFile(fmt.Sprintf("/proc/%d/environ", pid)) if err != nil { return svc.InstrumentableGeneric diff --git a/pkg/internal/exec/proclang_test.go b/pkg/internal/exec/proclang_test.go index 57dbdb27c..c115150bd 100644 --- a/pkg/internal/exec/proclang_test.go +++ b/pkg/internal/exec/proclang_test.go @@ -40,9 +40,15 @@ func TestSymbolDetection(t *testing.T) { assert.Equal(t, svc.InstrumentableGeneric, instrumentableFromSymbolName("graal")) assert.Equal(t, svc.InstrumentableGeneric, instrumentableFromSymbolName("rust")) } + func TestEnvironDetection(t *testing.T) { assert.Equal(t, svc.InstrumentableDotnet, instrumentableFromEnviron("ASPNETCORE_HTTP_PORTS=8080")) assert.Equal(t, svc.InstrumentableDotnet, instrumentableFromEnviron("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true")) assert.Equal(t, svc.InstrumentableGeneric, instrumentableFromEnviron("SOME_ENV_VAR=123")) assert.Equal(t, svc.InstrumentableGeneric, instrumentableFromEnviron("DOT=1")) } + +func TestPathDetection(t *testing.T) { + assert.Equal(t, svc.InstrumentablePHP, instrumentableFromPath("php")) + assert.Equal(t, svc.InstrumentableGeneric, instrumentableFromPath("python")) +} diff --git a/pkg/internal/svc/svc.go b/pkg/internal/svc/svc.go index 1b97c2e0e..ea9813d86 100644 --- a/pkg/internal/svc/svc.go +++ b/pkg/internal/svc/svc.go @@ -1,7 +1,7 @@ package svc import ( - semconv "go.opentelemetry.io/otel/semconv/v1.19.0" + semconv "go.opentelemetry.io/otel/semconv/v1.25.0" attr "github.com/grafana/beyla/pkg/internal/export/attributes/names" ) @@ -17,6 +17,7 @@ const ( InstrumentableNodejs InstrumentableRust InstrumentableGeneric + InstrumentablePHP ) func (it InstrumentableType) String() string { @@ -34,7 +35,9 @@ func (it InstrumentableType) String() string { case InstrumentableNodejs: return semconv.TelemetrySDKLanguageNodejs.Value.AsString() case InstrumentableRust: - return "rust" + return semconv.TelemetrySDKLanguageRust.Value.AsString() + case InstrumentablePHP: + return semconv.TelemetrySDKLanguagePHP.Value.AsString() case InstrumentableGeneric: return "generic" default: