alibaba / opentelemetry-go-auto-instrumentation

OpenTelemetry Compile-Time Instrumentation for Golang
Apache License 2.0
138 stars 18 forks source link

Can't use otelbuild to build binary #67

Closed Alleysira closed 2 months ago

Alleysira commented 2 months ago

Describe the bug

otelbuild can't build go binary with error otelbuild to build binary

Steps to reproduce

  1. build the otelbuild with make build.
    go mod tidy
    go mod vendor
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags="-X=github.com/alibaba/opentelemetry-go-auto-instrumentation/tool/shared.TheVersion=1.0.0_7d11331 -X=github.com/alibaba/opentelemetry-go-auto-instrumentation/tool/shared.TheName=otelbuild -s -w" -o otelbuild
  2. git clone https://github.com/ethereum/go-ethereum and cd go-ethereum
  3. Use otelbuild instead of go build to compile cmd/evm
    otelbuild -- -o play-evm-in ./cmd/evm

Expected behavior

Compile successfully.

Actual behavior

The error is too long, I will upload a txt file instead. error.txt

opentelemetry-go-auto-instrumentation version

1.0.0_7d11331

Environment

Go: go1.22.3 linux/amd64 OS: Ubuntu 20.04 in wsl

Additional context

No response

123liuziming commented 2 months ago

https://github.com/googleapis/go-genproto/issues/1015 You can check if your google.golang.org/genproto version is too old. You can upgrade the version of google.golang.org/genproto to the latest

123liuziming commented 2 months ago
module mingin

go 1.21.4

require (
    github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0
    go.opentelemetry.io/otel v1.29.0
    go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0
    go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.29.0
    go.opentelemetry.io/otel/sdk v1.29.0
    google.golang.org/grpc v1.65.0
    google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1
    google.golang.org/protobuf v1.34.2
)

require (
    github.com/cenkalti/backoff/v4 v4.3.0 // indirect
    github.com/go-logr/logr v1.4.2 // indirect
    github.com/go-logr/stdr v1.2.2 // indirect
    github.com/google/uuid v1.6.0 // indirect
    go.opentelemetry.io/otel/metric v1.29.0 // indirect
    go.opentelemetry.io/otel/trace v1.29.0 // indirect
    go.opentelemetry.io/proto/otlp v1.3.1 // indirect
    golang.org/x/net v0.28.0 // indirect
    golang.org/x/sys v0.24.0 // indirect
    golang.org/x/text v0.17.0 // indirect
    google.golang.org/genproto v0.0.0-20240823204242-4ba0660f739c // indirect
    google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd // indirect
    google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect
    gopkg.in/yaml.v3 v3.0.1 // indirect
)

I've made a demo to reproduce your problem, I upgrade the google.golang.org/genproto version to v0.0.0-20240823204242-4ba0660f739c and the problem is solved.

Alleysira commented 2 months ago

Thanks for your quick reply, @123liuziming it works after I added a replace in go-ethereum/go.mod

replace google.golang.org/genproto => google.golang.org/genproto v0.0.0-20240822170219-fc7c04adadcd

BTW, I have another usage question: how can I get the code coverage of the instrumented binary when executing with some inputs using otelbuild? Is there any tutorial or recommended codes? Thanks in advance!

123liuziming commented 2 months ago

Thanks for your quick reply, @123liuziming it works after I added a replace in go-ethereum/go.mod

replace google.golang.org/genproto => google.golang.org/genproto v0.0.0-20240822170219-fc7c04adadcd

BTW, I have another usage question: how can I get the code coverage of the instrumented binary when executing with some inputs using otelbuild? Is there any tutorial or recommended codes? Thanks in advance!

What does the code coverage mean? You mean test coverage like jacoco?

Alleysira commented 2 months ago

Yes. My original purpose is to calculate the touched lines of the test binary when executing inputs using this framework.

123liuziming commented 2 months ago

Yes. My original purpose is to calculate the touched lines of the test binary when executing inputs using this framework.

The project is not intended to collect line coverage because we only support to insert code before and after function. We don't need to track every line of code because tracking every line is too costly to maintain the project.

Alleysira commented 2 months ago

The project is not intended to collect line coverage because we only support to insert code before and after function. We don't need to track every line of code because tracking every line is too costly to maintain the project.

Got it, thanks for your time and patience!

Alleysira commented 2 months ago

Hello, @123liuziming. Sorry for the trouble. I came to an error that everytime I use go build to compile, it seems that instrument always happens and [instrument] log will be output even if I'm not using otelbuild (It's weird, I have already deleted the compiled otelbuild). For example:

