gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

partialsuccess.go (2071B)


      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 internal // import "go.opentelemetry.io/otel/exporters/otlp/internal"
     16 
     17 import "fmt"
     18 
     19 // PartialSuccess represents the underlying error for all handling
     20 // OTLP partial success messages.  Use `errors.Is(err,
     21 // PartialSuccess{})` to test whether an error passed to the OTel
     22 // error handler belongs to this category.
     23 type PartialSuccess struct {
     24 	ErrorMessage  string
     25 	RejectedItems int64
     26 	RejectedKind  string
     27 }
     28 
     29 var _ error = PartialSuccess{}
     30 
     31 // Error implements the error interface.
     32 func (ps PartialSuccess) Error() string {
     33 	msg := ps.ErrorMessage
     34 	if msg == "" {
     35 		msg = "empty message"
     36 	}
     37 	return fmt.Sprintf("OTLP partial success: %s (%d %s rejected)", msg, ps.RejectedItems, ps.RejectedKind)
     38 }
     39 
     40 // Is supports the errors.Is() interface.
     41 func (ps PartialSuccess) Is(err error) bool {
     42 	_, ok := err.(PartialSuccess)
     43 	return ok
     44 }
     45 
     46 // TracePartialSuccessError returns an error describing a partial success
     47 // response for the trace signal.
     48 func TracePartialSuccessError(itemsRejected int64, errorMessage string) error {
     49 	return PartialSuccess{
     50 		ErrorMessage:  errorMessage,
     51 		RejectedItems: itemsRejected,
     52 		RejectedKind:  "spans",
     53 	}
     54 }
     55 
     56 // MetricPartialSuccessError returns an error describing a partial success
     57 // response for the metric signal.
     58 func MetricPartialSuccessError(itemsRejected int64, errorMessage string) error {
     59 	return PartialSuccess{
     60 		ErrorMessage:  errorMessage,
     61 		RejectedItems: itemsRejected,
     62 		RejectedKind:  "metric data points",
     63 	}
     64 }