Skip to content

Commit

Permalink
proceed through walk errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffail committed Oct 14, 2024
1 parent 86fa49c commit 821a30e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
33 changes: 33 additions & 0 deletions internal/telemetry/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2024 Redpanda Data, Inc.
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package telemetry

import "github.com/redpanda-data/benthos/v4/public/service"

type logWrapper struct {
l *service.Logger
}

func (l *logWrapper) Errorf(format string, v ...interface{}) {
l.l.With("component", "resty").Debugf(format, v...)
}

func (l *logWrapper) Warnf(format string, v ...interface{}) {
// Ignore
}

func (l *logWrapper) Debugf(format string, v ...interface{}) {
// Ignore
}
4 changes: 2 additions & 2 deletions internal/telemetry/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type payload struct {

// All information sent during a telemetry export is extracted within this
// function and stored within the payload.
func extractPayload(identifier string, schema *service.ConfigSchema, conf *service.ParsedConfig) (*payload, error) {
func extractPayload(identifier string, logger *service.Logger, schema *service.ConfigSchema, conf *service.ParsedConfig) (*payload, error) {
p := payload{ID: identifier, Uptime: 0}

rootValue, err := conf.FieldAny()
Expand All @@ -60,7 +60,7 @@ func extractPayload(identifier string, schema *service.ConfigSchema, conf *servi
})
return nil
}); err != nil {
return nil, fmt.Errorf("failed to walk config: %w", err)
logger.With("error", err).Debug("Failed to walk config")
}

return &p, nil
Expand Down
3 changes: 2 additions & 1 deletion internal/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ func ActivateExporter(identifier, version string, logger *service.Logger, schema
SetHeader("Accept", "application/json").
SetBaseURL(exportHost).
SetTimeout(10 * time.Second).
SetLogger(&logWrapper{l: logger}).
SetRetryCount(3),
JWTBuilder: josejwt.Signed(signer),
}

payload, err := extractPayload(identifier, schema, conf)
payload, err := extractPayload(identifier, logger, schema, conf)
if err != nil {
logger.With("error", err).Debug("Failed to create telemetry payload")
return
Expand Down

0 comments on commit 821a30e

Please sign in to comment.