Skip to content

Commit

Permalink
Beholder: remove beholder logger based on opentelemetry-go-extra/otelzap
Browse files Browse the repository at this point in the history
  • Loading branch information
pkcll committed Aug 12, 2024
1 parent 5afe2ec commit 79fb2d0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 141 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ require (
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c
github.com/stretchr/testify v1.9.0
github.com/uptrace/opentelemetry-go-extra/otelzap v0.3.1
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240801233905-f7977e064c9c
Expand Down Expand Up @@ -87,7 +86,6 @@ require (
github.com/prometheus/procfs v0.11.1 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.2.0
github.com/stretchr/objx v0.5.2 // indirect
github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.1 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/testcontainers/testcontainers-go v0.14.0 h1:h0D5GaYG9mhOWr2qHdEKDXpkce/VlvaYOCzTRi6UBi8=
github.com/testcontainers/testcontainers-go v0.14.0/go.mod h1:hSRGJ1G8Q5Bw2gXgPulJOLlEBaYJHeBSOkQM5JLG+JQ=
github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.1 h1:Suvl9fe12MM0oi8/rcGxlGd7XawNQawU369aHzZFFec=
github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.1/go.mod h1:aiX/F5+EYbY2ed2OQEYRXzMcNGvI9pip5gW2ZtBDers=
github.com/uptrace/opentelemetry-go-extra/otelzap v0.3.1 h1:0iCp8hx3PFhGihubKHxyOCdIlIPxzUr0VsK+rvlMGdk=
github.com/uptrace/opentelemetry-go-extra/otelzap v0.3.1/go.mod h1:FXrjpUJDqwqofvXWG3YNxQwhg2876tUpZASj8VvOMAM=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
Expand Down
16 changes: 8 additions & 8 deletions pkg/beholder/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ type Client interface {
Close() error
}

var _ Client = (*beholderClient)(nil)
var _ Client = (*otelClient)(nil)

type messageEmitter struct {
exporter sdklog.Exporter
messageLogger otellog.Logger
}

type beholderClient struct {
type otelClient struct {
config Config
// Logger
logger otellog.Logger
Expand All @@ -66,7 +66,7 @@ func NewClient(
emitter Emitter,
onClose func() error,
) Client {
return &beholderClient{
return &otelClient{
config: config,
logger: logger,
tracer: tracer,
Expand Down Expand Up @@ -249,22 +249,22 @@ func (e messageEmitter) EmitMessage(ctx context.Context, message Message) error
return nil
}

func (b *beholderClient) Logger() otellog.Logger {
func (b *otelClient) Logger() otellog.Logger {
return b.logger
}

func (b *beholderClient) Tracer() oteltrace.Tracer {
func (b *otelClient) Tracer() oteltrace.Tracer {
return b.tracer
}

func (b *beholderClient) Meter() otelmetric.Meter {
func (b *otelClient) Meter() otelmetric.Meter {
return b.meter
}
func (b *beholderClient) Emitter() Emitter {
func (b *otelClient) Emitter() Emitter {
return b.emitter
}

func (b *beholderClient) Close() error {
func (b *otelClient) Close() error {
if b.closeFunc != nil {
return b.closeFunc()
}
Expand Down
56 changes: 40 additions & 16 deletions pkg/beholder/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ import (
func ExampleClient() {
ctx := context.Background()

newMessageBytes := func(i int) []byte {
// Create protobuf message
customMessagePb := &pb.CustomMessage{}
customMessagePb.BoolVal = true
customMessagePb.IntVal = int64(i)
customMessagePb.FloatVal = float32(i)
customMessagePb.StringVal = fmt.Sprintf("string-value-%d", i)
customMessagePb.BytesVal = []byte{byte(i)}
// Encode protobuf message
customMessageBytes, err := proto.Marshal(customMessagePb)
if err != nil {
log.Fatalf("Error encoding message: %v", err)
}
return customMessageBytes
}

client, err := beholder.NewOtelClient(beholder.DefaultConfig(), errorHandler)
if err != nil {
log.Fatalf("Error creating beholder client: %v", err)
Expand Down Expand Up @@ -80,6 +64,22 @@ func ExampleClient() {
// Emitting message 2
}

func newMessageBytes(i int) []byte {
// Create protobuf message
customMessagePb := &pb.CustomMessage{}
customMessagePb.BoolVal = true
customMessagePb.IntVal = int64(i)
customMessagePb.FloatVal = float32(i)
customMessagePb.StringVal = fmt.Sprintf("string-value-%d", i)
customMessagePb.BytesVal = []byte{byte(i)}
// Encode protobuf message
customMessageBytes, err := proto.Marshal(customMessagePb)
if err != nil {
log.Fatalf("Error encoding message: %v", err)
}
return customMessageBytes
}

func errorHandler(e error) {
if e != nil {
log.Fatalf("otel error: %v", e)
Expand Down Expand Up @@ -131,3 +131,27 @@ func ExampleEmitter() {
// Create metric counter
// Emit custom message
}

func ExampleBootstrap() {
beholderConfig := beholder.DefaultConfig()

// Bootstrap Beholder Client
err := global.Bootstrap(beholderConfig, errorHandler)
if err != nil {
log.Fatalf("Error bootstrapping Beholder: %v", err)
}

payloadBytes := newMessageBytes(0)

// Emit custom message
for range 3 {
err := global.Emit(context.Background(), payloadBytes, beholder.Attributes{
"beholder_data_type": "custom_message",
"foo": "bar",
})
if err != nil {
log.Printf("Error emitting message: %v", err)
}
}
// Output:
}
21 changes: 2 additions & 19 deletions pkg/beholder/global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import (
"context"
"sync/atomic"

"github.com/uptrace/opentelemetry-go-extra/otelzap"
otellog "go.opentelemetry.io/otel/log"
otelmetric "go.opentelemetry.io/otel/metric"
oteltrace "go.opentelemetry.io/otel/trace"

"github.com/smartcontractkit/chainlink-common/pkg/beholder"
"github.com/smartcontractkit/chainlink-common/pkg/beholder/logger"
)

var log = logger.New()

// Pointer to the global Beholder Client
var globalBeholderClient = defaultBeholderClient()

Expand Down Expand Up @@ -65,11 +61,9 @@ func Emit(ctx context.Context, body []byte, attrs beholder.Attributes) error {
return Emitter().Emit(ctx, body, attrs)
}

func Bootstrap(cfg beholder.Config) error {
func Bootstrap(cfg beholder.Config, errorHandler func(error)) error {
// Initialize beholder client
c, err := beholder.NewOtelClient(cfg, func(err error) {
log.Infof("OTel error %s", err)
})
c, err := beholder.NewOtelClient(cfg, errorHandler)
if err != nil {
return err
}
Expand All @@ -82,14 +76,3 @@ func Bootstrap(cfg beholder.Config) error {
func NewConfig() beholder.Config {
return beholder.DefaultConfig()
}

// Creates logger based on zap logger which writes to stdout
func NewSimpleLogger() logger.Logger {
return logger.New()
}

// Returns a new logger based on otelzap logger
// The logger is able to write to stdout and send logs to otel collector
func NewLogger() *otelzap.Logger {
return logger.NewOtelzapLogger()
}
63 changes: 0 additions & 63 deletions pkg/beholder/logger/logger.go

This file was deleted.

29 changes: 0 additions & 29 deletions pkg/beholder/logger/logger_test.go

This file was deleted.

0 comments on commit 79fb2d0

Please sign in to comment.