Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handler to replace global otel error handler #1233

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions pkg/traces/exporter/error_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package exporter

import (
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
)

// errorHandler implements the go.opentelemetry.io/otel/internal/global.ErrorHandler interface.
// We use our own error handler instead of the default global one to avoid errors being printed
// to our logs without JSON formatting and without appropriate log level consideration.
type errorHandler struct {
logger log.Logger
}

func newErrorHandler(logger log.Logger) *errorHandler {
return &errorHandler{
logger: logger,
}
}

func (e *errorHandler) Handle(err error) {
level.Debug(e.logger).Log("msg", "tracing error", "err", err)
}
5 changes: 5 additions & 0 deletions pkg/traces/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func NewTraceExporter(ctx context.Context, k types.Knapsack, client osquery.Quer
return t, nil
}

// Set our own error handler to avoid otel printing errors
otel.SetErrorHandler(newErrorHandler(
log.With(logger, "component", "trace_exporter"),
))

t.addDeviceIdentifyingAttributes()

// Set the provider with as many resource attributes as we can get immediately
Expand Down