Skip to content

Commit

Permalink
Exposed the HTTP tracer in the logger directly
Browse files Browse the repository at this point in the history
  • Loading branch information
jclapis committed Jun 30, 2024
1 parent 8e445d8 commit e61b52a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion beacon/client/http-provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func (p *BeaconHttpProvider) logRequest(ctx context.Context, methodName string,
args = append(args, slog.Time("deadline", deadline.UTC()))
}
logger.Debug("Running BN request", args...)
tracer := logger.GetHttpTracer()
tracer := logger.HttpTracer
if tracer != nil {
// Enable HTTP tracing if requested
ctx = httptrace.WithClientTrace(ctx, tracer)
Expand Down
2 changes: 1 addition & 1 deletion eth/std-rpc-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (c *StandardRpcClient) logRequest(ctx context.Context, methodName string) c
args = append(args, slog.Time("deadline", deadline.UTC()))
}
logger.Debug("Running EC request", args...)
tracer := logger.GetHttpTracer()
tracer := logger.HttpTracer
if tracer != nil {
// Enable HTTP tracing if requested
ctx = httptrace.WithClientTrace(ctx, tracer)
Expand Down
13 changes: 6 additions & 7 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ import (
// Logger is a simple wrapper for a slog Logger that writes to a file on disk.
type Logger struct {
*slog.Logger

// The HTTP client tracer for this logger if HTTP tracing was enabled
HttpTracer *httptrace.ClientTrace

// Internal fields
logFile *lumberjack.Logger
path string
tracer *httptrace.ClientTrace
}

// Creates a new logger that writes out to a log file on disk.
Expand Down Expand Up @@ -60,7 +64,7 @@ func NewLogger(logFilePath string, options LoggerOptions) (*Logger, error) {
}

if options.EnableHttpTracing {
logger.tracer = logger.createHttpClientTracer()
logger.HttpTracer = logger.createHttpClientTracer()
}
return logger, nil
}
Expand All @@ -78,11 +82,6 @@ func (l *Logger) GetFilePath() string {
return l.path
}

// Get the HTTP client tracer for this logger if HTTP tracing was enabled
func (l *Logger) GetHttpTracer() *httptrace.ClientTrace {
return l.tracer
}

// Rotate the log file, migrating the current file to an old backup and starting a new one
func (l *Logger) Rotate() error {
if l.logFile != nil {
Expand Down

0 comments on commit e61b52a

Please sign in to comment.