Skip to content

Commit

Permalink
Add name as service parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Sep 22, 2024
1 parent 2343a4f commit 6963cf0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions http/deliveredbidtrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
// Will return nil if the relay did not deliver a bid for the slot.
func (s *Service) DeliveredBidTrace(ctx context.Context, slot phase0.Slot) (*v1.BidTrace, error) {
ctx, span := otel.Tracer("attestantio.go-relay-client.http").Start(ctx, "DeliveredBidTrace", trace.WithAttributes(
//nolint:gosec
attribute.Int64("slot", int64(slot)),
))
defer span.End()
Expand Down
10 changes: 9 additions & 1 deletion http/parameters.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022, 2023 Attestant Limited.
// Copyright © 2022 - 2024 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -24,6 +24,7 @@ import (
type parameters struct {
logLevel zerolog.Level
monitor metrics.Service
name string
address string
timeout time.Duration
extraHeaders map[string]string
Expand Down Expand Up @@ -54,6 +55,13 @@ func WithMonitor(monitor metrics.Service) Parameter {
})
}

// WithName provides the name for the endpoint.
func WithName(name string) Parameter {
return parameterFunc(func(p *parameters) {
p.name = name
})
}

// WithAddress provides the address for the endpoint.
func WithAddress(address string) Parameter {
return parameterFunc(func(p *parameters) {
Expand Down
1 change: 1 addition & 0 deletions http/receivedbidtraces.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
// ReceivedBidTraces provides all bid traces received for a given slot.
func (s *Service) ReceivedBidTraces(ctx context.Context, slot phase0.Slot) ([]*v1.BidTraceWithTimestamp, error) {
ctx, span := otel.Tracer("attestantio.go-relay-client.http").Start(ctx, "ReceivedBidTraces", trace.WithAttributes(
//nolint:gosec
attribute.Int64("slot", int64(slot)),
))
defer span.End()
Expand Down
12 changes: 10 additions & 2 deletions http/service.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022, 2023 Attestant Limited.
// Copyright © 2022 - 2024 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -33,6 +33,7 @@ import (
// Service is an Ethereum 2 client service.
type Service struct {
base *url.URL
name string
address string
client *http.Client
timeout time.Duration
Expand Down Expand Up @@ -100,8 +101,15 @@ func New(ctx context.Context, params ...Parameter) (builderclient.Service, error
// Remove the user from the URL.
base.User = nil
}

name := parameters.name
if name == "" {
name = base.String()
}

s := &Service{
base: base,
name: name,
address: base.String(),
client: client,
timeout: parameters.timeout,
Expand All @@ -121,7 +129,7 @@ func New(ctx context.Context, params ...Parameter) (builderclient.Service, error

// Name provides the name of the service.
func (s *Service) Name() string {
return s.address
return s.name
}

// Address provides the address for the connection.
Expand Down

0 comments on commit 6963cf0

Please sign in to comment.