mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
- Copied api and utils/rpc packages from node to remove dependency - Updated imports to use local packages - Removed node from go.mod requirements - Core EVM package now builds without node dependency - Only runner/main (for testing) still uses node/vms/rpcchainvm This allows EVM to be used as a library without pulling in the entire node package tree.
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package api // Copied from luxfi/node to remove dependency
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"github.com/luxfi/trace"
|
|
|
|
oteltrace "go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
var _ http.Handler = (*tracedHandler)(nil)
|
|
|
|
type tracedHandler struct {
|
|
h http.Handler
|
|
serveHTTPTag string
|
|
tracer trace.Tracer
|
|
}
|
|
|
|
func TraceHandler(h http.Handler, name string, tracer trace.Tracer) http.Handler {
|
|
return &tracedHandler{
|
|
h: h,
|
|
serveHTTPTag: name + ".ServeHTTP",
|
|
tracer: tracer,
|
|
}
|
|
}
|
|
|
|
func (h *tracedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
ctx, span := h.tracer.Start(ctx, h.serveHTTPTag, oteltrace.WithAttributes(
|
|
attribute.String("method", r.Method),
|
|
attribute.String("url", r.URL.Redacted()),
|
|
attribute.String("proto", r.Proto),
|
|
attribute.String("host", r.Host),
|
|
attribute.String("remoteAddr", r.RemoteAddr),
|
|
attribute.String("requestURI", r.RequestURI),
|
|
))
|
|
defer span.End()
|
|
|
|
r = r.WithContext(ctx)
|
|
h.h.ServeHTTP(w, r)
|
|
}
|