open-telemetry / opentelemetry-collector

OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
4.43k stars 1.46k forks source link

Ambiguous import error with opentelemetry collector builder #10476

Open zdelagrange opened 4 months ago

zdelagrange commented 4 months ago

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/grpc@v1.64.0/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/genproto@v0.0.0-20200526211855-cb27e3aa2013/googleapis/rpc/status)
    google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 (/home/hanyang/go/pkg/mod/google.golang.org/genproto/googleapis/rpc@v0.0.0-20240520151616-dc85e6b867a5/status)
../go/pkg/mod/go.opentelemetry.io/collector/exporter/otlpexporter@v0.103.0/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/genproto@v0.0.0-20200526211855-cb27e3aa2013/googleapis/rpc/errdetails)
    google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 (/home/hanyang/go/pkg/mod/google.golang.org/genproto/googleapis/rpc@v0.0.0-20240520151616-dc85e6b867a5/errdetails)
../go/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/v2@v2.20.0/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/genproto@v0.0.0-20200526211855-cb27e3aa2013/googleapis/api/httpbody)
    google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 (/home/hanyang/go/pkg/mod/google.golang.org/genproto/googleapis/api@v0.0.0-20240520151616-dc85e6b867a5/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. -->
mx-psi commented 3 months ago

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"}
evan361425 commented 3 months ago

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"
mattjohnsonpint commented 2 months ago

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

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