1 // Code created by gotmpl. DO NOT MODIFY. 2 // source: internal/shared/otlp/partialsuccess.go 3 4 // Copyright The OpenTelemetry Authors 5 // 6 // Licensed under the Apache License, Version 2.0 (the "License"); 7 // you may not use this file except in compliance with the License. 8 // You may obtain a copy of the License at 9 // 10 // http://www.apache.org/licenses/LICENSE-2.0 11 // 12 // Unless required by applicable law or agreed to in writing, software 13 // distributed under the License is distributed on an "AS IS" BASIS, 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 // See the License for the specific language governing permissions and 16 // limitations under the License. 17 18 package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal" 19 20 import "fmt" 21 22 // PartialSuccess represents the underlying error for all handling 23 // OTLP partial success messages. Use `errors.Is(err, 24 // PartialSuccess{})` to test whether an error passed to the OTel 25 // error handler belongs to this category. 26 type PartialSuccess struct { 27 ErrorMessage string 28 RejectedItems int64 29 RejectedKind string 30 } 31 32 var _ error = PartialSuccess{} 33 34 // Error implements the error interface. 35 func (ps PartialSuccess) Error() string { 36 msg := ps.ErrorMessage 37 if msg == "" { 38 msg = "empty message" 39 } 40 return fmt.Sprintf("OTLP partial success: %s (%d %s rejected)", msg, ps.RejectedItems, ps.RejectedKind) 41 } 42 43 // Is supports the errors.Is() interface. 44 func (ps PartialSuccess) Is(err error) bool { 45 _, ok := err.(PartialSuccess) 46 return ok 47 } 48 49 // TracePartialSuccessError returns an error describing a partial success 50 // response for the trace signal. 51 func TracePartialSuccessError(itemsRejected int64, errorMessage string) error { 52 return PartialSuccess{ 53 ErrorMessage: errorMessage, 54 RejectedItems: itemsRejected, 55 RejectedKind: "spans", 56 } 57 } 58 59 // MetricPartialSuccessError returns an error describing a partial success 60 // response for the metric signal. 61 func MetricPartialSuccessError(itemsRejected int64, errorMessage string) error { 62 return PartialSuccess{ 63 ErrorMessage: errorMessage, 64 RejectedItems: itemsRejected, 65 RejectedKind: "metric data points", 66 } 67 } 68