Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import (
"github.com/flashbots/bmonitor/metrics"
"github.com/flashbots/bmonitor/utils"

"github.com/ethereum/go-ethereum/ethclient"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/otel/attribute"
otelapi "go.opentelemetry.io/otel/metric"
"go.uber.org/zap"

"github.com/ethereum/go-ethereum/ethclient"
)

type Server struct {
Expand Down Expand Up @@ -114,6 +115,8 @@ func (s *Server) Run() error {
return err
}

s.initializePeersMetrics(ctx)

go func() { // run the server
l.Info("Builder monitor server is going up...",
zap.String("server_listen_address", s.cfg.Server.ListenAddress),
Expand Down Expand Up @@ -182,3 +185,21 @@ func (s *Server) Run() error {

return utils.FlattenErrors(errs)
}

func (s *Server) initializePeersMetrics(ctx context.Context) {
for builder := range s.builders {
for _, typ := range []string{"loopback", "internal", "external"} {
metrics.PeersCount.Record(ctx, 0, otelapi.WithAttributes(
attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)},
attribute.KeyValue{Key: "type", Value: attribute.StringValue(typ)},
))
}
Comment on lines +191 to +196
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces several magic strings for attribute keys/values (\"builder\", \"type\", \"label\", \"loopback\", \"internal\", \"external\", \"labelled\"). Consider centralizing these as constants (or reusing existing constants/enums if the repo has them) to prevent drift/typos and make it easier to change label conventions later.

Copilot uses AI. Check for mistakes.
for _, label := range s.peers {
metrics.PeersCount.Record(ctx, 0, otelapi.WithAttributes(
attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)},
attribute.KeyValue{Key: "type", Value: attribute.StringValue("labelled")},
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces several magic strings for attribute keys/values (\"builder\", \"type\", \"label\", \"loopback\", \"internal\", \"external\", \"labelled\"). Consider centralizing these as constants (or reusing existing constants/enums if the repo has them) to prevent drift/typos and make it easier to change label conventions later.

Copilot uses AI. Check for mistakes.
attribute.KeyValue{Key: "label", Value: attribute.StringValue(label)},
Comment on lines +193 to +201
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer the typed helpers (e.g., attribute.String(\"builder\", builder)) over manually constructing attribute.KeyValue with attribute.StringValue(...). It reads clearer and avoids potential subtle inconsistencies in how attributes are constructed across the codebase.

Suggested change
attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)},
attribute.KeyValue{Key: "type", Value: attribute.StringValue(typ)},
))
}
for _, label := range s.peers {
metrics.PeersCount.Record(ctx, 0, otelapi.WithAttributes(
attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)},
attribute.KeyValue{Key: "type", Value: attribute.StringValue("labelled")},
attribute.KeyValue{Key: "label", Value: attribute.StringValue(label)},
attribute.String("builder", builder),
attribute.String("type", typ),
))
}
for _, label := range s.peers {
metrics.PeersCount.Record(ctx, 0, otelapi.WithAttributes(
attribute.String("builder", builder),
attribute.String("type", "labelled"),
attribute.String("label", label),

Copilot uses AI. Check for mistakes.
))
}
}
}