diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fdedf0f0b..05d28b89a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,10 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http - Cache offsets for Go `1.26.0`. ([#3365](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/3365)) - Cache offsets for Go `1.26.1`. ([#3365](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/3365)) +### Fixed + +- Parse Go versions that include `GOEXPERIMENT` suffixes such as `-X:boringcrypto`. ([#3390](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/3390)) + ### Removed - Build support for [Go 1.23] has been removed. diff --git a/internal/pkg/process/info.go b/internal/pkg/process/info.go index c1fb64be02..0264b1fbed 100644 --- a/internal/pkg/process/info.go +++ b/internal/pkg/process/info.go @@ -108,16 +108,24 @@ func goVer(raw string) (*semver.Version, error) { return goDevVer(raw) } raw = strings.TrimPrefix(raw, "go") + raw = stripGoExperimentSuffix(raw) - // Handle local modified versions of Go. - raw = strings.TrimSuffix(raw, "+") + return semver.NewVersion(raw) +} - // Trims GOEXPERIMENT version suffix if present. +func stripGoExperimentSuffix(raw string) string { + // Trim GOEXPERIMENT suffixes used in Go version strings. + // Historically this appeared as " X:...", and newer toolchains can emit + // it as "-X:..." (for example, "go1.26.0-X:boringcrypto"). if idx := strings.Index(raw, " X:"); idx > 0 { raw = raw[:idx] } + if idx := strings.Index(raw, "-X:"); idx > 0 { + raw = raw[:idx] + } - return semver.NewVersion(raw) + // Handle local modified versions of Go. + return strings.TrimSuffix(raw, "+") } var devVerRE = regexp.MustCompile(`devel \+([a-f0-9]+) `) diff --git a/internal/pkg/process/info_test.go b/internal/pkg/process/info_test.go index ca4e0f5ac7..14e9d37da3 100644 --- a/internal/pkg/process/info_test.go +++ b/internal/pkg/process/info_test.go @@ -30,6 +30,10 @@ func TestGoVer(t *testing.T) { in: "go1.20.1 X:nocoverageredesign", want: semver.MustParse("1.20.1"), }, + { + in: "go1.26.0-X:boringcrypto", + want: semver.MustParse("1.26.0"), + }, { in: "go1.18+", want: semver.MustParse("1.18"), diff --git a/internal/tools/inspect/app.go b/internal/tools/inspect/app.go index 450f1db626..a3aeab5de4 100644 --- a/internal/tools/inspect/app.go +++ b/internal/tools/inspect/app.go @@ -85,7 +85,7 @@ func newApp(ctx context.Context, l *slog.Logger, j job) (*app, error) { return a, nil } -// GetOffset returnst the struct field offset for sf. It uses the DWARF data +// GetOffset returns the struct field offset for sf. It uses the DWARF data // of the app's built binary to find this value. func (a *app) GetOffset(id structfield.ID) (uint64, bool) { a.log.Debug("analyzing binary...", "id", id, "binary", a.exec)