Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otelhttp: Bazel fails to build due to io_opentelemetry_go_otel_internal_metric #872

Open
AlanDavd opened this issue Jul 9, 2021 · 13 comments
Labels
area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelhttp

Comments

@AlanDavd
Copy link

AlanDavd commented Jul 9, 2021

I'm using Bazel in my project and trying to implement otelhttp in Go.
This is the actual library I'm importing:

...
import go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp
...

When I try to build the package without otelhttp it build successfully, but whenever I try to use it, I got this error:

ERROR: /private/var/tmp/_bazel_aland/06c232323b49fbb607928a9019828b11/external/io_opentelemetry_go_otel_metric/global/BUILD.bazel:3:11: in go_library rule @io_opentelemetry_go_otel_metric//global:go_default_library: target '@io_opentelemetry_go_otel_internal_metric//global:go_default_library' is not visible from target '@io_opentelemetry_go_otel_metric//global:go_default_library'. Check the visibility declaration of the former target if you think the dependency is legitimate
ERROR: Analysis of target '//tracing:tracing' failed; build aborted: Analysis of target '@io_opentelemetry_go_otel_metric//global:go_default_library' failed
  • Mac mini M1
  • OS: [MacOS]
  • Go Version: [1.14]
  • opentelemetry-go version: [0.21.0]
@MrAlias
Copy link
Contributor

MrAlias commented Jul 9, 2021

Please include a minimal set of steps to reproduce the error here.

Have you tried building with Go 1.15+?

@MrAlias MrAlias added bug Something isn't working area: instrumentation Related to an instrumentation package labels Jul 9, 2021
@AlanDavd
Copy link
Author

AlanDavd commented Jul 9, 2021

Yeah. In order to give more context, I use Bazel 4.0.0 in a monorepo of Go services and I'm trying to add otel's net/http package in some services and it fails (returns the same error that above) in all of them.

These are the steps I follow:

  • Add example code shown here according to my needs
  • Run go mod tidy to update go dependencies
  • Run bazel run //:gazelle -- update-repos -from_file=.../go.mod -to_macro=deps.bzl%go_dependencies
  • Run bazel run //:gazelle
  • Try to start service up and then I get the mentioned error

Also, I haven't tried building with Go 1.15+ due to problems with the version of other dependencies, so that's not an option in this case.

@MrAlias
Copy link
Contributor

MrAlias commented Jul 9, 2021

Thanks for the added info. I do not have a setup to test this immediately, but my first guess is going to be that the Go version is blocking this. The sdk/metric package has a dependency on github.com/benbjohnson/clock v1.1.0 which requires Go 1.15+. We followed suit with the rest of the Go community two months ago and moved to support the current and last minor releases of Go. Because of this we upgraded that dependency. I wonder if Bazel is complaining that it cannot resolve the dependency because it needs a different version of the standard library (to be clear I know very little about Bazel).

@floyola
Copy link

floyola commented Jul 13, 2021

bazelbuild/bazel-gazelle#998 👀

@seh
Copy link

seh commented Jul 22, 2021

I spent many hours today writing patches for Gazelle to apply to fix this problem and several others like it. The patches work, to a point, but the real solution turned out to be this:

bazel clean --expunge

I don't know why, but either Gazelle or Bazel was consulting some stale files, and failing to generate BUILD.bazel files that capture the true needs of these Go packages and their containing modules.

Please try running that, and then building without any patches in place. Let us know if that did the trick.

plantfansam referenced this issue in plantfansam/opentelemetry-go-contrib Mar 18, 2022
* Make metric test helpers public

* Move everything metric test related to api/metric/metrictest

* Unify metric measurement assertions

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
@michaelrios
Copy link

michaelrios commented Jul 29, 2022

I am getting a similar error

