go-redis: undefined: otel.Meter or cannot find package "go.opentelemetry.io/otel/api/trace"

To fix cannot find package "go.opentelemetry.io/otel/api/trace" or undefined: otel.Meter:

  1. Make sure to initialize a Go module: go mod init github.com/my/repo

  2. Make sure to use correct import path with v8 in the end: go get github.com/go-redis/redis/v8

For example:

mkdir /tmp/redis-test
cd /tmp/redis-test
go mod init redis-test
go get github.com/go-redis/redis/v8

The root cause

The error is not caused by OpenTelemetry. OpenTelemetry is just the first module Go tries to install. And the error will not go away until you start using Go modules properly.

The presence of $GOROOT or $GOPATH in error messages indicates that you are NOT using Go modules.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 33 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Current version of this library (v8.5.0) uses go.opentelemetry.io/otel v0.16.0, but otel released v0.17.0 in which they broke backward compatibility by reorganizing their modules (https://github.com/open-telemetry/opentelemetry-go/pull/1528). And that possibility was very clearly stated in their README:

Warning: this project is currently in a pre-GA phase. Backwards incompatible changes may be introduced in subsequent minor version releases as we work to track the evolving OpenTelemetry specification and user feedback.

So until go-redis/redis is updated to use otel v0.17.0 this error can temporary be avoided by forcing your project to use v0.16.0 in go.mod:

replace go.opentelemetry.io/otel => go.opentelemetry.io/otel v0.16.0

The issue is an old one and the project team has not fixed it yet, even though I have sent them the fix and explain the reasons for the error. This issue arises only on CLEAN development environments. This means on fresh installs or if you clean your existing development environment (I saw the error first on a clean linux install, and then when I cleaned my level environment in a separate machine). Cause: the error is not caused by any mod or sum file… that is not correct. The issue is caused by the changes made by the opentelemetry project team on the projects package structure. They remove the /opel/api/trace package and move all the code (declarations and functions) to the Otel package; and the go-redis team has not updated the imports for this packages, nor the function declarations (and variables). If you read the code, you will see that redid v8.3.3 code keeps importing the /otel/api/trace package, and when you compare it with the version it pulls from open telemetry, the package does not exist in the open telemetry code. The go-redis team do not see the error because (I’m pretty sure of this, cause it happened to me also) because they have not made a cleanup to their development environment and try to build the code. If they do this, they will get it as well (again, I have don that and get the error).

Fix: There are several ways to fix the error, some of which are for your local machine (they do not fix the error when pulling from a container, or any other pull-dependent build or run).

  • Local fix: see the pull request and you will find a pull request I made with the changes needed to make the code work. You can make the changes in your local sources and your code will build. I would recommend this fix only for testing in your local machine, so your development do not get delayed because of the go-redis team not fixing this critical issue.

  • Avoid error fix (stick with the v8 beta): I checked the commit history and realized that the last working version is the version 8.0.0-beta.8. You can update your code’s mod file to fix the version and refresh your environment. This fix made the trick for me, but I don’t want to make it a permanent thing.

  • Try another package: I do not see the go-readis team fixing this issue in the near future (and I do not think that getting stuck in the v8 beta forever is an option) as they have not suffer it yet. They closed the issue and failed to get the severity of it or even getting the point.

I hope this helps

I just want the old version back, I don’t want to change anything I believe stuff should not break like this without releasing a v9

Sorry if ai’m not clear: I’ve been using go-redis for months now. yesterday I tried to build my code and the compiler showed me the error I sent on my initial post. Go keeps trying to get the package go.opentelemetry.io/otel/api/trace. If I do a go build, the error is: /home/gonzalo/golib/src/github.com/go-redis/redis/internal/util.go:10:2: cannot find package “go.opentelemetry.io/otel/api/trace” in any of: /usr/local/go/src/go.opentelemetry.io/otel/api/trace (from $GOROOT) /home/gonzalo/golib/src/go.opentelemetry.io/otel/api/trace (from $GOPATH) /home/gonzalo/go/src/go.opentelemetry.io/otel/api/trace

@vmihailenco this error occurs when people attempts to update all dependencies (direct and transitive) to the latest version. Personally I’m using this command: go get -v -u -d all. This attempts to update the otel modules from 0.20.0 to 1.0.0 RC1. In my projects I’m only using go-redis directly, and otel is a transitive dependency.

There is a commit for the bug (1f32092a3b04c21b6e8e51e2c94c03448d14a2c9) but there is no release.

Force go get to get this commit: go get github.com/go-redis/redis/v8@1f32092a3b04c21b6e8e51e2c94c03448d14a2c9

Anyone else having this issue on version v8.10.0?

I’m still getting this error… I’m using “github.com/go-redis/redis/v8” and my go.mod has “github.com/go-redis/redis/v8 v8.3.3”

Here is my docker log:

Step 1/7 : FROM golang:1.15

| —> 1b8b0ceece59   | Step 2/7 : WORKDIR /go/src/app   | —> Using cache   | —> fe62023733e0   | Step 3/7 : COPY . .   | —> ca629ac8d7f3   | Step 4/7 : RUN go get -v ./…   | —> Running in bc86e65b37d3   | github.com/aws/aws-lambda-go (download)   | github.com/aws/aws-sdk-go (download)   | github.com/jmespath/go-jmespath (download)   | github.com/aws/aws-xray-sdk-go (download)   | github.com/pkg/errors (download)   | github.com/cultureamp/glamplify (download)   | github.com/bobesa/go-domain-util (download)   | get “golang.org/x/net/idna”: found meta tag get.metaImport{Prefix:“golang.org/x/net”, VCS:“git”, RepoRoot:“https://go.googlesource.com/net”} at //golang.org/x/net/idna?go-get=1   | get “golang.org/x/net/idna”: verifying non-authoritative meta tag   | golang.org/x/net (download)   | get “golang.org/x/text/secure/bidirule”: found meta tag get.metaImport{Prefix:“golang.org/x/text”, VCS:“git”, RepoRoot:“https://go.googlesource.com/text”} at //golang.org/x/text/secure/bidirule?go-get=1   | get “golang.org/x/text/secure/bidirule”: verifying non-authoritative meta tag   | golang.org/x/text (download)   | get “golang.org/x/text/unicode/bidi”: found meta tag get.metaImport{Prefix:“golang.org/x/text”, VCS:“git”, RepoRoot:“https://go.googlesource.com/text”} at //golang.org/x/text/unicode/bidi?go-get=1   | get “golang.org/x/text/unicode/bidi”: verifying non-authoritative meta tag   | get “golang.org/x/text/unicode/norm”: found meta tag get.metaImport{Prefix:“golang.org/x/text”, VCS:“git”, RepoRoot:“https://go.googlesource.com/text”} at //golang.org/x/text/unicode/norm?go-get=1   | get “golang.org/x/text/unicode/norm”: verifying non-authoritative meta tag   | github.com/patrickmn/go-cache (download)   | github.com/dgrijalva/jwt-go (download)   | github.com/go-errors/errors (download)   | github.com/gookit/color (download)   | github.com/DataDog/datadog-lambda-go (download)   | github.com/DataDog/datadog-go (download)   | get “gopkg.in/DataDog/dd-trace-go.v1/ddtrace”: found meta tag get.metaImport{Prefix:“gopkg.in/DataDog/dd-trace-go.v1”, VCS:“git”, RepoRoot:“https://gopkg.in/DataDog/dd-trace-go.v1”} at //gopkg.in/DataDog/dd-trace-go.v1/ddtrace?go-get=1   | get “gopkg.in/DataDog/dd-trace-go.v1/ddtrace”: verifying non-authoritative meta tag   | gopkg.in/DataDog/dd-trace-go.v1 (download)   | get “gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer”: found meta tag get.metaImport{Prefix:“gopkg.in/DataDog/dd-trace-go.v1”, VCS:“git”, RepoRoot:“https://gopkg.in/DataDog/dd-trace-go.v1”} at //gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer?go-get=1   | get “gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer”: verifying non-authoritative meta tag   | get “golang.org/x/time/rate”: found meta tag get.metaImport{Prefix:“golang.org/x/time”, VCS:“git”, RepoRoot:“https://go.googlesource.com/time”} at //golang.org/x/time/rate?go-get=1   | get “golang.org/x/time/rate”: verifying non-authoritative meta tag   | golang.org/x/time (download)   | get “golang.org/x/xerrors”: found meta tag get.metaImport{Prefix:“golang.org/x/xerrors”, VCS:“git”, RepoRoot:“https://go.googlesource.com/xerrors”} at //golang.org/x/xerrors?go-get=1   | golang.org/x/xerrors (download)   | github.com/google/uuid (download)   | get “gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http”: found meta tag get.metaImport{Prefix:“gopkg.in/DataDog/dd-trace-go.v1”, VCS:“git”, RepoRoot:“https://gopkg.in/DataDog/dd-trace-go.v1”} at //gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http?go-get=1   | get “gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http”: verifying non-authoritative meta tag   | github.com/getsentry/sentry-go (download)   | github.com/go-redis/redis (download)   | github.com/cespare/xxhash (download)   | github.com/dgryski/go-rendezvous (download)   | get “go.opentelemetry.io/otel/api/global”: found meta tag get.metaImport{Prefix:“go.opentelemetry.io/otel”, VCS:“git”, RepoRoot:“https://github.com/open-telemetry/opentelemetry-go”} at //go.opentelemetry.io/otel/api/global?go-get=1   | get “go.opentelemetry.io/otel/api/global”: verifying non-authoritative meta tag   | go.opentelemetry.io/otel (download)   | cannot find package “go.opentelemetry.io/otel/api/global” in any of:   | /usr/local/go/src/go.opentelemetry.io/otel/api/global (from $GOROOT)   | /go/src/go.opentelemetry.io/otel/api/global (from $GOPATH)   | get “go.opentelemetry.io/otel/api/metric”: found meta tag get.metaImport{Prefix:“go.opentelemetry.io/otel”, VCS:“git”, RepoRoot:“https://github.com/open-telemetry/opentelemetry-go”} at //go.opentelemetry.io/otel/api/metric?go-get=1   | get “go.opentelemetry.io/otel/api/metric”: verifying non-authoritative meta tag   | cannot find package “go.opentelemetry.io/otel/api/metric” in any of:   | /usr/local/go/src/go.opentelemetry.io/otel/api/metric (from $GOROOT)   | /go/src/go.opentelemetry.io/otel/api/metric (from $GOPATH)   | get “go.opentelemetry.io/otel/api/trace”: found meta tag get.metaImport{Prefix:“go.opentelemetry.io/otel”, VCS:“git”, RepoRoot:“https://github.com/open-telemetry/opentelemetry-go”} at //go.opentelemetry.io/otel/api/trace?go-get=1   | get “go.opentelemetry.io/otel/api/trace”: verifying non-authoritative meta tag   | cannot find package “go.opentelemetry.io/otel/api/trace” in any of:   | /usr/local/go/src/go.opentelemetry.io/otel/api/trace (from $GOROOT)   | /go/src/go.opentelemetry.io/otel/api/trace (from $GOPATH)   | get “go.opentelemetry.io/otel/label”: found meta tag get.metaImport{Prefix:“go.opentelemetry.io/otel”, VCS:“git”, RepoRoot:“https://github.com/open-telemetry/opentelemetry-go”} at //go.opentelemetry.io/otel/label?go-get=1   | get “go.opentelemetry.io/otel/label”: verifying non-authoritative meta tag   | The command ‘/bin/sh -c go get -v ./…’ returned a non-zero code: 1   | 🚨 Error: The command exited with status 1