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

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

Closed
vmihailenco opened this issue Oct 13, 2020 · 33 comments · Fixed by #1805
Closed

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

vmihailenco opened this issue Oct 13, 2020 · 33 comments · Fixed by #1805

Comments

@vmihailenco
Copy link
Collaborator

vmihailenco commented Oct 13, 2020

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.

@gonzalochief
Copy link

go get -u go.opentelemetry.io/otel/apils

I got this error when initializing the module and downloading all dependencies:
go get go.opentelemetry.io/otel/apils: module go.opentelemetry.io/otel@upgrade found (v0.13.0), but does not contain package go.opentelemetry.io/otel/apils

@vmihailenco
Copy link
Collaborator Author

@vmihailenco you don't need to install go.opentelemetry.io/otel/apils. And you have typo in the name.

@gonzalochief
Copy link

Thanks for answering in such a short time... I appreciate that
just to make my previous post clear, the typo was a copy paste issue for this post (my bad). The thing is that go says
go get go.opentelemetry.io/otel/api: module go.opentelemetry.io/otel@upgrade found (v0.13.0), but does not contain package go.opentelemetry.io/otel/api
the same goes with the /otel/api/trace

@vmihailenco
Copy link
Collaborator Author

I don't understand what you are trying to do. To install go-redis you don't need opentelemetry:

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

@gonzalochief
Copy link

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

@praesyx
Copy link

praesyx commented Oct 14, 2020

