diff --git a/tools/go-agent/instrument/plugins/instrument.go b/tools/go-agent/instrument/plugins/instrument.go index bb82f658..f0024a2a 100644 --- a/tools/go-agent/instrument/plugins/instrument.go +++ b/tools/go-agent/instrument/plugins/instrument.go @@ -50,10 +50,6 @@ import ( //go:embed templates var templatesFS embed.FS -var ( - errNoVersionFound = errors.New("no version found in the path of the source file") -) - type Instrument struct { realInst instrument.Instrument methodFilters []*instrument.Point @@ -110,7 +106,7 @@ func (i *Instrument) CouldHandle(opts *api.CompileOptions) bool { } // check the version of the framework could handler version, err := i.tryToFindThePluginVersion(opts, ins) - if err != nil && !errors.Is(err, errNoVersionFound) { + if err != nil { logrus.Warnf("ignore the plugin %s, because %s", ins.Name(), err) continue } @@ -566,7 +562,10 @@ func (i *Instrument) tryToFindThePluginVersion(opts *api.CompileOptions, ins ins // arg example: github.com/!shopify/sarama@1.34.1/acl.go _, afterPkg, found := strings.Cut(arg, escapedBasePkg) if !found { - return "", errors.Wrapf(errNoVersionFound, "package %s, go file path: %s", basePkg, arg) + // This could happen if the module is replaced by a local one + // For example, in the E2E + logrus.Warnf("could not found the go version of the package %s, go file path: %s", basePkg, arg) + return "", nil } if !strings.HasPrefix(afterPkg, "@") { diff --git a/tools/go-agent/instrument/plugins/instrument_test.go b/tools/go-agent/instrument/plugins/instrument_test.go index 0b26894c..57f56310 100644 --- a/tools/go-agent/instrument/plugins/instrument_test.go +++ b/tools/go-agent/instrument/plugins/instrument_test.go @@ -21,6 +21,8 @@ import ( "embed" "testing" + "github.com/stretchr/testify/require" + "github.com/apache/skywalking-go/plugins/core/instrument" "github.com/apache/skywalking-go/tools/go-agent/instrument/api" ) @@ -52,12 +54,35 @@ func TestInstrument_tryToFindThePluginVersion(t *testing.T) { NewTestInstrument("github.com/Shopify/sarama"), "1.34.1", }, + { + "plugin for go stdlib", + &api.CompileOptions{ + AllArgs: []string{ + "/opt/homebrew/Cellar/go/1.21.4/libexec/src/runtime/metrics/sample.go", + }, + }, + NewTestInstrument("runtime/metrics"), + "", + }, + { + "plugin for replaced module", + &api.CompileOptions{ + AllArgs: []string{ + "/home/user/skywalking-go/toolkit/trace/api.go", + }, + }, + NewTestInstrument("github.com/apache/skywalking-go/toolkit"), + "", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { i := &Instrument{} - got, _ := i.tryToFindThePluginVersion(tt.opts, tt.ins) + got, err := i.tryToFindThePluginVersion(tt.opts, tt.ins) + if err != nil { + require.NoError(t, err) + } if got != tt.want { t.Errorf("tryToFindThePluginVersion() got = %v, want %v", got, tt.want) }