VictoriaMetrics/vendor/go.opentelemetry.io/otel/internal/global/handler.go

37 lines
794 B
Go
Raw Normal View History

2023-05-10 06:13:50 +00:00
// Copyright The OpenTelemetry Authors
2024-04-11 07:46:22 +00:00
// SPDX-License-Identifier: Apache-2.0
2023-05-10 06:13:50 +00:00
package global // import "go.opentelemetry.io/otel/internal/global"
import (
"log"
"sync/atomic"
)
// ErrorHandler handles irremediable events.
type ErrorHandler interface {
// Handle handles any error deemed irremediable by an OpenTelemetry
// component.
Handle(error)
}
type ErrDelegator struct {
2023-08-29 11:12:56 +00:00
delegate atomic.Pointer[ErrorHandler]
2023-05-10 06:13:50 +00:00
}
2024-04-11 07:46:22 +00:00
// Compile-time check that delegator implements ErrorHandler.
var _ ErrorHandler = (*ErrDelegator)(nil)
2023-05-10 06:13:50 +00:00
2024-04-11 07:46:22 +00:00
func (d *ErrDelegator) Handle(err error) {
if eh := d.delegate.Load(); eh != nil {
(*eh).Handle(err)
return
}
log.Print(err)
2023-05-10 06:13:50 +00:00
}
// setDelegate sets the ErrorHandler delegate.
func (d *ErrDelegator) setDelegate(eh ErrorHandler) {
2023-08-29 11:12:56 +00:00
d.delegate.Store(&eh)
2023-05-10 06:13:50 +00:00
}