Yes, I also get this error when installing packages.
I noticed that the go.opentelemetry.io package was recently updated (Move trace api package into ʻotel` (# 1229)
) and now there is no go.opentelemetry.io/otel/api/trace. Some of your code files have links to /api/trace (span trace.Span), but now they are gone.
The update will be like this -
import "go.opentelemetry.io/otel"
func (ctx context.Context, span otel.Span)
I'm sorry if I'm wrong

@gonzalochief
Copy link

Actually,, your suggestion worked! if you need the fixed code while the fix gets implemented in the oficial repository, i can share it...

@anboo
Copy link

anboo commented Oct 20, 2020

I have same error:

 ---> d6f3656320fe
Step 2/11 : RUN go get github.com/go-redis/redis && mkdir /app
 ---> Running in e904119f8623
package go.opentelemetry.io/otel/api/global: 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)
package go.opentelemetry.io/otel/api/metric: 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)
package go.opentelemetry.io/otel/api/trace: 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)
The command '/bin/sh -c go get github.com/go-redis/redis && mkdir /app' returned a non-zero code: 1

Base image:
FROM golang:1.13

@anboo
Copy link

anboo commented Oct 20, 2020

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

Output:

Sending build context to Docker daemon  158.2kB
Step 1/11 : FROM golang:1.13
1.13: Pulling from library/golang
Digest: sha256:8ebb6d5a48deef738381b56b1d4cd33d99a5d608e0d03c5fe8dfa3f68d41a1f8
Status: Image is up to date for golang:1.13
 ---> d6f3656320fe
Step 2/11 : RUN mkdir /tmp/redis-test &&     cd /tmp/redis-test &&     go mod init redis-test &&     go get github.com/go-redis/redis &&     mkdir /app
 ---> Running in 17e507455f58
go: creating new go.mod: module redis-test
go: finding github.com/go-redis/redis v6.15.9+incompatible
go: downloading github.com/go-redis/redis v6.15.9+incompatible
go: extracting github.com/go-redis/redis v6.15.9+incompatible
Removing intermediate container 17e507455f58
 ---> 68dbf45d5e84
Step 3/11 : ADD . /app/
 ---> cf9904244733
Step 4/11 : WORKDIR /app
 ---> Running in c902877bee9b
Removing intermediate container c902877bee9b
 ---> 32e6f69765f3
Step 5/11 : ADD . .
 ---> 771e8215b6d8
Step 6/11 : RUN go get -d
 ---> Running in 89787736a5b1
package go.opentelemetry.io/otel/api/global: 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)
package go.opentelemetry.io/otel/api/metric: 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)
package go.opentelemetry.io/otel/api/trace: 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)
The command '/bin/sh -c go get -d' returned a non-zero code: 1

@lululombard
Copy link

lululombard commented Oct 23, 2020

Our GitHub actions also stopped working randomly because of this.

Why is this issue closed? It's a problem even with the last version...

@anboo
Copy link

anboo commented Oct 23, 2020

@lululombard go-redis supports 2 last Go versions and requires a Go version with modules support

I run init module for current project

go mod init ...

with

RUN mkdir /tmp/redis-test && \
    cd /tmp/redis-test && \
    go mod init redis-test && \
    go get github.com/go-redis/redis/v8 && \
    mkdir /app

RUN go get -d

in main.go:

import "github.com/go-redis/redis/v8"

file go.mod automatically generated:

module gitlab.com/.../event-bus

go 1.13

require (
	github.com/go-redis/redis/v8 v8.3.2
	github.com/gorilla/websocket v1.4.2
	github.com/mitchellh/mapstructure v1.3.3
	github.com/streadway/amqp v1.0.0
)

And I fix this problem for me.

@anboo
Copy link

anboo commented Oct 23, 2020

@lululombard
Copy link

lululombard commented Oct 23, 2020

I have no idea how a golang project should be set up, but I have $GOPATH/go.mod exists but should not when I try to install redis after I run go mod init ..., the thing is I can't find any doc on how I'm supposed to set up my environment

EDIT: I found some doc and set up my environment properly and now it works!

@lululombard
Copy link

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

@Gelembjuk
Copy link

Gelembjuk commented Nov 6, 2020

Hi Guys,
So what is the final solution here?

In my docker-compose settings i had
RUN go get -u github.com/go-redis/redis

and t worked fine. Now it stopped to work.

I tried to do

`FROM centos:7 AS builder
WORKDIR /app/

RUN yum install -y wget git &&
wget https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz -O /tmp/golang.tar.gz &&
tar -C /usr/local -xvzf /tmp/golang.tar.gz

ENV PATH="/usr/local/go/bin:${PATH}"
ENV GOPATH="/app/"

RUN mkdir /tmp/redis-test &&
cd /tmp/redis-test &&
go mod init redis-test &&
go get -u github.com/go-redis/redis/v8`

It is executed fie but than my app compilation fails with the error

../lib/consumer/redis.go:13:2: cannot find package "github.com/go-redis/redis" in any of: /usr/local/go/src/github.com/go-redis/redis (from $GOROOT) /app/src/github.com/go-redis/redis (from $GOPATH)

So, what else can i do? If that module is installed, where is it? do i need to change my code too?

Do i need to have something like ?

import "github.com/go-redis/redis/v8"

this also doesn't work.

@g-t-675
Copy link

g-t-675 commented Nov 6, 2020

@Gelembjuk Your envs are causing the issue. You can try this: copy the code of your app into the same place where the redis mod has been inited and run the compilation inside that folder, since you are using a builder image you are just interested in the output executable anyway (I assume).
Also I would recommend using the official golang builder and not like in your example - using centos, fetching the golang and then setting manually env paths.

@gonzalochief
Copy link

If you want to fix it to work in your PC, i'v posted the changes needed in the code to reflect the changes made in the package that's making the code crash.
To make it work with containers, I had to use the las beta version of v8 by seeing the version on my code's mod file.

@techmanmike
Copy link

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

@gonzalochief
Copy link

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

@specialshoot
Copy link

Not fix but close? I run "go mod init ..." then run "go get github.com/go-redis/redis/v8", but it doesn't work.
Even "go-redis" dir doesn't appear in "go/src/github/" dir

@ahmadfarisfs
Copy link

ahmadfarisfs commented Dec 7, 2020

any fix for this yet ?

UPDATE: my workaround was :

  1. go to ~/go/src/go.opentelemetry.io/otel
  2. git checkout 1d2189088dbfe62fc65bfd481c547d33ba59c522

this will revert otel package before the breaking changes

@jay-khatri
Copy link

I fixed this by using github.com/go-redis/redis/v7 rather than v8 (this was fine given my usage of the library).

@gonzalochief 's suggestion to use 8.0.0-beta.8 didn't work; maybe its an earlier beta version?

@vmihailenco vmihailenco unpinned this issue Feb 9, 2021
@vmihailenco vmihailenco pinned this issue Feb 14, 2021
@vmihailenco vmihailenco changed the title cannot find package "go.opentelemetry.io/otel/api/trace" undefined: otel.Meter or cannot find package "go.opentelemetry.io/otel/api/trace" Feb 15, 2021
@optiman
Copy link

optiman commented Feb 16, 2021

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 (open-telemetry/opentelemetry-go#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

@fallais
Copy link

fallais commented Feb 17, 2021

Any upcoming due date to see this fixed ? :)

@ribice
Copy link

ribice commented Feb 17, 2021

Facing same issue when trying to update go-redis.

@Navid2zp
Copy link

Navid2zp commented Feb 17, 2021

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

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

@jayyu317
Copy link

jayyu317 commented Jun 2, 2021

When I use the workaround solution with replace() dependencies in my go.mod, I encountered "opentelemetry.io/otel/api/trace" dependency error. The solution for that error is adding redis v8 dependency at require() in your go.mod by "go get github.com/go-redis/redis/v8". FYI #1534

@vmihailenco vmihailenco unpinned this issue Jun 7, 2021
@rubens21
Copy link

Anyone else having this issue on version v8.10.0?

@pierrre
Copy link

pierrre commented Jun 30, 2021

I think this issue occurs because they've released the version 1.0.0 rc1 of the otel modules.
I guess they have changed the internal package structure again.

The quickfix for each individual project is to use replace in go.mod, and force the otel version.

The fix for go-redis is to upgrade to otel 1.0.0 RC1.

Should we open a new issue or reopen this one ?

@vmihailenco
Copy link
Collaborator Author

It would help if someone can explain why the build is passing and go-redis is working fine in my (private) projects...

I will update the OpenTelemetry version used in go-redis. May be even remove existing metrics - they don't look worth the trouble and we plan to replace them anyway with something more useful.

@pierrre
Copy link

pierrre commented Jun 30, 2021

@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.

@pierrre
Copy link

pierrre commented Jun 30, 2021

FYI #1805 (comment)

@gonzalochief
Copy link

I only het the error either when I do a clean deploy (new redevelopment machine) or update dependencies.
This happens every time otel makes a radical change. Go redid is a very good package, but otel failures makes it hard to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.