aws-otel-collector
aws-otel-collector copied to clipboard
go mod tidy can cause ambiguous import error
Describe the bug
go 1.17 introduced behavior that can lead to an ambiguous import error
when attempting to run go mod tidy
Steps to reproduce
This occurs when attempting to update OTel dependency versions.
run go mod tidy
What did you expect to see? No errors
What did you see instead?
bryaag@147ddac12c15 lambdacomponents % go mod tidy
github.com/aws-observability/aws-otel-collector/pkg/lambdacomponents imports
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter tested by
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter.test imports
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver imports
github.com/prometheus/prometheus/discovery/install imports
github.com/prometheus/prometheus/discovery/gce imports
golang.org/x/oauth2/google imports
cloud.google.com/go/compute/metadata: ambiguous import: found package cloud.google.com/go/compute/metadata in multiple modules:
cloud.google.com/go v0.99.0 (/Users/bryaag/go/pkg/mod/cloud.google.com/[email protected]/compute/metadata)
cloud.google.com/go/compute v1.1.0 (/Users/bryaag/go/pkg/mod/cloud.google.com/go/[email protected]/metadata)
bryaag@147ddac12c15 lambdacomponents % go mod tidy -e
github.com/aws-observability/aws-otel-collector/pkg/lambdacomponents imports
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter tested by
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter.test imports
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver imports
github.com/prometheus/prometheus/discovery/install imports
github.com/prometheus/prometheus/discovery/gce imports
golang.org/x/oauth2/google imports
cloud.google.com/go/compute/metadata: ambiguous import: found package cloud.google.com/go/compute/metadata in multiple modules:
cloud.google.com/go v0.99.0 (/Users/bryaag/go/pkg/mod/cloud.google.com/[email protected]/compute/metadata)
cloud.google.com/go/compute v1.1.0 (/Users/bryaag/go/pkg/mod/cloud.google.com/go/[email protected]/metadata)
cloud.google.com/go/compute/metadata failed to load from any module,
but go 1.16 would load it from cloud.google.com/go/[email protected]
Environment Upgrading the dependency version.
Additional context
This can be alleviated with running rm go.sum && go mod tidy -go=1.16 && go mod tidy -go=1.17
The upstream collector-contrib repository also faces the same issues and gets around it by adding a make gotidy
command to their makefile.
This is changing upstream, and will hopefully avoid these issues in the future: https://github.com/open-telemetry/opentelemetry-collector/pull/4810.
Will this alleviate the issue downstream also or will we have to follow suit and implement compat
?
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been marked as stall for 30 days with no activity.
Have the same issue while trying to build own collector following this instruction: https://opentelemetry.io/docs/collector/custom-collector/
I'm also facing the same issue. does someone know how to resolve this ?
`Error: failed to update go.mod: exit status 1. Output: "github.com/hpe-hcss/test-opentelemetry-collector-build/src/test-otel-collector imports\n\tgo.opentelemetry.io/collector/exporter/otlpexporter imports\n\tgo.opentelemetry.io/collector/config/configgrpc imports\n\tgo.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc tested by\n\tgo.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc.test imports\n\tgoogle.golang.org/grpc/interop imports\n\tgolang.org/x/oauth2/google imports\n\tcloud.google.com/go/compute/metadata: ambiguous import: found package cloud.google.com/go/compute/metadata in multiple modules:\n\tcloud.google.com/go v0.65.0 (/home/manjuna/go/pkg/mod/cloud.google.com/[email protected]/compute/metadata)\n\tcloud.google.com/go/compute v1.6.1 (/home/manjuna/go/pkg/mod/cloud.google.com/go/[email protected]/metadata)\n"
exit status 1
make: *** [Makefile:50: src/generated-gl-test-otel-collector] Error 1`
@manjunath-batakurki have you found any solution? I just experienced this myself.
I deleted this /home/manjuna/go/pkg/mod/cloud.google.com/go/[email protected]/metadata
and then it worked for me.
I encountered the same problem.
cloud.google.com/go/compute/metadata: ambiguous import: found package cloud.google.com/go/compute/metadata in multiple modules:
cloud.google.com/go v0.97.0 (C:\Users\xxx\go\pkg\mod\cloud.google.com\[email protected]\compute\metadata)
cloud.google.com/go/compute v1.7.0 (C:\Users\xxx\go\pkg\mod\cloud.google.com\go\[email protected]\metadata)
Thank you so much for explaining the problem, i hope this would work
run go clean -modcache
before running go mod tidy -compat=1.18
Just so that no one has to sort through the PR. This replace statement was added to the offending go.mod
file which alleviates the error for now.
replace cloud.google.com/go => cloud.google.com/go v0.100.2
@bryan-aguilar thank you! this fixed the error for me
This helped for me: https://stackoverflow.com/a/74689094/633961
Try
go get cloud.google.com/go/compute/metadata
and thengo mod tidy