mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
add fast path to startSpan().
This commit is contained in:
parent
d4ba577b03
commit
ecf30d940c
1 changed files with 11 additions and 5 deletions
|
|
@ -526,7 +526,7 @@ func (h *handler) handleCall(cp *callProc, msg *jsonrpcMessage) *jsonrpcMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start tracing span before invoking the method.
|
// Start tracing span before invoking the method.
|
||||||
ctx, span := h.startRPCSpan(cp.ctx, msg, cp.isBatch)
|
ctx, span := h.startSpan(cp.ctx, msg, cp.isBatch)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
@ -586,7 +586,7 @@ func (h *handler) handleSubscribe(cp *callProc, msg *jsonrpcMessage) *jsonrpcMes
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
|
|
||||||
// Start tracing span before invoking the subscription method.
|
// Start tracing span before invoking the subscription method.
|
||||||
ctx, span := h.startRPCSpan(cp.ctx, msg, cp.isBatch)
|
ctx, span := h.startSpan(cp.ctx, msg, cp.isBatch)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
// Install notifier in context so the subscription handler can find it.
|
// Install notifier in context so the subscription handler can find it.
|
||||||
|
|
@ -606,15 +606,21 @@ func (h *handler) handleSubscribe(cp *callProc, msg *jsonrpcMessage) *jsonrpcMes
|
||||||
return answer
|
return answer
|
||||||
}
|
}
|
||||||
|
|
||||||
// startRPCSpan starts a tracing span for an RPC call.
|
// startSpan starts a tracing span for an RPC call.
|
||||||
func (h *handler) startRPCSpan(ctx context.Context, msg *jsonrpcMessage, isBatch bool) (context.Context, trace.Span) {
|
func (h *handler) startSpan(ctx context.Context, msg *jsonrpcMessage, isBatch bool) (context.Context, trace.Span) {
|
||||||
ctx, span := h.tracer().Start(ctx, "rpc.call")
|
ctx, span := h.tracer().Start(ctx, "rpc.call")
|
||||||
|
|
||||||
|
// Fast path: noop provider or span not sampled
|
||||||
|
if !span.IsRecording() {
|
||||||
|
return ctx, span
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set span attributes.
|
||||||
span.SetAttributes(
|
span.SetAttributes(
|
||||||
semconv.RPCSystemKey.String("jsonrpc"),
|
semconv.RPCSystemKey.String("jsonrpc"),
|
||||||
semconv.RPCMethodKey.String(msg.Method),
|
semconv.RPCMethodKey.String(msg.Method),
|
||||||
attribute.Bool("rpc.batch", isBatch),
|
attribute.Bool("rpc.batch", isBatch),
|
||||||
)
|
)
|
||||||
// Request id
|
|
||||||
id := strings.TrimSpace(string(msg.ID))
|
id := strings.TrimSpace(string(msg.ID))
|
||||||
if id != "" && id != "null" {
|
if id != "" && id != "null" {
|
||||||
span.SetAttributes(attribute.String("rpc.id", id))
|
span.SetAttributes(attribute.String("rpc.id", id))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue