Skip to content

Commit

Permalink
Use debug modules to parse Go version and modules (#653)
Browse files Browse the repository at this point in the history
* Refactor version/module parsing

* Remove unused version/module parsing code
  • Loading branch information
damemi authored Feb 9, 2024
1 parent 2ac2845 commit 5178a69
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 217 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http

- Don't call `manager.Close()` when `Analyze()` fails. ([#638](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/638))
- Close `proc` file when done discovering PID. ([#649](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/649))
- Use `debug` packages to parse Go and modules' versions. ([#653](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/653))

## [v0.10.1-alpha] - 2024-01-10

Expand Down
22 changes: 17 additions & 5 deletions internal/pkg/process/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
package process

import (
"debug/buildinfo"
"debug/elf"
"errors"
"fmt"
"os"
"strings"

"github.com/hashicorp/go-version"

Expand Down Expand Up @@ -80,15 +82,25 @@ func (a *Analyzer) Analyze(pid int, relevantFuncs map[string]interface{}) (*Targ
return nil, err
}

goVersion, modules, err := a.getModuleDetails(elfF)
buildInfo, err := buildinfo.Read(f)
if err != nil {
return nil, err
}
goVersion, err := version.NewVersion(strings.ReplaceAll(buildInfo.GoVersion, "go", ""))
if err != nil {
return nil, err
}
result.GoVersion = goVersion

// Include the Go standard library module.
modules["std"] = goVersion
result.Libraries = modules
result.Libraries = make(map[string]*version.Version, len(buildInfo.Deps)+1)
for _, dep := range buildInfo.Deps {
depVersion, err := version.NewVersion(dep.Version)
if err != nil {
a.logger.Error(err, "error parsing module version")
continue
}
result.Libraries[dep.Path] = depVersion
}
result.Libraries["std"] = goVersion

funcs, err := a.findFunctions(elfF, relevantFuncs)
if err != nil {
Expand Down
212 changes: 0 additions & 212 deletions internal/pkg/process/module.go

This file was deleted.

0 comments on commit 5178a69

Please sign in to comment.