zJiaJun opened a new pull request, #216: URL: https://github.com/apache/skywalking-go/pull/216
Fixes #13188 **Problem:** The runtime instrumentation logic in `tools/go-agent/instrument/runtime/instrument.go` incorrectly checked for a hardcoded number of parameters (3) for the internal `runtime.newproc1` function. This check failed for Go versions 1.23 and later, where the relevant function signature expects 2 parameters for the instrumentation purpose. Consequently, the agent skipped the injection of the necessary code for automatic context propagation when new goroutines were created using `newproc1`, breaking automatic tracing in Go 1.23+ environments. **Solution:** This patch addresses the issue by implementing dynamic parameter count checking based on the Go version specified during compilation via the `-lang` flag: 1. **Introduced Robust Version Checking:** Added a new method `CheckGoVersionGreaterOrEqual(major, minor int) bool` to the `api.CompileOptions` struct in `tools/go-agent/instrument/api/flags.go`. This method reliably parses the `-lang` flag value (e.g., "go1.22", "go1.23", "go2.0") to accurately determine the Go version and compare it against required major and minor versions. 2. **Dynamic Parameter Check in Runtime Instrument:** Modified the `FilterAndEdit` method within `runtime.Instrument` (`tools/go-agent/instrument/runtime/instrument.go`). It now utilizes the new `opts.CheckGoVersionGreaterOrEqual(1, 23)` method to determine the `expectedParamCount` for `newproc1` (3 if Go version < 1.23, 2 if Go version >= 1.23). The instrumentation logic for `newproc1` now only proceeds if the detected parameter count matches the expected count for the target Go version. **Impact:** With this fix, the skywalking-go agent can now correctly identify and instrument the `runtime.newproc1` function on Go 1.23 and later versions, in addition to older versions. This ensures that the automatic context propagation mechanism functions as expected for goroutines created via the standard `go` keyword across all supported Go versions specified by the `-lang` flag during the build process. **Files Changed:** * `tools/go-agent/instrument/api/flags.go` * `tools/go-agent/instrument/runtime/instrument.go` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@skywalking.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org