opentelemetry-collector icon indicating copy to clipboard operation
opentelemetry-collector copied to clipboard

Ambiguous import error with opentelemetry collector builder

Open zdelagrange opened this issue 1 year ago • 9 comments
trafficstars

Describe the bug cross posting from here: https://github.com/open-telemetry/opentelemetry.io/issues/4738

After following the instructions up to Running and debugging the receiver I get unexpected output

../go/pkg/mod/google.golang.org/[email protected]/status/status.go:35:2: ambiguous import: found package google.golang.org/genproto/googleapis/rpc/status in multiple modules:
	google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 (/home/hanyang/go/pkg/mod/google.golang.org/[email protected]/googleapis/rpc/status)
	google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 (/home/hanyang/go/pkg/mod/google.golang.org/genproto/googleapis/[email protected]/status)
../go/pkg/mod/go.opentelemetry.io/collector/exporter/[email protected]/otlp.go:13:2: ambiguous import: found package google.golang.org/genproto/googleapis/rpc/errdetails in multiple modules:
	google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 (/home/hanyang/go/pkg/mod/google.golang.org/[email protected]/googleapis/rpc/errdetails)
	google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 (/home/hanyang/go/pkg/mod/google.golang.org/genproto/googleapis/[email protected]/errdetails)
../go/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/[email protected]/runtime/handler.go:12:2: ambiguous import: found package google.golang.org/genproto/googleapis/api/httpbody in multiple modules:
	google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 (/home/hanyang/go/pkg/mod/google.golang.org/[email protected]/googleapis/api/httpbody)
	google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 (/home/hanyang/go/pkg/mod/google.golang.org/genproto/googleapis/[email protected]/httpbody)
when running the  go run ./otelcol-dev --config config.yaml from the instructions

Steps to reproduce Builder conf:

  name: otelcol-deb
  description: otel collector distribution for tenable
  output_path: ./otelcol-dev
  otelcol_version: 0.103.0

exporters:
  - gomod:
      go.opentelemetry.io/collector/exporter/debugexporter v0.103.0
  - gomod:
      go.opentelemetry.io/collector/exporter/otlpexporter v0.103.0
processors:
  - gomod:
      go.opentelemetry.io/collector/processor/batchprocessor v0.103.0
