Skip to content

Commit 41cac58

Browse files
authored
chore: inject W3C headers into engine client and eth client (#2958)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview Part of #2956 Injects W3C headers into engine client and eth client, this will allow us to set up proper traces (with some changes to ev-reth to respect them) I will add additional spans in a follow up. <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> -->
1 parent 4ce10cd commit 41cac58

File tree

10 files changed

+561
-86
lines changed

10 files changed

+561
-86
lines changed

apps/evm/cmd/run.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/rs/zerolog"
1414
"github.com/spf13/cobra"
1515

16+
"github.com/evstack/ev-node/apps/evm/server"
1617
"github.com/evstack/ev-node/block"
1718
"github.com/evstack/ev-node/core/execution"
1819
coresequencer "github.com/evstack/ev-node/core/sequencer"
@@ -29,8 +30,6 @@ import (
2930
"github.com/evstack/ev-node/pkg/sequencers/based"
3031
"github.com/evstack/ev-node/pkg/sequencers/single"
3132
"github.com/evstack/ev-node/pkg/store"
32-
33-
"github.com/evstack/ev-node/apps/evm/server"
3433
)
3534

3635
const (
@@ -56,7 +55,8 @@ var RunCmd = &cobra.Command{
5655
return err
5756
}
5857

59-
executor, err := createExecutionClient(cmd, datastore)
58+
tracingEnabled := nodeConfig.Instrumentation.IsTracingEnabled()
59+
executor, err := createExecutionClient(cmd, datastore, tracingEnabled)
6060
if err != nil {
6161
return err
6262
}
@@ -201,7 +201,7 @@ func createSequencer(
201201
return sequencer, nil
202202
}
203203

204-
func createExecutionClient(cmd *cobra.Command, db datastore.Batching) (execution.Executor, error) {
204+
func createExecutionClient(cmd *cobra.Command, db datastore.Batching, tracingEnabled bool) (execution.Executor, error) {
205205
// Read execution client parameters from flags
206206
ethURL, err := cmd.Flags().GetString(evm.FlagEvmEthURL)
207207
if err != nil {
@@ -246,7 +246,7 @@ func createExecutionClient(cmd *cobra.Command, db datastore.Batching) (execution
246246
genesisHash := common.HexToHash(genesisHashStr)
247247
feeRecipient := common.HexToAddress(feeRecipientStr)
248248

249-
return evm.NewEngineExecutionClient(ethURL, engineURL, jwtSecret, genesisHash, feeRecipient, db)
249+
return evm.NewEngineExecutionClient(ethURL, engineURL, jwtSecret, genesisHash, feeRecipient, db, tracingEnabled)
250250
}
251251

252252
// addFlags adds flags related to the EVM execution client

execution/evm/execution.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/rs/zerolog"
2424

2525
"github.com/evstack/ev-node/core/execution"
26+
"github.com/evstack/ev-node/pkg/telemetry"
2627
)
2728

2829
const (
@@ -157,40 +158,55 @@ type EngineClient struct {
157158
// The db parameter is required for ExecMeta tracking which enables idempotent
158159
// execution and crash recovery. The db is wrapped with a prefix to isolate
159160
// EVM execution data from other ev-node data.
161+
// When tracingEnabled is true, the client will inject W3C trace context headers
162+
// and wrap Engine API calls with OpenTelemetry spans.
160163
func NewEngineExecutionClient(
161164
ethURL,
162165
engineURL string,
163166
jwtSecret string,
164167
genesisHash common.Hash,
165168
feeRecipient common.Address,
166169
db ds.Batching,
170+
tracingEnabled bool,
167171
) (*EngineClient, error) {
168172
if db == nil {
169173
return nil, errors.New("db is required for EVM execution client")
170174
}
171175

172-
ethClient, err := ethclient.Dial(ethURL)
176+
var rpcOpts []rpc.ClientOption
177+
// If tracing enabled, add W3C header propagation to rpcOpts
178+
if tracingEnabled {
179+
rpcOpts = append(rpcOpts, rpc.WithHTTPClient(
180+
telemetry.NewPropagatingHTTPClient(http.DefaultTransport)))
181+
}
182+
183+
// Create ETH RPC client with HTTP options
184+
ethRPC, err := rpc.DialOptions(context.Background(), ethURL, rpcOpts...)
173185
if err != nil {
174186
return nil, err
175187
}
188+
ethClient := ethclient.NewClient(ethRPC)
176189

177190
secret, err := decodeSecret(jwtSecret)
178191
if err != nil {
179192
return nil, err
180193
}
181194

182-
engineClient, err := rpc.DialOptions(context.Background(), engineURL,
183-
rpc.WithHTTPAuth(func(h http.Header) error {
184-
authToken, err := getAuthToken(secret)
185-
if err != nil {
186-
return err
187-
}
188-
189-
if authToken != "" {
190-
h.Set("Authorization", "Bearer "+authToken)
191-
}
192-
return nil
193-
}))
195+
// Create Engine RPC with optional HTTP client and JWT auth
196+
// Compose engine options: pass-through rpcOpts plus JWT auth
197+
engineOptions := make([]rpc.ClientOption, len(rpcOpts))
198+
copy(engineOptions, rpcOpts) // copy to avoid using same backing array from rpcOpts.
199+
engineOptions = append(engineOptions, rpc.WithHTTPAuth(func(h http.Header) error {
200+
authToken, err := getAuthToken(secret)
201+
if err != nil {
202+
return err
203+
}
204+
if authToken != "" {
205+
h.Set("Authorization", "Bearer "+authToken)
206+
}
207+
return nil
208+
}))
209+
engineClient, err := rpc.DialOptions(context.Background(), engineURL, engineOptions...)
194210
if err != nil {
195211
return nil, err
196212
}

execution/evm/go.mod

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.24.6
44

55
require (
66
github.com/ethereum/go-ethereum v1.16.7
7+
github.com/evstack/ev-node v1.0.0-beta.10
78
github.com/evstack/ev-node/core v1.0.0-beta.5
89
github.com/golang-jwt/jwt/v5 v5.3.0
910
github.com/ipfs/go-datastore v0.9.0
@@ -18,8 +19,10 @@ require (
1819
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251001021608-1fe7b43fc4d6 // indirect
1920
github.com/StackExchange/wmi v1.2.1 // indirect
2021
github.com/bits-and-blooms/bitset v1.20.0 // indirect
22+
github.com/celestiaorg/go-square/v3 v3.0.2 // indirect
23+
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
24+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2125
github.com/consensys/gnark-crypto v0.18.0 // indirect
22-
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
2326
github.com/crate-crypto/go-eth-kzg v1.4.0 // indirect
2427
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
2528
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
@@ -29,33 +32,76 @@ require (
2932
github.com/ethereum/c-kzg-4844/v2 v2.1.5 // indirect
3033
github.com/ethereum/go-verkle v0.2.2 // indirect
3134
github.com/ferranbt/fastssz v0.1.4 // indirect
35+
github.com/fsnotify/fsnotify v1.9.0 // indirect
36+
github.com/go-logr/logr v1.4.3 // indirect
37+
github.com/go-logr/stdr v1.2.2 // indirect
3238
github.com/go-ole/go-ole v1.3.0 // indirect
39+
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
40+
github.com/goccy/go-yaml v1.19.0 // indirect
3341
github.com/gofrs/flock v0.12.1 // indirect
3442
github.com/golang/snappy v1.0.0 // indirect
3543
github.com/google/uuid v1.6.0 // indirect
3644
github.com/gorilla/websocket v1.5.3 // indirect
45+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
3746
github.com/holiman/uint256 v1.3.2 // indirect
47+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
48+
github.com/ipfs/go-cid v0.6.0 // indirect
3849
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
3950
github.com/mattn/go-colorable v0.1.14 // indirect
4051
github.com/mattn/go-isatty v0.0.20 // indirect
4152
github.com/mattn/go-runewidth v0.0.15 // indirect
4253
github.com/minio/sha256-simd v1.0.1 // indirect
4354
github.com/mitchellh/mapstructure v1.5.0 // indirect
55+
github.com/mr-tron/base58 v1.2.0 // indirect
56+
github.com/multiformats/go-base32 v0.1.0 // indirect
57+
github.com/multiformats/go-base36 v0.2.0 // indirect
58+
github.com/multiformats/go-multiaddr v0.16.1 // indirect
59+
github.com/multiformats/go-multibase v0.2.0 // indirect
60+
github.com/multiformats/go-multihash v0.2.3 // indirect
61+
github.com/multiformats/go-varint v0.1.0 // indirect
4462
github.com/olekukonko/tablewriter v0.0.5 // indirect
63+
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
4564
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
4665
github.com/rivo/uniseg v0.2.0 // indirect
47-
github.com/rogpeppe/go-internal v1.14.1 // indirect
4866
github.com/rs/cors v1.11.1 // indirect
67+
github.com/sagikazarmark/locafero v0.11.0 // indirect
4968
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
69+
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
70+
github.com/spaolacci/murmur3 v1.1.0 // indirect
71+
github.com/spf13/afero v1.15.0 // indirect
72+
github.com/spf13/cast v1.10.0 // indirect
73+
github.com/spf13/cobra v1.10.2 // indirect
74+
github.com/spf13/pflag v1.0.10 // indirect
75+
github.com/spf13/viper v1.21.0 // indirect
76+
github.com/subosito/gotenv v1.6.0 // indirect
5077
github.com/supranational/blst v0.3.16-0.20250831170142-f48500c1fdbe // indirect
5178
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
5279
github.com/tklauser/go-sysconf v0.3.12 // indirect
5380
github.com/tklauser/numcpus v0.6.1 // indirect
81+
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
82+
go.opentelemetry.io/otel v1.39.0 // indirect
83+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 // indirect
84+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0 // indirect
85+
go.opentelemetry.io/otel/metric v1.39.0 // indirect
86+
go.opentelemetry.io/otel/sdk v1.38.0 // indirect
87+
go.opentelemetry.io/otel/trace v1.39.0 // indirect
88+
go.opentelemetry.io/proto/otlp v1.7.1 // indirect
89+
go.yaml.in/yaml/v3 v3.0.4 // indirect
5490
golang.org/x/crypto v0.46.0 // indirect
91+
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
92+
golang.org/x/net v0.48.0 // indirect
5593
golang.org/x/sync v0.19.0 // indirect
5694
golang.org/x/sys v0.39.0 // indirect
95+
golang.org/x/text v0.32.0 // indirect
96+
google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 // indirect
97+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect
98+
google.golang.org/grpc v1.75.0 // indirect
5799
gopkg.in/yaml.v2 v2.4.0 // indirect
58100
gopkg.in/yaml.v3 v3.0.1 // indirect
101+
lukechampine.com/blake3 v1.4.1 // indirect
59102
)
60103

61-
replace github.com/evstack/ev-node/core => ../../core
104+
replace (
105+
github.com/evstack/ev-node => ../../
106+
github.com/evstack/ev-node/core => ../../core
107+
)

0 commit comments

Comments
 (0)