handler.go 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package otel // import "go.opentelemetry.io/otel"
  4. import (
  5. "go.opentelemetry.io/otel/internal/global"
  6. )
  7. // Compile-time check global.ErrDelegator implements ErrorHandler.
  8. var _ ErrorHandler = (*global.ErrDelegator)(nil)
  9. // GetErrorHandler returns the global ErrorHandler instance.
  10. //
  11. // The default ErrorHandler instance returned will log all errors to STDERR
  12. // until an override ErrorHandler is set with SetErrorHandler. All
  13. // ErrorHandler returned prior to this will automatically forward errors to
  14. // the set instance instead of logging.
  15. //
  16. // Subsequent calls to SetErrorHandler after the first will not forward errors
  17. // to the new ErrorHandler for prior returned instances.
  18. func GetErrorHandler() ErrorHandler { return global.GetErrorHandler() }
  19. // SetErrorHandler sets the global ErrorHandler to h.
  20. //
  21. // The first time this is called all ErrorHandler previously returned from
  22. // GetErrorHandler will send errors to h instead of the default logging
  23. // ErrorHandler. Subsequent calls will set the global ErrorHandler, but not
  24. // delegate errors to h.
  25. func SetErrorHandler(h ErrorHandler) { global.SetErrorHandler(h) }
  26. // Handle is a convenience function for GetErrorHandler().Handle(err).
  27. func Handle(err error) { global.GetErrorHandler().Handle(err) }