Open pellared opened 1 year ago
I found a hacky workaround
That isn't a “hacky workaround”. It's how you fix an ambiguous import.
However,
go mod tidy
correctly clears thegithub.com/ugorji/go v1.2.9 // indirect
entry fromgo.mod
and the issue is back again
That sounds like a bug that was supposed to have been fixed in https://go.dev/cl/344572. I'll investigate.
Here is the path leading to the dependency that causes the ambiguous import:
~/src/go.opentelemetry.io/contrib$ go mod graph | grep ' github.com/ugorji/go@'
github.com/ledisdb/ledisdb@v0.0.0-20200510135210-d35789ec47e6 github.com/ugorji/go@v0.0.0-20171122102828-84cb69a8af83
~/src/go.opentelemetry.io/contrib$ go mod graph | grep ' github.com/ledisdb'
github.com/astaxie/beego@v1.12.3 github.com/ledisdb/ledisdb@v0.0.0-20200510135210-d35789ec47e6
~/src/go.opentelemetry.io/contrib$ go mod graph | grep ' github.com/astaxie/beego@'
go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego github.com/astaxie/beego@v1.12.3
go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego/example github.com/astaxie/beego@v1.12.3
go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego/test github.com/astaxie/beego@v1.12.3
go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego@v0.41.1 github.com/astaxie/beego@v1.12.3
go mod tidy
in the module go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego
does not preserve any requirement for package github.com/ugorji/go/codec
because that module doesn't use it. (There is no ambiguous import there because the package isn't imported in that module at all.)
go mod tidy
in the module go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgen
also doesn't preserve a requirement on github.com/ugorji/go v1.2.9
, because lazy module loading always resolves the ambiguity in favor of the module explicitly listed in the go.mod
file. (The package is imported, but lazy module loading makes it unambiguous.)
So the root of the bug here seems to be that lazy module loading does not take effect in workspace mode, and the interaction between lazy module loading, workspace mode, and go mod tidy
is such that you can't fix the problem by adding a requirement in any one module.
(CC @matloob)
I'll see what I can do about supporting lazy module loading in workspace mode, but in the interim there is a workaround. When we load the module graph for a workspace, we also apply the exclude
directives from each of the modules in the workspace.
So you can run go mod edit -exclude=github.com/ugorji/go@v0.0.0-20171122102828-84cb69a8af83
in one or more of the modules in the workspace, and that will prune out the problematic dependency for the whole workspace. (I suggest the otelbeego
modules because they are the ones that introduce the node into the module graph in the first place, but you could also put it in otelgin
because that's the module that really needs to have it pruned out.)
~/src/go.opentelemetry.io/contrib$ git diff
diff --git i/instrumentation/github.com/astaxie/beego/otelbeego/example/go.mod w/instrumentation/github.com/astaxie/beego/otelbeego/example/go.mod
index bb0b98e2..b13cdfa2 100644
--- i/instrumentation/github.com/astaxie/beego/otelbeego/example/go.mod
+++ w/instrumentation/github.com/astaxie/beego/otelbeego/example/go.mod
@@ -40,3 +40,5 @@ require (
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
+
+exclude github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83
diff --git i/instrumentation/github.com/astaxie/beego/otelbeego/go.mod w/instrumentation/github.com/astaxie/beego/otelbeego/go.mod
index b53b2900..a88c751a 100644
--- i/instrumentation/github.com/astaxie/beego/otelbeego/go.mod
+++ w/instrumentation/github.com/astaxie/beego/otelbeego/go.mod
@@ -38,3 +38,5 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
+
+exclude github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83
diff --git i/instrumentation/github.com/astaxie/beego/otelbeego/test/go.mod w/instrumentation/github.com/astaxie/beego/otelbeego/test/go.mod
index 5204c090..46adf681 100644
--- i/instrumentation/github.com/astaxie/beego/otelbeego/test/go.mod
+++ w/instrumentation/github.com/astaxie/beego/otelbeego/test/go.mod
@@ -45,3 +45,5 @@ replace (
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp => ../../../../../net/http/otelhttp
go.opentelemetry.io/contrib/propagators/b3 => ../../../../../../propagators/b3
)
+
+exclude github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83
~/src/go.opentelemetry.io/contrib$ go test -c -o /dev/null go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin/...
? go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin/example [no test files]
@bcmills Thanks a lot for quick feedback, great explanation and even workaround ❤️
What version of Go are you using (
go version
)?Also tested on the latest:
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I added
go.work
and it looks like it caused thego build
tooling to differently handle dependency versions. Reference: https://github.com/open-telemetry/opentelemetry-go-contrib/pull/3805You can checkout this repository https://github.com/pellared/opentelemetry-go-contrib/tree/5a8a020149031cf531deada3c13e83d79c39ed3a and run:
go test ./instrumentation/github.com/gin-gonic/gin/otelgin/...
to reproduce the bug.What did you expect to see?
Build and tests are passing.
Using
go.work
does not affect the buildWhat did you see instead?
I tried even to clear Go modules cache hoping that it will fix the issue. However, for some reason it keeps downloading
github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83
even thoughgithub.com/ugorji/go/codec v1.2.9
is ingo.mod
:I found a hacky workaround:
However,
go mod tidy
correctly clears thegithub.com/ugorji/go v1.2.9 // indirect
entry fromgo.mod
and the issue is back again:I find this issue frightening. I am not sure if I can confidently use Go workspaces in monorepos.