opentelemetry-go-contrib
opentelemetry-go-contrib copied to clipboard
Examples built with 'golang:alpine' Docker image no longer work
It seems that instrumentation examples which are based on the golang:alpine
image can no longer be brought up with docker-compose
.
Example from gin-gonic
, which fails with:
Step 5/6 : RUN go install ./example/server.go
---> Running in dbf8d4e69071
go: downloading go.opentelemetry.io/otel v0.18.0
go: downloading github.com/gin-gonic/gin v1.6.3
go: downloading go.opentelemetry.io/otel/trace v0.18.0
go: downloading go.opentelemetry.io/otel/metric v0.18.0
go: downloading github.com/gin-contrib/sse v0.1.0
go: downloading github.com/mattn/go-isatty v0.0.12
go: downloading github.com/go-playground/validator/v10 v10.2.0
go: downloading github.com/golang/protobuf v1.3.3
go: downloading github.com/ugorji/go v1.1.7
go: downloading gopkg.in/yaml.v2 v2.2.8
go: downloading golang.org/x/sys v0.0.0-20200116001909-b77594299b42go: downloading github.com/ugorji/go/codec v1.1.7
go: downloading github.com/leodido/go-urn v1.2.0
go: downloading github.com/go-playground/universal-translator v0.17.0
go: downloading github.com/go-playground/locales v0.13.0
example/server.go:27:2: no required module provides package go.opentelemetry.io/otel/exporters/stdout; to add it:
go get go.opentelemetry.io/otel/exporters/stdout
example/server.go:29:2: no required module provides package go.opentelemetry.io/otel/sdk/trace; to add it:
go get go.opentelemetry.io/otel/sdk/trace
ERROR: Service 'gin-server' failed to build: The command '/bin/sh -c go install ./example/server.go' returned a non-zero code: 1
Since this behavior is not present in examples built with golang:1.14-alpine
, I presume the issue is related to the fact that the golang:alpine
is now based on Go 1.16, which introduced some changes to module-aware mode for the go install
command.
One possible way to fix this would be to ensure all examples use image version with Go version < 1.16. Otherwise it should be investigated what is the exact cause why Go fails to fetch the mentioned modules and how to mitigate it.
Or maybe rather this might give the right context: https://blog.golang.org/go116-module-changes
In Go 1.16, module-aware commands report an error after discovering a problem in go.mod or go.sum instead of attempting to fix the problem automatically.
It seems like building with Go < 1.16 resolves the issue 'automatically' and fixes go.mod
:
go: finding module for package go.opentelemetry.io/otel/exporters/stdout
go: finding module for package go.opentelemetry.io/otel/sdk/trace
go: found go.opentelemetry.io/otel/exporters/stdout in go.opentelemetry.io/otel/exporters/stdout v0.18.0
go: found go.opentelemetry.io/otel/sdk/trace in go.opentelemetry.io/otel/sdk v0.18.0
Whereas with Go 1.16 we are getting an error by default.
Thanks catching and documenting this!
Otherwise it should be investigated what is the exact cause why Go fails to fetch the mentioned modules and how to mitigate it.
This sounds like the appropriate resolution. That way we ensure other users that use Go 1.16 will not encounter this error as well. This also motivates me to add 1.16 to the versions we validate in our CI system.