handler.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright The OpenTelemetry Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package otel // import "go.opentelemetry.io/otel"
  15. import (
  16. "go.opentelemetry.io/otel/internal/global"
  17. )
  18. var (
  19. // Compile-time check global.ErrDelegator implements ErrorHandler.
  20. _ ErrorHandler = (*global.ErrDelegator)(nil)
  21. // Compile-time check global.ErrLogger implements ErrorHandler.
  22. _ ErrorHandler = (*global.ErrLogger)(nil)
  23. )
  24. // GetErrorHandler returns the global ErrorHandler instance.
  25. //
  26. // The default ErrorHandler instance returned will log all errors to STDERR
  27. // until an override ErrorHandler is set with SetErrorHandler. All
  28. // ErrorHandler returned prior to this will automatically forward errors to
  29. // the set instance instead of logging.
  30. //
  31. // Subsequent calls to SetErrorHandler after the first will not forward errors
  32. // to the new ErrorHandler for prior returned instances.
  33. func GetErrorHandler() ErrorHandler { return global.GetErrorHandler() }
  34. // SetErrorHandler sets the global ErrorHandler to h.
  35. //
  36. // The first time this is called all ErrorHandler previously returned from
  37. // GetErrorHandler will send errors to h instead of the default logging
  38. // ErrorHandler. Subsequent calls will set the global ErrorHandler, but not
  39. // delegate errors to h.
  40. func SetErrorHandler(h ErrorHandler) { global.SetErrorHandler(h) }
  41. // Handle is a convenience function for ErrorHandler().Handle(err).
  42. func Handle(err error) { global.Handle(err) }