handler.go (1958B)
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 15 package otel // import "go.opentelemetry.io/otel" 16 17 import ( 18 "go.opentelemetry.io/otel/internal/global" 19 ) 20 21 var ( 22 // Compile-time check global.ErrDelegator implements ErrorHandler. 23 _ ErrorHandler = (*global.ErrDelegator)(nil) 24 // Compile-time check global.ErrLogger implements ErrorHandler. 25 _ ErrorHandler = (*global.ErrLogger)(nil) 26 ) 27 28 // GetErrorHandler returns the global ErrorHandler instance. 29 // 30 // The default ErrorHandler instance returned will log all errors to STDERR 31 // until an override ErrorHandler is set with SetErrorHandler. All 32 // ErrorHandler returned prior to this will automatically forward errors to 33 // the set instance instead of logging. 34 // 35 // Subsequent calls to SetErrorHandler after the first will not forward errors 36 // to the new ErrorHandler for prior returned instances. 37 func GetErrorHandler() ErrorHandler { return global.GetErrorHandler() } 38 39 // SetErrorHandler sets the global ErrorHandler to h. 40 // 41 // The first time this is called all ErrorHandler previously returned from 42 // GetErrorHandler will send errors to h instead of the default logging 43 // ErrorHandler. Subsequent calls will set the global ErrorHandler, but not 44 // delegate errors to h. 45 func SetErrorHandler(h ErrorHandler) { global.SetErrorHandler(h) } 46 47 // Handle is a convenience function for ErrorHandler().Handle(err). 48 func Handle(err error) { global.Handle(err) }