mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
Merge 348e88cb4a into 12eabbd76d
This commit is contained in:
commit
c357d0e7b5
4 changed files with 17 additions and 6 deletions
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -88,6 +89,7 @@ type Client struct {
|
||||||
// config fields
|
// config fields
|
||||||
batchItemLimit int
|
batchItemLimit int
|
||||||
batchResponseMaxSize int
|
batchResponseMaxSize int
|
||||||
|
tracerProvider trace.TracerProvider
|
||||||
|
|
||||||
// writeConn is used for writing to the connection on the caller's goroutine. It should
|
// writeConn is used for writing to the connection on the caller's goroutine. It should
|
||||||
// only be accessed outside of dispatch, with the write lock held. The write lock is
|
// only be accessed outside of dispatch, with the write lock held. The write lock is
|
||||||
|
|
@ -119,7 +121,7 @@ func (c *Client) newClientConn(conn ServerCodec) *clientConn {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx = context.WithValue(ctx, clientContextKey{}, c)
|
ctx = context.WithValue(ctx, clientContextKey{}, c)
|
||||||
ctx = context.WithValue(ctx, peerInfoContextKey{}, conn.peerInfo())
|
ctx = context.WithValue(ctx, peerInfoContextKey{}, conn.peerInfo())
|
||||||
handler := newHandler(ctx, conn, c.idgen, c.services, c.batchItemLimit, c.batchResponseMaxSize, nil)
|
handler := newHandler(ctx, conn, c.idgen, c.services, c.batchItemLimit, c.batchResponseMaxSize, c.tracerProvider)
|
||||||
return &clientConn{conn, handler}
|
return &clientConn{conn, handler}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -247,6 +249,7 @@ func initClient(conn ServerCodec, services *serviceRegistry, cfg *clientConfig)
|
||||||
idgen: cfg.idgen,
|
idgen: cfg.idgen,
|
||||||
batchItemLimit: cfg.batchItemLimit,
|
batchItemLimit: cfg.batchItemLimit,
|
||||||
batchResponseMaxSize: cfg.batchResponseLimit,
|
batchResponseMaxSize: cfg.batchResponseLimit,
|
||||||
|
tracerProvider: cfg.tracerProvider,
|
||||||
writeConn: conn,
|
writeConn: conn,
|
||||||
close: make(chan struct{}),
|
close: make(chan struct{}),
|
||||||
closing: make(chan struct{}),
|
closing: make(chan struct{}),
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ClientOption is a configuration option for the RPC client.
|
// ClientOption is a configuration option for the RPC client.
|
||||||
|
|
@ -41,6 +42,7 @@ type clientConfig struct {
|
||||||
idgen func() ID
|
idgen func() ID
|
||||||
batchItemLimit int
|
batchItemLimit int
|
||||||
batchResponseLimit int
|
batchResponseLimit int
|
||||||
|
tracerProvider trace.TracerProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *clientConfig) initHeaders() {
|
func (cfg *clientConfig) initHeaders() {
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ func (s *Server) ServeCodec(codec ServerCodec, options CodecOption) {
|
||||||
idgen: s.idgen,
|
idgen: s.idgen,
|
||||||
batchItemLimit: s.batchItemLimit,
|
batchItemLimit: s.batchItemLimit,
|
||||||
batchResponseLimit: s.batchResponseLimit,
|
batchResponseLimit: s.batchResponseLimit,
|
||||||
|
tracerProvider: s.tracerProvider,
|
||||||
}
|
}
|
||||||
c := initClient(codec, &s.services, cfg)
|
c := initClient(codec, &s.services, cfg)
|
||||||
<-codec.closed()
|
<-codec.closed()
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package rpc
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
|
|
@ -240,8 +241,8 @@ func TestTracingBatchHTTP(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestTracingSubscribeUnsubscribe verifies that subscribe and unsubscribe calls
|
// TestTracingSubscribeUnsubscribe verifies that subscribe and unsubscribe calls
|
||||||
// do not emit any spans.
|
// do not emit RPC server spans (like "jsonrpc.service/method").
|
||||||
// Note: This works because client.newClientConn() passes nil as the tracer provider.
|
// Note: handleSubscribe does not create the main RPC span, only internal encoding spans.
|
||||||
func TestTracingSubscribeUnsubscribe(t *testing.T) {
|
func TestTracingSubscribeUnsubscribe(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
server, tracer, exporter := newTracingServer(t)
|
server, tracer, exporter := newTracingServer(t)
|
||||||
|
|
@ -257,12 +258,16 @@ func TestTracingSubscribeUnsubscribe(t *testing.T) {
|
||||||
// Unsubscribe.
|
// Unsubscribe.
|
||||||
sub.Unsubscribe()
|
sub.Unsubscribe()
|
||||||
|
|
||||||
// Flush and check that no spans were emitted.
|
// Flush and check that no RPC server spans were emitted.
|
||||||
|
// Internal spans like "rpc.encodeJSONResponse" are allowed.
|
||||||
if err := tracer.ForceFlush(context.Background()); err != nil {
|
if err := tracer.ForceFlush(context.Background()); err != nil {
|
||||||
t.Fatalf("failed to flush: %v", err)
|
t.Fatalf("failed to flush: %v", err)
|
||||||
}
|
}
|
||||||
spans := exporter.GetSpans()
|
spans := exporter.GetSpans()
|
||||||
if len(spans) != 0 {
|
for _, span := range spans {
|
||||||
t.Errorf("expected no spans for subscribe/unsubscribe, got %d", len(spans))
|
// RPC server spans have names like "jsonrpc.service/method"
|
||||||
|
if strings.HasPrefix(span.Name, "jsonrpc.") {
|
||||||
|
t.Errorf("unexpected RPC server span for subscribe/unsubscribe: %s", span.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue