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