ERROR: /private/var/tmp/_bazel_michaelrios/40b835931d2eac0aa05000d8e9424bb8/external/io_opentelemetry_go_otel_exporters_otlp_otlptrace/internal/otlpconfig/BUILD.bazel:3:11: no such package '@io_opentelemetry_go_otel_exporters_otlp//internal': BUILD file not found in directory 'internal' of external repository @io_opentelemetry_go_otel_exporters_otlp. Add a BUILD file to a directory to mark it as a package. and referenced by '@io_opentelemetry_go_otel_exporters_otlp_otlptrace//internal/otlpconfig:otlpconfig'

When I look into the Build.bazel file, there are 2 lines

"@io_opentelemetry_go_otel_exporters_otlp//internal",
"@io_opentelemetry_go_otel_exporters_otlp//internal/envconfig",

When I change those lines to be (note the change in the location of the // and replacement of some _ to /)

"@io_opentelemetry_go_otel//exporters/otlp/internal",
"@io_opentelemetry_go_otel//exporters/otlp/internal/envconfig",

This allows everything to work. I have tried bazel clean --expunge and it does not change the outcome.

All of my Build.bazel files are generated by Gazelle, and I do not have this problem anywhere else.

My Go version is 1.18.1
Bazel version 4.2.2
Here are the versions of the io_opentelemetry_go packages I am using

    go_repository(
        name = "io_opentelemetry_go_contrib",
        importpath = "go.opentelemetry.io/contrib",
        sum = "h1:ubFQUn0VCZ0gPwIoJfBJVpeBlyRMxu8Mm/huKWYd9p0=",
        version = "v0.20.0",
    )
    go_repository(
        name = "io_opentelemetry_go_contrib_instrumentation_google_golang_org_grpc_otelgrpc",
        importpath = "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc",
        sum = "h1:Ky1MObd188aGbgb5OgNnwGuEEwI9MVIcc7rBW6zk5Ak=",
        version = "v0.28.0",
    )

    go_repository(
        name = "io_opentelemetry_go_contrib_instrumentation_net_http_otelhttp",
        importpath = "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp",
        sum = "h1:mac9BKRqwaX6zxHPDe3pvmWpwuuIM0vuXv2juCnQevE=",
        version = "v0.32.0",
    )
    go_repository(
        name = "io_opentelemetry_go_contrib_propagators_aws",
        importpath = "go.opentelemetry.io/contrib/propagators/aws",
        sum = "h1:hzLtX+K4YhsrBabA35uBYxCENb5rS/9Z9X8MToTlA3k=",
        version = "v1.7.0",
    )
    go_repository(
        name = "io_opentelemetry_go_otel",
        importpath = "go.opentelemetry.io/otel",
        sum = "h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM=",
        version = "v1.7.0",
    )
    go_repository(
        name = "io_opentelemetry_go_otel_exporters_otlp",
        importpath = "go.opentelemetry.io/otel/exporters/otlp",
        sum = "h1:PTNgq9MRmQqqJY0REVbZFvwkYOA85vbdQU/nVfxDyqg=",
        version = "v0.20.0",
    )

    go_repository(
        name = "io_opentelemetry_go_otel_exporters_otlp_internal_retry",
        importpath = "go.opentelemetry.io/otel/exporters/otlp/internal/retry",
        sum = "h1:7Yxsak1q4XrJ5y7XBnNwqWx9amMZvoidCctv62XOQ6Y=",
        version = "v1.7.0",
    )
    go_repository(
        name = "io_opentelemetry_go_otel_exporters_otlp_otlptrace",
        importpath = "go.opentelemetry.io/otel/exporters/otlp/otlptrace",
        sum = "h1:cMDtmgJ5FpRvqx9x2Aq+Mm0O6K/zcUkH73SFz20TuBw=",
        version = "v1.7.0",
    )
    go_repository(
        name = "io_opentelemetry_go_otel_exporters_otlp_otlptrace_otlptracegrpc",
        importpath = "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc",
        sum = "h1:MFAyzUPrTwLOwCi+cltN0ZVyy4phU41lwH+lyMyQTS4=",
        version = "v1.7.0",
    )
    go_repository(
        name = "io_opentelemetry_go_otel_exporters_otlp_otlptrace_otlptracehttp",
        importpath = "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp",
        sum = "h1:Ydage/P0fRrSPpZeCVxzjqGcI6iVmG2xb43+IR8cjqM=",
        version = "v1.3.0",
    )

    go_repository(
        name = "io_opentelemetry_go_otel_exporters_prometheus",
        importpath = "go.opentelemetry.io/otel/exporters/prometheus",
        sum = "h1:YXo5ZY5nofaEYMCMTTMaRH2cLDZB8+0UGuk5RwMfIo0=",
        version = "v0.30.0",
    )
    go_repository(
        name = "io_opentelemetry_go_otel_metric",
        importpath = "go.opentelemetry.io/otel/metric",
        sum = "h1:Hs8eQZ8aQgs0U49diZoaS6Uaxw3+bBE3lcMUKBFIk3c=",
        version = "v0.30.0",
    )
    go_repository(
        name = "io_opentelemetry_go_otel_oteltest",
        importpath = "go.opentelemetry.io/otel/oteltest",
        sum = "h1:HiITxCawalo5vQzdHfKeZurV8x7ljcqAgiWzF6Vaeaw=",
        version = "v0.20.0",
    )

    go_repository(
        name = "io_opentelemetry_go_otel_sdk",
        importpath = "go.opentelemetry.io/otel/sdk",
        sum = "h1:4OmStpcKVOfvDOgCt7UriAPtKolwIhxpnSNI/yK+1B0=",
        version = "v1.7.0",
    )
    go_repository(
        name = "io_opentelemetry_go_otel_sdk_export_metric",
        importpath = "go.opentelemetry.io/otel/sdk/export/metric",
        sum = "h1:c5VRjxCXdQlx1HjzwGdQHzZaVI82b5EbBgOu2ljD92g=",
        version = "v0.20.0",
    )

    go_repository(
        name = "io_opentelemetry_go_otel_sdk_metric",
        importpath = "go.opentelemetry.io/otel/sdk/metric",
        sum = "h1:XTqQ4y3erR2Oj8xSAOL5ovO5011ch2ELg51z4fVkpME=",
        version = "v0.30.0",
    )
    go_repository(
        name = "io_opentelemetry_go_otel_trace",
        importpath = "go.opentelemetry.io/otel/trace",
        sum = "h1:O37Iogk1lEkMRXewVtZ1BBTVn5JEp8GrJvP92bJqC6o=",
        version = "v1.7.0",
    )
    go_repository(
        name = "io_opentelemetry_go_proto_otlp",
        importpath = "go.opentelemetry.io/proto/otlp",
        sum = "h1:W5hyXNComRa23tGpKwG+FRAc4rfF6ZUg1JReK+QHS80=",
        version = "v0.18.0",
    )

@andyliuliming
Copy link

andyliuliming commented Jul 29, 2022

@michaelrios same issue here.

I think opentelemetry may need to publish new go.opentelemetry.io/otel/exporters/otlp module which contains this package:
go.opentelemetry.io/otel/exporters/otlp/internal/envconfig

issue opened:
open-telemetry/opentelemetry-go#3046

@uhthomas
Copy link

FWIW the gazelle:resolve directive fixed things for me.

go_repository(
    name = "io_opentelemetry_go_otel",
    build_file_proto_mode = "disable",
    build_directives = [
        "gazelle:go_visibility @io_opentelemetry_go_otel_metric//:__subpackages__",
    ],  # keep
    importpath = "go.opentelemetry.io/otel",
    sum = "h1:8WZNQFIB2a71LnANS9JeyidJKKGOOremcUtb/OtHISw=",
    version = "v1.9.0",
)
go_repository(
    name = "io_opentelemetry_go_otel_exporters_otlp_otlptrace",
    build_file_proto_mode = "disable",
    build_directives = [
        "gazelle:resolve go go.opentelemetry.io/otel/exporters/otlp/internal @io_opentelemetry_go_otel//exporters/otlp/internal",
        "gazelle:resolve go go.opentelemetry.io/otel/exporters/otlp/internal/envconfig @io_opentelemetry_go_otel//exporters/otlp/internal/envconfig",
    ],
    importpath = "go.opentelemetry.io/otel/exporters/otlp/otlptrace",
    sum = "h1:LrHL1A3KqIgAgi6mK7Q0aczmzU414AONAGT5xtnp+uo=",
    version = "v1.8.0",
)

@ash2k
Copy link
Contributor

ash2k commented Aug 24, 2022

@uhthomas Thanks a lot! This worked for me too. I've also bumped the second one to v1.9.0:

go_repository(
    name = "io_opentelemetry_go_otel_exporters_otlp_otlptrace",
    build_directives = [
        "gazelle:resolve go go.opentelemetry.io/otel/exporters/otlp/internal @io_opentelemetry_go_otel//exporters/otlp/internal",
        "gazelle:resolve go go.opentelemetry.io/otel/exporters/otlp/internal/envconfig @io_opentelemetry_go_otel//exporters/otlp/internal/envconfig",
    ],
    build_file_proto_mode = "disable",
    importpath = "go.opentelemetry.io/otel/exporters/otlp/otlptrace",
    sum = "h1:NN90Cuna0CnBg8YNu1Q0V35i2E8LDByFOwHRCq/ZP9I=",
    version = "v1.9.0",
)

@ash2k
Copy link
Contributor

ash2k commented Sep 20, 2022

Fix for v1.10.0:

# See https://github.com/open-telemetry/opentelemetry-go-contrib/issues/872
go_repository(
    name = "io_opentelemetry_go_otel",
    build_directives = [
        "gazelle:go_visibility @io_opentelemetry_go_otel_metric//:__subpackages__",
    ],  # keep
    build_file_proto_mode = "disable",
    importpath = "go.opentelemetry.io/otel",
    sum = "h1:Y7DTJMR6zs1xkS/upamJYk0SxxN4C9AqRd77jmZnyY4=",
    version = "v1.10.0",
)

# See https://github.com/open-telemetry/opentelemetry-go-contrib/issues/872
go_repository(
    name = "io_opentelemetry_go_otel_exporters_otlp_otlptrace",
    build_directives = [
        "gazelle:resolve go go.opentelemetry.io/otel/exporters/otlp/internal @io_opentelemetry_go_otel//exporters/otlp/internal",
        "gazelle:resolve go go.opentelemetry.io/otel/exporters/otlp/internal/envconfig @io_opentelemetry_go_otel//exporters/otlp/internal/envconfig",
    ],
    build_file_proto_mode = "disable",
    importpath = "go.opentelemetry.io/otel/exporters/otlp/otlptrace",
    sum = "h1:pDDYmo0QadUPal5fwXoY1pmMpFcdyhXOmL5drCrI3vU=",
    version = "v1.10.0",
)

# See https://github.com/open-telemetry/opentelemetry-go-contrib/issues/872
go_repository(
    name = "io_opentelemetry_go_otel_exporters_otlp_otlptrace_otlptracehttp",
    build_directives = [
        "gazelle:resolve go go.opentelemetry.io/otel/exporters/otlp/internal @io_opentelemetry_go_otel//exporters/otlp/internal",
    ],
    build_file_proto_mode = "disable_global",
    importpath = "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp",
    sum = "h1:S8DedULB3gp93Rh+9Z+7NTEv+6Id/KYS7LDyipZ9iCE=",
    version = "v1.10.0",
)

@uhthomas
Copy link

uhthomas commented Nov 8, 2022

Fix for v1.10.0:

# See https://github.com/open-telemetry/opentelemetry-go-contrib/issues/872
go_repository(
    name = "io_opentelemetry_go_otel",
    build_directives = [
        "gazelle:go_visibility @io_opentelemetry_go_otel_metric//:__subpackages__",
    ],  # keep
    build_file_proto_mode = "disable",
    importpath = "go.opentelemetry.io/otel",
    sum = "h1:Y7DTJMR6zs1xkS/upamJYk0SxxN4C9AqRd77jmZnyY4=",
    version = "v1.10.0",
)

# See https://github.com/open-telemetry/opentelemetry-go-contrib/issues/872
go_repository(
    name = "io_opentelemetry_go_otel_exporters_otlp_otlptrace",
    build_directives = [
        "gazelle:resolve go go.opentelemetry.io/otel/exporters/otlp/internal @io_opentelemetry_go_otel//exporters/otlp/internal",
        "gazelle:resolve go go.opentelemetry.io/otel/exporters/otlp/internal/envconfig @io_opentelemetry_go_otel//exporters/otlp/internal/envconfig",
    ],
    build_file_proto_mode = "disable",
    importpath = "go.opentelemetry.io/otel/exporters/otlp/otlptrace",
    sum = "h1:pDDYmo0QadUPal5fwXoY1pmMpFcdyhXOmL5drCrI3vU=",
    version = "v1.10.0",
)

# See https://github.com/open-telemetry/opentelemetry-go-contrib/issues/872
go_repository(
    name = "io_opentelemetry_go_otel_exporters_otlp_otlptrace_otlptracehttp",
    build_directives = [
        "gazelle:resolve go go.opentelemetry.io/otel/exporters/otlp/internal @io_opentelemetry_go_otel//exporters/otlp/internal",
    ],
    build_file_proto_mode = "disable_global",
    importpath = "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp",
    sum = "h1:S8DedULB3gp93Rh+9Z+7NTEv+6Id/KYS7LDyipZ9iCE=",
    version = "v1.10.0",
)

I found that in addition to your changes, the otlptracegrpc package needs a build directive too.

go_repository(
    name = "io_opentelemetry_go_otel_exporters_otlp_otlptrace_otlptracegrpc",
    build_directives = [
        "gazelle:resolve go go.opentelemetry.io/otel/exporters/otlp/internal @io_opentelemetry_go_otel//exporters/otlp/internal",
    ],
    build_file_proto_mode = "disable",
    importpath = "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc",
    sum = "h1:KtiUEhQmj/Pa874bVYKGNVdq8NPKiacPbaRRtgXi+t4=",
    version = "v1.10.0",
)

@ChenX1993
Copy link

Thanks all!

For v1.13.0, I still face the same issue.
The above fix worked for me.

@chrisseto
Copy link

Just ran into this issue myself and was able to work around it with the build directives described but I found a slightly nicer solution that I think further points the finger at something being incorrect in gazelle.

The issue is caused by the inclusion of this go_repository. If you remove this rule and then re-run your build, you'll find that imports are correctly resolved.

    go_repository(
        name = "io_opentelemetry_go_otel_exporters_otlp",
        build_file_proto_mode = "disable",
        importpath = "go.opentelemetry.io/otel/exporters/otlp",
        sum = "h1:PTNgq9MRmQqqJY0REVbZFvwkYOA85vbdQU/nVfxDyqg=",
        version = "v0.20.0",
    )

I don't know the provenance of this repo but I suspect there was a go.mod in that folder at some point in time. This results in an entry in the go.sum file ala go mod's dependency resolution. Gazelle "sees" this and then turns into a go_repository rule [citation needed]. Gazelle's dependency resolution, incorrectly, sees the importpath of this go_repository and then routes imports to it which causes this failure.

I can't figure out how to stop gazelle from generating this go_repository but you can fix the issue with fewer lines by munging the importpath and adding a # keep directive.

    go_repository(
        name = "io_opentelemetry_go_otel_exporters_otlp",
        build_file_proto_mode = "disable",
        importpath = "WRONGgo.opentelemetry.io/otel/exporters/otlp", # keep
        sum = "h1:PTNgq9MRmQqqJY0REVbZFvwkYOA85vbdQU/nVfxDyqg=",
        version = "v0.20.0",
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelhttp
Projects
None yet
Development

No branches or pull requests

10 participants