diff --git a/.github/workflows/golangci_lint.yml b/.github/workflows/golangci_lint.yml index 060ba7484..12e61f688 100644 --- a/.github/workflows/golangci_lint.yml +++ b/.github/workflows/golangci_lint.yml @@ -12,7 +12,22 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.20' + go-version: '1.21' - - name: Run lint (Run `make lint` locally to reproduce) - run: make lint \ No newline at end of file + - name: Install golangci-lint + run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2 + + # go.work makes it necessary to run linter manually + - name: Run golangci-lint + run: find . -name "go.mod" -execdir $(go env GOPATH)/bin/golangci-lint run --enable=gofmt --tests=false --exclude-use-default --timeout=5m0s --out-format checkstyle:golangci-lint-report.xml \; + + - name: Check golangci-lint report for errors + run: find . -name "golangci-lint-report.xml" -exec grep "error" {} + && exit 1 || true + + - name: Upload golangci-lint report + if: always() + uses: actions/upload-artifact@v3 + with: + name: golangci-lint-report + path: | + ./golangci-lint-report.xml \ No newline at end of file diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 70202eefb..6d0a4d9d2 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -45,7 +45,6 @@ type Config struct { var defaultConfig Config // New returns a new Logger with the default configuration. -// TODO: why do API consumers have to worry about err here? Not useful? func New() (Logger, error) { return defaultConfig.New() } // New returns a new Logger for Config. diff --git a/pkg/loop/telem.go b/pkg/loop/telem.go index edf2f579a..87bbf7346 100644 --- a/pkg/loop/telem.go +++ b/pkg/loop/telem.go @@ -20,7 +20,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/smartcontractkit/chainlink-relay/pkg/logger" "github.com/smartcontractkit/chainlink-relay/pkg/loop/internal" ) @@ -40,15 +39,9 @@ type TracingConfig struct { SamplingRatio float64 } -// SetupTelemetry initializes open telemetry and returns GRPCOpts with telemetry interceptors. +// NewGRPCOpts initializes open telemetry and returns GRPCOpts with telemetry interceptors. // It is called from the host and each plugin - intended as there is bidirectional communication -func SetupTelemetry(registerer prometheus.Registerer, config TracingConfig) GRPCOpts { - if config.Enabled { - SetupTracing(config) - } - - otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})) - +func NewGRPCOpts(registerer prometheus.Registerer) GRPCOpts { if registerer == nil { registerer = prometheus.DefaultRegisterer } @@ -57,10 +50,9 @@ func SetupTelemetry(registerer prometheus.Registerer, config TracingConfig) GRPC // SetupTracing initializes open telemetry with the provided config. // It sets the global trace provider and opens a connection to the configured collector. -func SetupTracing(config TracingConfig) { - log, err := logger.New() - if err != nil { - panic(err) +func SetupTracing(config TracingConfig) error { + if !config.Enabled { + return nil } ctx := context.Background() @@ -75,22 +67,20 @@ func SetupTracing(config TracingConfig) { grpc.WithBlock(), ) if err != nil { - log.Errorf("Connecting to OTEL collector %w failed: %v", config.CollectorTarget, err) + return err } // Set up a trace exporter // Shutting down the traceExporter will not shutdown the underlying connection. traceExporter, err := otlptracegrpc.New(ctx, otlptracegrpc.WithGRPCConn(conn)) if err != nil { - log.Errorf("failed to create trace exporter: %w", err) - return + return err } var version string var service string buildInfo, ok := debug.ReadBuildInfo() if !ok { - log.Errorf("failed to read build info: %w", err) version = "unknown" service = "cl-node" } else { @@ -120,6 +110,8 @@ func SetupTracing(config TracingConfig) { ) otel.SetTracerProvider(tracerProvider) + otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})) + return nil } var grpcpromBuckets = []float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120}