diff --git a/api/metric/sync.go b/api/metric/sync.go index 029137683..2cdc9fb14 100644 --- a/api/metric/sync.go +++ b/api/metric/sync.go @@ -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 diff --git a/api/oterror/doc.go b/api/oterror/doc.go new file mode 100644 index 000000000..aa2f59d0e --- /dev/null +++ b/api/oterror/doc.go @@ -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 diff --git a/api/oterror/errors.go b/api/oterror/errors.go new file mode 100644 index 000000000..2dfb1f083 --- /dev/null +++ b/api/oterror/errors.go @@ -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") +) diff --git a/api/oterror/handler.go b/api/oterror/handler.go new file mode 100644 index 000000000..dc64f9097 --- /dev/null +++ b/api/oterror/handler.go @@ -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) +}