receivers:
  - gomod:
      go.opentelemetry.io/collector/receiver/otlpreceiver v0.103.0```

**What did you expect to see?**
a clean build

**What did you see instead?**
ambiguous import error

**What version did you use?**
0.103.0

**What config did you use?**
<!-- Config: (e.g. the yaml config file) -->

**Environment**
macos with asdf golang install

**Additional context**
<!-- Add any other context about the problem here. -->

zdelagrange avatar Jun 27 '24 22:06 zdelagrange

I am unable to reproduce with OCB v0.106.0 and the following manifest:

name: otelcol-deb
description: otel collector distribution for tenable
output_path: ./otelcol-dev
otelcol_version: 0.106.0

exporters:
  - gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.106.0
  - gomod: go.opentelemetry.io/collector/exporter/otlpexporter v0.106.0
processors:
  - gomod: go.opentelemetry.io/collector/processor/batchprocessor v0.106.0
receivers:
  - gomod: go.opentelemetry.io/collector/receiver/otlpreceiver v0.106.0

I get the following logs:

2024-07-30T17:19:04.603+0200	INFO	internal/command.go:125	OpenTelemetry Collector Builder	{"version": "0.106.0", "date": "2024-07-29T19:36:07Z"}
2024-07-30T17:19:04.605+0200	INFO	internal/command.go:161	Using config file	{"path": "manifest.yaml"}
2024-07-30T17:19:04.605+0200	INFO	builder/config.go:142	Using go	{"go-executable": "/home/pablo.baeyens/.gvm/gos/go1.22.4/bin/go"}
2024-07-30T17:19:04.606+0200	INFO	builder/main.go:100	Sources created	{"path": "/tmp/otelcol-distribution2888401949"}
2024-07-30T17:19:04.846+0200	INFO	builder/main.go:191	Getting go modules
2024-07-30T17:19:04.896+0200	INFO	builder/main.go:111	Compiling
2024-07-30T17:19:07.021+0200	INFO	builder/main.go:130	Compiled	{"binary": "/tmp/otelcol-distribution2888401949/otelcol-custom"}

mx-psi avatar Jul 30 '24 15:07 mx-psi

You got same module but different versions, try force the version in go.mod. Something like:

require (
  // you should use the desired version in the error log
  google.golang.org/genproto v0.0.0-20240520151616-dc85e6b867a5
)

If you want to avoid go mod tidy discard your changes, try import any modules of the package, for example type/date:

// This is necessary to avoid ambiguous import error
// see https://github.com/open-telemetry/opentelemetry-collector/issues/10476
import _ "google.golang.org/genproto/googleapis/type/date"

evan361425 avatar Aug 08 '24 00:08 evan361425

I encountered the same issue, and found that the following fixed it:

go get google.golang.org/genproto/googleapis/api
go mod tidy

mattjohnsonpint avatar Aug 16 '24 17:08 mattjohnsonpint

I tried:

go get google.golang.org/genproto/googleapis/api
go mod tidy

I get:

go: upgraded google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 => v0.0.0-20250313205543-e70fdf4c4cb4
go: dql-events/internal/web_data/exports imports
        cloud.google.com/go/storage imports
        google.golang.org/grpc/stats/opentelemetry: ambiguous import: found package google.golang.org/grpc/stats/opentelemetry in multiple modules:
        google.golang.org/grpc v1.71.0 (/Users/work/source/go/pkg/mod/google.golang.org/[email protected]/stats/opentelemetry)
        google.golang.org/grpc/stats/opentelemetry v0.0.0-20241028142157-ada6787961b3 (/Users/work/source/go/pkg/mod/google.golang.org/grpc/stats/[email protected])

I also tried and failed with:

go get -u cloud.google.com/go/storage

go: downloading cloud.google.com/go/iam v1.4.1
go: downloading google.golang.org/api v0.224.0
go: cloud.google.com/go/storage imports
        google.golang.org/grpc/stats/opentelemetry: ambiguous import: found package google.golang.org/grpc/stats/opentelemetry in multiple modules:
        google.golang.org/grpc v1.71.0 (/Users/work/source/go/pkg/mod/google.golang.org/[email protected]/stats/opentelemetry)
        google.golang.org/grpc/stats/opentelemetry v0.0.0-20241028142157-ada6787961b3 (/Users/work/source/go/pkg/mod/google.golang.org/grpc/stats/[email protected])
go: downloading cloud.google.com/go/longrunning v0.6.5

tommed avatar Mar 19 '25 11:03 tommed

We need to see your manifest and have more details on whether you are using custom components to provide further help. If you are also facing this issue, could you please post the full Collector builder manifest you are using?

mx-psi avatar Mar 19 '25 12:03 mx-psi

Thanks. In the meantime Gemini provided a working fix:

"Historically, sub-packages of google.golang.org/grpc were not always treated as independent modules. Now they can be. This can lead to issues when dependencies rely on different module versions."

Complete Reset and Rebuild:

Remove go.mod and go.sum: rm go.mod go.sum

Clean the Module Cache: go clean -modcache

Reinitialize Modules: go mod init your/module/name (Replace your/module/name with your actual module path.)

Add the Required Dependency: go get cloud.google.com/go/storage

Tidy Dependencies: go mod tidy

Build/Run Your Code: go build or go run your_file.go

tommed avatar Mar 19 '25 13:03 tommed

i face same issue.

~~~/cloud.google.com/go/[email protected]/grpc_metrics.go:34:2: ambiguous import: found package google.golang.org/grpc/stats/opentelemetry in multiple modules:
        google.golang.org/grpc v1.71.0 (/Users/~~~/google.golang.org/[email protected]/stats/opentelemetry)
        google.golang.org/grpc/stats/opentelemetry v0.0.0-20240907200651-3ffb98b2c93a (/Users/~~~/google.golang.org/grpc/stats/[email protected])

i think, this issue happening cause is later google.golang.org/[email protected].

i add below code to go.mod then, resolve this issue

replace google.golang.org/grpc v1.71.0 => google.golang.org/grpc v1.68.0

but this solution is temporary. the definitive solution is that  provided package is being corrected.

kwgc-t avatar Mar 21 '25 07:03 kwgc-t

Are there any updates on this?

lukasbash avatar Jun 02 '25 05:06 lukasbash

@lukasbash I was unable to reproduce this with the latest version at the time I had a look at this (see https://github.com/open-telemetry/opentelemetry-collector/issues/10476#issuecomment-2258613279). If you have a way to reliably reproduce this with a manifest using non-custom components, please share it

mx-psi avatar Jun 02 '25 07:06 mx-psi