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

37 lines
794 B
Go
Raw Normal View History

2023-05-10 08:16:43 +02:00
// Copyright The OpenTelemetry Authors
2024-04-11 09:46:22 +02:00
// SPDX-License-Identifier: Apache-2.0
2023-05-10 08:16:43 +02: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 13:12:56 +02:00
delegate atomic.Pointer[ErrorHandler]
2023-05-10 08:16:43 +02:00
}
2024-04-11 09:46:22 +02:00
// Compile-time check that delegator implements ErrorHandler.
var _ ErrorHandler = (*ErrDelegator)(nil)
2023-05-10 08:16:43 +02:00
2024-04-11 09:46:22 +02:00
func (d *ErrDelegator) Handle(err error) {
if eh := d.delegate.Load(); eh != nil {
(*eh).Handle(err)
return
}
log.Print(err)
2023-05-10 08:16:43 +02:00
}
// setDelegate sets the ErrorHandler delegate.
func (d *ErrDelegator) setDelegate(eh ErrorHandler) {
2023-08-29 13:12:56 +02:00
d.delegate.Store(&eh)
2023-05-10 08:16:43 +02:00
}