1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-03-25 21:28:58 +02:00

Add api/oterror package

This commit is contained in:
Tyler Yahn 2020-05-29 12:56:15 -07:00
parent 3b76c770cc
commit 7cccff7944
No known key found for this signature in database
GPG Key ID: 42AA23B0BC85B798
4 changed files with 74 additions and 7 deletions

@ -16,9 +16,9 @@ package metric
import (
"context"
"errors"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/oterror"
)
// Measurement is used for reporting a synchronous batch of metric
@ -45,10 +45,6 @@ type asyncInstrument struct {
instrument AsyncImpl
}
// ErrSDKReturnedNilImpl is used when one of the `MeterImpl` New
// methods returns nil.
var ErrSDKReturnedNilImpl = errors.New("SDK returned a nil implementation")
// SyncImpl returns the instrument that created this measurement.
// This returns an implementation-level object for use by the SDK,
// users should not refer to this.
@ -114,7 +110,7 @@ func (h syncBoundInstrument) Unbind() {
func checkNewAsync(instrument AsyncImpl, err error) (asyncInstrument, error) {
if instrument == nil {
if err == nil {
err = ErrSDKReturnedNilImpl
err = oterror.SDKReturnedNilImpl
}
instrument = NoopAsync{}
}
@ -129,7 +125,7 @@ func checkNewAsync(instrument AsyncImpl, err error) (asyncInstrument, error) {
func checkNewSync(instrument SyncImpl, err error) (syncInstrument, error) {
if instrument == nil {
if err == nil {
err = ErrSDKReturnedNilImpl
err = oterror.SDKReturnedNilImpl
}
// Note: an alternate behavior would be to synthesize a new name
// or group all duplicately-named instruments of a certain type

26
api/oterror/doc.go Normal file

@ -0,0 +1,26 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* The oterror package provides unified error interactions in OpenTelemetry.
* This includes providing standardized errors common to OpenTelemetry (APIs,
* SDKs, and exporters). Additionally it provides an API for unified error
* handling in OpenTelemetry.
*
* The unified error handling interface is used for any error that
* OpenTelemetry component are not able to remediate on their own, instead
* handeling them in a uniform and user-defined way.
*/
package oterror

22
api/oterror/errors.go Normal file

@ -0,0 +1,22 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package oterror
import "errors"
var (
// SDKReturnedNilImpl is returned when a new `MeterImpl` returns nil.
SDKReturnedNilImpl = errors.New("SDK returned a nil implementation")
)

23
api/oterror/handler.go Normal file

@ -0,0 +1,23 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package oterror
// Handler performs a required function when an irremediable event is
// encountered.
type Handler interface {
// Error handles any error that irremediable by an OpenTelemetry
// component.
Error(error)
}