alleysira@LAPTOP-M4HO8L6S:~/workspace$ go build -o sealevm
# runtime
[instrument] 2024/08/26 20:33:42 Apply file rule runtime_linker.go by APPEND mode
[instrument] 2024/08/26 20:33:42 Apply struct rule @runtime@ {g}
[instrument] 2024/08/26 20:33:42 Apply struct rule @runtime@ {g}
[instrument] 2024/08/26 20:33:42 Apply func rule @runtime@@newproc1 {defer func(){ retVal0.ot_trace_context = contextPropagate(callergp.ot_trace_context); retVal0.ot_baggage_container = contextPropagate(callergp.ot_baggage_container); }() }
[instrument] 2024/08/26 20:33:43 CompileCmd: runtime took 1.326787933s (runtime)
# database/sql
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {DB}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {DB}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {DB}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Conn}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Conn}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Conn}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Tx}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Tx}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Tx}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Stmt}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Stmt}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Stmt}
[instrument] 2024/08/26 20:33:45 Apply func rule @database/sql@@(*Conn).PingContext {beforeConnPingContextInstrumentation afterConnPingContextInstrumentation}
[instrument] 2024/08/26 20:33:45 Apply func rule @database/sql@@(*Stmt).QueryContext {beforeStmtQueryContextInstrumentation afterStmtQueryContextInstrumentation}
[instrument] 2024/08/26 20:33:45 Apply func rule @database/sql@@(*Tx).ExecContext {beforeTxExecContextInstrumentation afterTxExecContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@Open {beforeOpenInstrumentation afterOpenInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*DB).PingContext {beforePingContextInstrumentation afterPingContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Conn).PrepareContext {beforeConnPrepareContextInstrumentation afterConnPrepareContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*DB).PrepareContext {beforePrepareContextInstrumentation afterPrepareContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Conn).QueryContext {beforeConnQueryContextInstrumentation afterConnQueryContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Tx).QueryContext {beforeTxQueryContextInstrumentation afterTxQueryContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Tx).Rollback {beforeTxRollbackInstrumentation afterTxRollbackInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Tx).StmtContext {beforeTxStmtContextInstrumentation afterTxStmtContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Conn).BeginTx {beforeConnTxInstrumentation afterConnTxInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Stmt).ExecContext {beforeStmtExecContextInstrumentation afterStmtExecContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*DB).Conn {beforeConnInstrumentation afterConnInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Conn).ExecContext {beforeConnExecContextInstrumentation afterConnExecContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*DB).ExecContext {beforeExecContextInstrumentation afterExecContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Tx).PrepareContext {beforeTxPrepareContextInstrumentation afterTxPrepareContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*DB).QueryContext {beforeQueryContextInstrumentation afterQueryContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*DB).BeginTx {beforeTxInstrumentation afterTxInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Tx).Commit {beforeTxCommitInstrumentation afterTxCommitInstrumentation}
[instrument] 2024/08/26 20:33:47 CompileCmd: database/sql took 1.734668779s (sql)

Just want to know how to get rid of this? Thanks!

123liuziming commented 2 months ago

Hello, @123liuziming. Sorry for the trouble. I came to an error that everytime I use go build to compile, it seems that instrument always happens and [instrument] log will be output even if I'm not using otelbuild (It's weird, I have already deleted the compiled otelbuild). For example:

alleysira@LAPTOP-M4HO8L6S:~/workspace$ go build -o sealevm
# runtime
[instrument] 2024/08/26 20:33:42 Apply file rule runtime_linker.go by APPEND mode
[instrument] 2024/08/26 20:33:42 Apply struct rule @runtime@ {g}
[instrument] 2024/08/26 20:33:42 Apply struct rule @runtime@ {g}
[instrument] 2024/08/26 20:33:42 Apply func rule @runtime@@newproc1 {defer func(){ retVal0.ot_trace_context = contextPropagate(callergp.ot_trace_context); retVal0.ot_baggage_container = contextPropagate(callergp.ot_baggage_container); }() }
[instrument] 2024/08/26 20:33:43 CompileCmd: runtime took 1.326787933s (runtime)
# database/sql
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {DB}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {DB}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {DB}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Conn}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Conn}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Conn}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Tx}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Tx}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Tx}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Stmt}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Stmt}
[instrument] 2024/08/26 20:33:45 Apply struct rule @database/sql@ {Stmt}
[instrument] 2024/08/26 20:33:45 Apply func rule @database/sql@@(*Conn).PingContext {beforeConnPingContextInstrumentation afterConnPingContextInstrumentation}
[instrument] 2024/08/26 20:33:45 Apply func rule @database/sql@@(*Stmt).QueryContext {beforeStmtQueryContextInstrumentation afterStmtQueryContextInstrumentation}
[instrument] 2024/08/26 20:33:45 Apply func rule @database/sql@@(*Tx).ExecContext {beforeTxExecContextInstrumentation afterTxExecContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@Open {beforeOpenInstrumentation afterOpenInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*DB).PingContext {beforePingContextInstrumentation afterPingContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Conn).PrepareContext {beforeConnPrepareContextInstrumentation afterConnPrepareContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*DB).PrepareContext {beforePrepareContextInstrumentation afterPrepareContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Conn).QueryContext {beforeConnQueryContextInstrumentation afterConnQueryContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Tx).QueryContext {beforeTxQueryContextInstrumentation afterTxQueryContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Tx).Rollback {beforeTxRollbackInstrumentation afterTxRollbackInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Tx).StmtContext {beforeTxStmtContextInstrumentation afterTxStmtContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Conn).BeginTx {beforeConnTxInstrumentation afterConnTxInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Stmt).ExecContext {beforeStmtExecContextInstrumentation afterStmtExecContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*DB).Conn {beforeConnInstrumentation afterConnInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Conn).ExecContext {beforeConnExecContextInstrumentation afterConnExecContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*DB).ExecContext {beforeExecContextInstrumentation afterExecContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Tx).PrepareContext {beforeTxPrepareContextInstrumentation afterTxPrepareContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*DB).QueryContext {beforeQueryContextInstrumentation afterQueryContextInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*DB).BeginTx {beforeTxInstrumentation afterTxInstrumentation}
[instrument] 2024/08/26 20:33:46 Apply func rule @database/sql@@(*Tx).Commit {beforeTxCommitInstrumentation afterTxCommitInstrumentation}
[instrument] 2024/08/26 20:33:47 CompileCmd: database/sql took 1.734668779s (sql)

Just want to know how to get rid of this? Thanks!

use go clean --cache to get rid of this. cc @y1yang0

Alleysira commented 2 months ago

use go clean --cache to get rid of this. cc @y1yang0

Thanks for your quick reply! This works for me. I think a tip in the doc would be nice.

y1yang0 commented 2 months ago

I'll address this soon.

Update: this bug should be addressed in PR#78

@123liuziming Please help review it, thanks.